[PATCH] Remove f_error field from struct file
[wrt350n-kernel.git] / fs / coda / cache.c
blob80072fd9b7faf6a6c21747d65ffc6bb2c65e8cbd
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
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 */
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/time.h>
13 #include <linux/fs.h>
14 #include <linux/stat.h>
15 #include <linux/errno.h>
16 #include <asm/uaccess.h>
17 #include <linux/string.h>
18 #include <linux/list.h>
20 #include <linux/coda.h>
21 #include <linux/coda_linux.h>
22 #include <linux/coda_psdev.h>
23 #include <linux/coda_fs_i.h>
24 #include <linux/coda_cache.h>
26 static atomic_t permission_epoch = ATOMIC_INIT(0);
28 /* replace or extend an acl cache hit */
29 void coda_cache_enter(struct inode *inode, int mask)
31 struct coda_inode_info *cii = ITOC(inode);
33 cii->c_cached_epoch = atomic_read(&permission_epoch);
34 if (cii->c_uid != current->fsuid) {
35 cii->c_uid = current->fsuid;
36 cii->c_cached_perm = mask;
37 } else
38 cii->c_cached_perm |= mask;
41 /* remove cached acl from an inode */
42 void coda_cache_clear_inode(struct inode *inode)
44 struct coda_inode_info *cii = ITOC(inode);
45 cii->c_cached_perm = 0;
48 /* remove all acl caches */
49 void coda_cache_clear_all(struct super_block *sb)
51 struct coda_sb_info *sbi;
53 sbi = coda_sbp(sb);
54 if (!sbi) BUG();
56 atomic_inc(&permission_epoch);
60 /* check if the mask has been matched against the acl already */
61 int coda_cache_check(struct inode *inode, int mask)
63 struct coda_inode_info *cii = ITOC(inode);
64 int hit;
66 hit = (mask & cii->c_cached_perm) == mask &&
67 cii->c_uid == current->fsuid &&
68 cii->c_cached_epoch == atomic_read(&permission_epoch);
70 return hit;
74 /* Purging dentries and children */
75 /* The following routines drop dentries which are not
76 in use and flag dentries which are in use to be
77 zapped later.
79 The flags are detected by:
80 - coda_dentry_revalidate (for lookups) if the flag is C_PURGE
81 - coda_dentry_delete: to remove dentry from the cache when d_count
82 falls to zero
83 - an inode method coda_revalidate (for attributes) if the
84 flag is C_VATTR
87 /* this won't do any harm: just flag all children */
88 static void coda_flag_children(struct dentry *parent, int flag)
90 struct list_head *child;
91 struct dentry *de;
93 spin_lock(&dcache_lock);
94 list_for_each(child, &parent->d_subdirs)
96 de = list_entry(child, struct dentry, d_child);
97 /* don't know what to do with negative dentries */
98 if ( ! de->d_inode )
99 continue;
100 coda_flag_inode(de->d_inode, flag);
102 spin_unlock(&dcache_lock);
103 return;
106 void coda_flag_inode_children(struct inode *inode, int flag)
108 struct dentry *alias_de;
110 if ( !inode || !S_ISDIR(inode->i_mode))
111 return;
113 alias_de = d_find_alias(inode);
114 if (!alias_de)
115 return;
116 coda_flag_children(alias_de, flag);
117 shrink_dcache_parent(alias_de);
118 dput(alias_de);