diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/coda/cache.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'fs/coda/cache.c')
-rw-r--r-- | fs/coda/cache.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/fs/coda/cache.c b/fs/coda/cache.c new file mode 100644 index 000000000000..80072fd9b7fa --- /dev/null +++ b/fs/coda/cache.c | |||
@@ -0,0 +1,120 @@ | |||
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/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> | ||
19 | |||
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> | ||
25 | |||
26 | static atomic_t permission_epoch = ATOMIC_INIT(0); | ||
27 | |||
28 | /* replace or extend an acl cache hit */ | ||
29 | void coda_cache_enter(struct inode *inode, int mask) | ||
30 | { | ||
31 | struct coda_inode_info *cii = ITOC(inode); | ||
32 | |||
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; | ||
39 | } | ||
40 | |||
41 | /* remove cached acl from an inode */ | ||
42 | void coda_cache_clear_inode(struct inode *inode) | ||
43 | { | ||
44 | struct coda_inode_info *cii = ITOC(inode); | ||
45 | cii->c_cached_perm = 0; | ||
46 | } | ||
47 | |||
48 | /* remove all acl caches */ | ||
49 | void coda_cache_clear_all(struct super_block *sb) | ||
50 | { | ||
51 | struct coda_sb_info *sbi; | ||
52 | |||
53 | sbi = coda_sbp(sb); | ||
54 | if (!sbi) BUG(); | ||
55 | |||
56 | atomic_inc(&permission_epoch); | ||
57 | } | ||
58 | |||
59 | |||
60 | /* check if the mask has been matched against the acl already */ | ||
61 | int coda_cache_check(struct inode *inode, int mask) | ||
62 | { | ||
63 | struct coda_inode_info *cii = ITOC(inode); | ||
64 | int hit; | ||
65 | |||
66 | hit = (mask & cii->c_cached_perm) == mask && | ||
67 | cii->c_uid == current->fsuid && | ||
68 | cii->c_cached_epoch == atomic_read(&permission_epoch); | ||
69 | |||
70 | return hit; | ||
71 | } | ||
72 | |||
73 | |||
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. | ||
78 | |||
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 | ||
85 | */ | ||
86 | |||
87 | /* this won't do any harm: just flag all children */ | ||
88 | static void coda_flag_children(struct dentry *parent, int flag) | ||
89 | { | ||
90 | struct list_head *child; | ||
91 | struct dentry *de; | ||
92 | |||
93 | spin_lock(&dcache_lock); | ||
94 | list_for_each(child, &parent->d_subdirs) | ||
95 | { | ||
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); | ||
101 | } | ||
102 | spin_unlock(&dcache_lock); | ||
103 | return; | ||
104 | } | ||
105 | |||
106 | void coda_flag_inode_children(struct inode *inode, int flag) | ||
107 | { | ||
108 | struct dentry *alias_de; | ||
109 | |||
110 | if ( !inode || !S_ISDIR(inode->i_mode)) | ||
111 | return; | ||
112 | |||
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); | ||
119 | } | ||
120 | |||