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>.
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/time.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>
19 #include <linux/sched.h>
20 #include <linux/spinlock.h>
22 #include <linux/coda.h>
23 #include <linux/coda_linux.h>
24 #include <linux/coda_psdev.h>
25 #include <linux/coda_fs_i.h>
26 #include <linux/coda_cache.h>
28 static atomic_t permission_epoch
= ATOMIC_INIT(0);
30 /* replace or extend an acl cache hit */
31 void coda_cache_enter(struct inode
*inode
, int mask
)
33 struct coda_inode_info
*cii
= ITOC(inode
);
35 spin_lock(&cii
->c_lock
);
36 cii
->c_cached_epoch
= atomic_read(&permission_epoch
);
37 if (cii
->c_uid
!= current_fsuid()) {
38 cii
->c_uid
= current_fsuid();
39 cii
->c_cached_perm
= mask
;
41 cii
->c_cached_perm
|= mask
;
42 spin_unlock(&cii
->c_lock
);
45 /* remove cached acl from an inode */
46 void coda_cache_clear_inode(struct inode
*inode
)
48 struct coda_inode_info
*cii
= ITOC(inode
);
49 spin_lock(&cii
->c_lock
);
50 cii
->c_cached_epoch
= atomic_read(&permission_epoch
) - 1;
51 spin_unlock(&cii
->c_lock
);
54 /* remove all acl caches */
55 void coda_cache_clear_all(struct super_block
*sb
)
57 atomic_inc(&permission_epoch
);
61 /* check if the mask has been matched against the acl already */
62 int coda_cache_check(struct inode
*inode
, int mask
)
64 struct coda_inode_info
*cii
= ITOC(inode
);
67 spin_lock(&cii
->c_lock
);
68 hit
= (mask
& cii
->c_cached_perm
) == mask
&&
69 cii
->c_uid
== current_fsuid() &&
70 cii
->c_cached_epoch
== atomic_read(&permission_epoch
);
71 spin_unlock(&cii
->c_lock
);
77 /* Purging dentries and children */
78 /* The following routines drop dentries which are not
79 in use and flag dentries which are in use to be
82 The flags are detected by:
83 - coda_dentry_revalidate (for lookups) if the flag is C_PURGE
84 - coda_dentry_delete: to remove dentry from the cache when d_count
86 - an inode method coda_revalidate (for attributes) if the
90 /* this won't do any harm: just flag all children */
91 static void coda_flag_children(struct dentry
*parent
, int flag
)
93 struct list_head
*child
;
96 spin_lock(&dcache_lock
);
97 list_for_each(child
, &parent
->d_subdirs
)
99 de
= list_entry(child
, struct dentry
, d_u
.d_child
);
100 /* don't know what to do with negative dentries */
103 coda_flag_inode(de
->d_inode
, flag
);
105 spin_unlock(&dcache_lock
);
109 void coda_flag_inode_children(struct inode
*inode
, int flag
)
111 struct dentry
*alias_de
;
113 if ( !inode
|| !S_ISDIR(inode
->i_mode
))
116 alias_de
= d_find_alias(inode
);
119 coda_flag_children(alias_de
, flag
);
120 shrink_dcache_parent(alias_de
);