1
2
3
4
5
6
7
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 <linux/uaccess.h>
17#include <linux/string.h>
18#include <linux/list.h>
19#include <linux/sched.h>
20#include <linux/spinlock.h>
21
22#include <linux/coda.h>
23#include <linux/coda_psdev.h>
24#include "coda_linux.h"
25#include "coda_cache.h"
26
27static atomic_t permission_epoch = ATOMIC_INIT(0);
28
29
30void coda_cache_enter(struct inode *inode, int mask)
31{
32 struct coda_inode_info *cii = ITOC(inode);
33
34 spin_lock(&cii->c_lock);
35 cii->c_cached_epoch = atomic_read(&permission_epoch);
36 if (!uid_eq(cii->c_uid, current_fsuid())) {
37 cii->c_uid = current_fsuid();
38 cii->c_cached_perm = mask;
39 } else
40 cii->c_cached_perm |= mask;
41 spin_unlock(&cii->c_lock);
42}
43
44
45void coda_cache_clear_inode(struct inode *inode)
46{
47 struct coda_inode_info *cii = ITOC(inode);
48 spin_lock(&cii->c_lock);
49 cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50 spin_unlock(&cii->c_lock);
51}
52
53
54void coda_cache_clear_all(struct super_block *sb)
55{
56 atomic_inc(&permission_epoch);
57}
58
59
60
61int coda_cache_check(struct inode *inode, int mask)
62{
63 struct coda_inode_info *cii = ITOC(inode);
64 int hit;
65
66 spin_lock(&cii->c_lock);
67 hit = (mask & cii->c_cached_perm) == mask &&
68 uid_eq(cii->c_uid, current_fsuid()) &&
69 cii->c_cached_epoch == atomic_read(&permission_epoch);
70 spin_unlock(&cii->c_lock);
71
72 return hit;
73}
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90static void coda_flag_children(struct dentry *parent, int flag)
91{
92 struct dentry *de;
93
94 spin_lock(&parent->d_lock);
95 list_for_each_entry(de, &parent->d_subdirs, d_child) {
96
97 if (d_inode(de) )
98 coda_flag_inode(d_inode(de), flag);
99 }
100 spin_unlock(&parent->d_lock);
101 return;
102}
103
104void coda_flag_inode_children(struct inode *inode, int flag)
105{
106 struct dentry *alias_de;
107
108 if ( !inode || !S_ISDIR(inode->i_mode))
109 return;
110
111 alias_de = d_find_alias(inode);
112 if (!alias_de)
113 return;
114 coda_flag_children(alias_de, flag);
115 shrink_dcache_parent(alias_de);
116 dput(alias_de);
117}
118
119