aboutsummaryrefslogtreecommitdiffstats
path: root/fs/coda
diff options
context:
space:
mode:
authorYoshihisa Abe <yoshiabe@cs.cmu.edu>2010-10-25 02:03:44 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-25 11:02:40 -0400
commitb5ce1d83a62fc109d8e815b1fc71dcdb0d26bc49 (patch)
treeea537c1b6436c36bee3b33d8b4f750124fd7d661 /fs/coda
parent3a99c6319064af3f2e18eb929f638d555dbf7a62 (diff)
Coda: add spin lock to protect accesses to struct coda_inode_info.
We mostly need it to protect cached user permissions. The c_flags field is advisory, reading the wrong value is harmless and in the worst case we hit a slow path where we have to make an extra upcall to the userspace cache manager when revalidating a dentry or inode. Signed-off-by: Yoshihisa Abe <yoshiabe@cs.cmu.edu> Signed-off-by: Jan Harkes <jaharkes@cs.cmu.edu> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/coda')
-rw-r--r--fs/coda/cache.c17
-rw-r--r--fs/coda/cnode.c19
-rw-r--r--fs/coda/dir.c6
-rw-r--r--fs/coda/file.c12
-rw-r--r--fs/coda/inode.c2
5 files changed, 44 insertions, 12 deletions
diff --git a/fs/coda/cache.c b/fs/coda/cache.c
index a5bf5771a22a..9060f08e70cf 100644
--- a/fs/coda/cache.c
+++ b/fs/coda/cache.c
@@ -17,6 +17,7 @@
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/spinlock.h>
20 21
21#include <linux/coda.h> 22#include <linux/coda.h>
22#include <linux/coda_linux.h> 23#include <linux/coda_linux.h>
@@ -31,19 +32,23 @@ void coda_cache_enter(struct inode *inode, int mask)
31{ 32{
32 struct coda_inode_info *cii = ITOC(inode); 33 struct coda_inode_info *cii = ITOC(inode);
33 34
35 spin_lock(&cii->c_lock);
34 cii->c_cached_epoch = atomic_read(&permission_epoch); 36 cii->c_cached_epoch = atomic_read(&permission_epoch);
35 if (cii->c_uid != current_fsuid()) { 37 if (cii->c_uid != current_fsuid()) {
36 cii->c_uid = current_fsuid(); 38 cii->c_uid = current_fsuid();
37 cii->c_cached_perm = mask; 39 cii->c_cached_perm = mask;
38 } else 40 } else
39 cii->c_cached_perm |= mask; 41 cii->c_cached_perm |= mask;
42 spin_unlock(&cii->c_lock);
40} 43}
41 44
42/* remove cached acl from an inode */ 45/* remove cached acl from an inode */
43void coda_cache_clear_inode(struct inode *inode) 46void coda_cache_clear_inode(struct inode *inode)
44{ 47{
45 struct coda_inode_info *cii = ITOC(inode); 48 struct coda_inode_info *cii = ITOC(inode);
49 spin_lock(&cii->c_lock);
46 cii->c_cached_epoch = atomic_read(&permission_epoch) - 1; 50 cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
51 spin_unlock(&cii->c_lock);
47} 52}
48 53
49/* remove all acl caches */ 54/* remove all acl caches */
@@ -57,13 +62,15 @@ void coda_cache_clear_all(struct super_block *sb)
57int coda_cache_check(struct inode *inode, int mask) 62int coda_cache_check(struct inode *inode, int mask)
58{ 63{
59 struct coda_inode_info *cii = ITOC(inode); 64 struct coda_inode_info *cii = ITOC(inode);
60 int hit; 65 int hit;
61 66
62 hit = (mask & cii->c_cached_perm) == mask && 67 spin_lock(&cii->c_lock);
63 cii->c_uid == current_fsuid() && 68 hit = (mask & cii->c_cached_perm) == mask &&
64 cii->c_cached_epoch == atomic_read(&permission_epoch); 69 cii->c_uid == current_fsuid() &&
70 cii->c_cached_epoch == atomic_read(&permission_epoch);
71 spin_unlock(&cii->c_lock);
65 72
66 return hit; 73 return hit;
67} 74}
68 75
69 76
diff --git a/fs/coda/cnode.c b/fs/coda/cnode.c
index a7a780929eec..602240569c89 100644
--- a/fs/coda/cnode.c
+++ b/fs/coda/cnode.c
@@ -45,13 +45,15 @@ static void coda_fill_inode(struct inode *inode, struct coda_vattr *attr)
45static int coda_test_inode(struct inode *inode, void *data) 45static int coda_test_inode(struct inode *inode, void *data)
46{ 46{
47 struct CodaFid *fid = (struct CodaFid *)data; 47 struct CodaFid *fid = (struct CodaFid *)data;
48 return coda_fideq(&(ITOC(inode)->c_fid), fid); 48 struct coda_inode_info *cii = ITOC(inode);
49 return coda_fideq(&cii->c_fid, fid);
49} 50}
50 51
51static int coda_set_inode(struct inode *inode, void *data) 52static int coda_set_inode(struct inode *inode, void *data)
52{ 53{
53 struct CodaFid *fid = (struct CodaFid *)data; 54 struct CodaFid *fid = (struct CodaFid *)data;
54 ITOC(inode)->c_fid = *fid; 55 struct coda_inode_info *cii = ITOC(inode);
56 cii->c_fid = *fid;
55 return 0; 57 return 0;
56} 58}
57 59
@@ -71,6 +73,7 @@ struct inode * coda_iget(struct super_block * sb, struct CodaFid * fid,
71 cii = ITOC(inode); 73 cii = ITOC(inode);
72 /* we still need to set i_ino for things like stat(2) */ 74 /* we still need to set i_ino for things like stat(2) */
73 inode->i_ino = hash; 75 inode->i_ino = hash;
76 /* inode is locked and unique, no need to grab cii->c_lock */
74 cii->c_mapcount = 0; 77 cii->c_mapcount = 0;
75 unlock_new_inode(inode); 78 unlock_new_inode(inode);
76 } 79 }
@@ -107,14 +110,20 @@ int coda_cnode_make(struct inode **inode, struct CodaFid *fid, struct super_bloc
107} 110}
108 111
109 112
113/* Although we treat Coda file identifiers as immutable, there is one
114 * special case for files created during a disconnection where they may
115 * not be globally unique. When an identifier collision is detected we
116 * first try to flush the cached inode from the kernel and finally
117 * resort to renaming/rehashing in-place. Userspace remembers both old
118 * and new values of the identifier to handle any in-flight upcalls.
119 * The real solution is to use globally unique UUIDs as identifiers, but
120 * retrofitting the existing userspace code for this is non-trivial. */
110void coda_replace_fid(struct inode *inode, struct CodaFid *oldfid, 121void coda_replace_fid(struct inode *inode, struct CodaFid *oldfid,
111 struct CodaFid *newfid) 122 struct CodaFid *newfid)
112{ 123{
113 struct coda_inode_info *cii; 124 struct coda_inode_info *cii = ITOC(inode);
114 unsigned long hash = coda_f2i(newfid); 125 unsigned long hash = coda_f2i(newfid);
115 126
116 cii = ITOC(inode);
117
118 BUG_ON(!coda_fideq(&cii->c_fid, oldfid)); 127 BUG_ON(!coda_fideq(&cii->c_fid, oldfid));
119 128
120 /* replace fid and rehash inode */ 129 /* replace fid and rehash inode */
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index ccd98b0f2b0b..69fbbea75f1b 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -18,6 +18,7 @@
18#include <linux/errno.h> 18#include <linux/errno.h>
19#include <linux/string.h> 19#include <linux/string.h>
20#include <linux/smp_lock.h> 20#include <linux/smp_lock.h>
21#include <linux/spinlock.h>
21 22
22#include <asm/uaccess.h> 23#include <asm/uaccess.h>
23 24
@@ -617,7 +618,9 @@ static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd)
617 goto out; 618 goto out;
618 619
619 /* clear the flags. */ 620 /* clear the flags. */
621 spin_lock(&cii->c_lock);
620 cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH); 622 cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH);
623 spin_unlock(&cii->c_lock);
621 624
622bad: 625bad:
623 unlock_kernel(); 626 unlock_kernel();
@@ -691,7 +694,10 @@ int coda_revalidate_inode(struct dentry *dentry)
691 goto return_bad; 694 goto return_bad;
692 695
693 coda_flag_inode_children(inode, C_FLUSH); 696 coda_flag_inode_children(inode, C_FLUSH);
697
698 spin_lock(&cii->c_lock);
694 cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH); 699 cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH);
700 spin_unlock(&cii->c_lock);
695 } 701 }
696 702
697ok: 703ok:
diff --git a/fs/coda/file.c b/fs/coda/file.c
index ad3cd2abeeb4..c4e395781d41 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -16,6 +16,7 @@
16#include <linux/cred.h> 16#include <linux/cred.h>
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/smp_lock.h> 18#include <linux/smp_lock.h>
19#include <linux/spinlock.h>
19#include <linux/string.h> 20#include <linux/string.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <asm/uaccess.h> 22#include <asm/uaccess.h>
@@ -109,19 +110,24 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
109 110
110 coda_inode = coda_file->f_path.dentry->d_inode; 111 coda_inode = coda_file->f_path.dentry->d_inode;
111 host_inode = host_file->f_path.dentry->d_inode; 112 host_inode = host_file->f_path.dentry->d_inode;
113
114 cii = ITOC(coda_inode);
115 spin_lock(&cii->c_lock);
112 coda_file->f_mapping = host_file->f_mapping; 116 coda_file->f_mapping = host_file->f_mapping;
113 if (coda_inode->i_mapping == &coda_inode->i_data) 117 if (coda_inode->i_mapping == &coda_inode->i_data)
114 coda_inode->i_mapping = host_inode->i_mapping; 118 coda_inode->i_mapping = host_inode->i_mapping;
115 119
116 /* only allow additional mmaps as long as userspace isn't changing 120 /* only allow additional mmaps as long as userspace isn't changing
117 * the container file on us! */ 121 * the container file on us! */
118 else if (coda_inode->i_mapping != host_inode->i_mapping) 122 else if (coda_inode->i_mapping != host_inode->i_mapping) {
123 spin_unlock(&cii->c_lock);
119 return -EBUSY; 124 return -EBUSY;
125 }
120 126
121 /* keep track of how often the coda_inode/host_file has been mmapped */ 127 /* keep track of how often the coda_inode/host_file has been mmapped */
122 cii = ITOC(coda_inode);
123 cii->c_mapcount++; 128 cii->c_mapcount++;
124 cfi->cfi_mapcount++; 129 cfi->cfi_mapcount++;
130 spin_unlock(&cii->c_lock);
125 131
126 return host_file->f_op->mmap(host_file, vma); 132 return host_file->f_op->mmap(host_file, vma);
127} 133}
@@ -185,11 +191,13 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)
185 cii = ITOC(coda_inode); 191 cii = ITOC(coda_inode);
186 192
187 /* did we mmap this file? */ 193 /* did we mmap this file? */
194 spin_lock(&cii->c_lock);
188 if (coda_inode->i_mapping == &host_inode->i_data) { 195 if (coda_inode->i_mapping == &host_inode->i_data) {
189 cii->c_mapcount -= cfi->cfi_mapcount; 196 cii->c_mapcount -= cfi->cfi_mapcount;
190 if (!cii->c_mapcount) 197 if (!cii->c_mapcount)
191 coda_inode->i_mapping = &coda_inode->i_data; 198 coda_inode->i_mapping = &coda_inode->i_data;
192 } 199 }
200 spin_unlock(&cii->c_lock);
193 201
194 fput(cfi->cfi_container); 202 fput(cfi->cfi_container);
195 kfree(coda_file->private_data); 203 kfree(coda_file->private_data);
diff --git a/fs/coda/inode.c b/fs/coda/inode.c
index bfe8179b1295..0553f3bd7b1b 100644
--- a/fs/coda/inode.c
+++ b/fs/coda/inode.c
@@ -16,6 +16,7 @@
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/unistd.h> 17#include <linux/unistd.h>
18#include <linux/smp_lock.h> 18#include <linux/smp_lock.h>
19#include <linux/spinlock.h>
19#include <linux/file.h> 20#include <linux/file.h>
20#include <linux/vfs.h> 21#include <linux/vfs.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
@@ -51,6 +52,7 @@ static struct inode *coda_alloc_inode(struct super_block *sb)
51 ei->c_flags = 0; 52 ei->c_flags = 0;
52 ei->c_uid = 0; 53 ei->c_uid = 0;
53 ei->c_cached_perm = 0; 54 ei->c_cached_perm = 0;
55 spin_lock_init(&ei->c_lock);
54 return &ei->vfs_inode; 56 return &ei->vfs_inode;
55} 57}
56 58