diff options
author | Yoshihisa Abe <yoshiabe@cs.cmu.edu> | 2010-10-25 02:03:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-25 11:02:40 -0400 |
commit | b5ce1d83a62fc109d8e815b1fc71dcdb0d26bc49 (patch) | |
tree | ea537c1b6436c36bee3b33d8b4f750124fd7d661 /fs/coda/file.c | |
parent | 3a99c6319064af3f2e18eb929f638d555dbf7a62 (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/file.c')
-rw-r--r-- | fs/coda/file.c | 12 |
1 files changed, 10 insertions, 2 deletions
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); |