1 /*
2 * Cache operations for Coda.
3 * For Linux 2.1: (C) 1997 Carnegie Mellon University
4 * For Linux 2.3: (C) 2000 Carnegie Mellon University
5 *
6 * Carnegie Mellon encourages users of this code to contribute improvements
7 * to the Coda project http://www.coda.cs.cmu.edu/ <coda@cs.cmu.edu>.
8 */
9
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/fs.h>
14 #include <linux/stat.h>
15 #include <linux/errno.h>
16 #include <linux/locks.h>
17 #include <asm/uaccess.h>
18 #include <linux/string.h>
19 #include <linux/list.h>
20
21 #include <linux/coda.h>
22 #include <linux/coda_linux.h>
23 #include <linux/coda_psdev.h>
24 #include <linux/coda_fs_i.h>
25 #include <linux/coda_cache.h>
26
27 /* replace or extend an acl cache hit */
coda_cache_enter(struct inode * inode,int mask)28 void coda_cache_enter(struct inode *inode, int mask)
29 {
30 struct coda_inode_info *cii = ITOC(inode);
31
32 if ( !coda_cred_ok(&cii->c_cached_cred) ) {
33 coda_load_creds(&cii->c_cached_cred);
34 cii->c_cached_perm = mask;
35 } else
36 cii->c_cached_perm |= mask;
37 }
38
39 /* remove cached acl from an inode */
coda_cache_clear_inode(struct inode * inode)40 void coda_cache_clear_inode(struct inode *inode)
41 {
42 struct coda_inode_info *cii = ITOC(inode);
43 cii->c_cached_perm = 0;
44 }
45
46 /* remove all acl caches for a principal (or all principals when cred == NULL)*/
coda_cache_clear_all(struct super_block * sb,struct coda_cred * cred)47 void coda_cache_clear_all(struct super_block *sb, struct coda_cred *cred)
48 {
49 struct coda_sb_info *sbi;
50 struct coda_inode_info *cii;
51 struct list_head *tmp;
52
53 sbi = coda_sbp(sb);
54 if (!sbi) BUG();
55
56 list_for_each(tmp, &sbi->sbi_cihead)
57 {
58 cii = list_entry(tmp, struct coda_inode_info, c_cilist);
59 if (!cred || coda_cred_eq(cred, &cii->c_cached_cred))
60 cii->c_cached_perm = 0;
61 }
62 }
63
64
65 /* check if the mask has been matched against the acl already */
coda_cache_check(struct inode * inode,int mask)66 int coda_cache_check(struct inode *inode, int mask)
67 {
68 struct coda_inode_info *cii = ITOC(inode);
69 int hit;
70
71 hit = ((mask & cii->c_cached_perm) == mask) &&
72 coda_cred_ok(&cii->c_cached_cred);
73
74 CDEBUG(D_CACHE, "%s for ino %ld\n", hit ? "HIT" : "MISS", inode->i_ino);
75 return hit;
76 }
77
78
79 /* Purging dentries and children */
80 /* The following routines drop dentries which are not
81 in use and flag dentries which are in use to be
82 zapped later.
83
84 The flags are detected by:
85 - coda_dentry_revalidate (for lookups) if the flag is C_PURGE
86 - coda_dentry_delete: to remove dentry from the cache when d_count
87 falls to zero
88 - an inode method coda_revalidate (for attributes) if the
89 flag is C_VATTR
90 */
91
92 /* this won't do any harm: just flag all children */
coda_flag_children(struct dentry * parent,int flag)93 static void coda_flag_children(struct dentry *parent, int flag)
94 {
95 struct list_head *child;
96 struct dentry *de;
97
98 spin_lock(&dcache_lock);
99 list_for_each(child, &parent->d_subdirs)
100 {
101 de = list_entry(child, struct dentry, d_child);
102 /* don't know what to do with negative dentries */
103 if ( ! de->d_inode )
104 continue;
105 CDEBUG(D_DOWNCALL, "%d for %*s/%*s\n", flag,
106 de->d_name.len, de->d_name.name,
107 de->d_parent->d_name.len, de->d_parent->d_name.name);
108 coda_flag_inode(de->d_inode, flag);
109 }
110 spin_unlock(&dcache_lock);
111 return;
112 }
113
coda_flag_inode_children(struct inode * inode,int flag)114 void coda_flag_inode_children(struct inode *inode, int flag)
115 {
116 struct dentry *alias_de;
117
118 if ( !inode || !S_ISDIR(inode->i_mode))
119 return;
120
121 alias_de = d_find_alias(inode);
122 if (!alias_de)
123 return;
124 coda_flag_children(alias_de, flag);
125 shrink_dcache_parent(alias_de);
126 dput(alias_de);
127 }
128
129