aboutsummaryrefslogtreecommitdiffstats
path: root/fs/coda/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/coda/file.c')
-rw-r--r--fs/coda/file.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/fs/coda/file.c b/fs/coda/file.c
index ad3cd2abeeb4..c8b50ba4366a 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -15,7 +15,7 @@
15#include <linux/stat.h> 15#include <linux/stat.h>
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/spinlock.h>
19#include <linux/string.h> 19#include <linux/string.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <asm/uaccess.h> 21#include <asm/uaccess.h>
@@ -109,19 +109,24 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
109 109
110 coda_inode = coda_file->f_path.dentry->d_inode; 110 coda_inode = coda_file->f_path.dentry->d_inode;
111 host_inode = host_file->f_path.dentry->d_inode; 111 host_inode = host_file->f_path.dentry->d_inode;
112
113 cii = ITOC(coda_inode);
114 spin_lock(&cii->c_lock);
112 coda_file->f_mapping = host_file->f_mapping; 115 coda_file->f_mapping = host_file->f_mapping;
113 if (coda_inode->i_mapping == &coda_inode->i_data) 116 if (coda_inode->i_mapping == &coda_inode->i_data)
114 coda_inode->i_mapping = host_inode->i_mapping; 117 coda_inode->i_mapping = host_inode->i_mapping;
115 118
116 /* only allow additional mmaps as long as userspace isn't changing 119 /* only allow additional mmaps as long as userspace isn't changing
117 * the container file on us! */ 120 * the container file on us! */
118 else if (coda_inode->i_mapping != host_inode->i_mapping) 121 else if (coda_inode->i_mapping != host_inode->i_mapping) {
122 spin_unlock(&cii->c_lock);
119 return -EBUSY; 123 return -EBUSY;
124 }
120 125
121 /* keep track of how often the coda_inode/host_file has been mmapped */ 126 /* keep track of how often the coda_inode/host_file has been mmapped */
122 cii = ITOC(coda_inode);
123 cii->c_mapcount++; 127 cii->c_mapcount++;
124 cfi->cfi_mapcount++; 128 cfi->cfi_mapcount++;
129 spin_unlock(&cii->c_lock);
125 130
126 return host_file->f_op->mmap(host_file, vma); 131 return host_file->f_op->mmap(host_file, vma);
127} 132}
@@ -138,8 +143,6 @@ int coda_open(struct inode *coda_inode, struct file *coda_file)
138 if (!cfi) 143 if (!cfi)
139 return -ENOMEM; 144 return -ENOMEM;
140 145
141 lock_kernel();
142
143 error = venus_open(coda_inode->i_sb, coda_i2f(coda_inode), coda_flags, 146 error = venus_open(coda_inode->i_sb, coda_i2f(coda_inode), coda_flags,
144 &host_file); 147 &host_file);
145 if (!host_file) 148 if (!host_file)
@@ -147,7 +150,6 @@ int coda_open(struct inode *coda_inode, struct file *coda_file)
147 150
148 if (error) { 151 if (error) {
149 kfree(cfi); 152 kfree(cfi);
150 unlock_kernel();
151 return error; 153 return error;
152 } 154 }
153 155
@@ -159,8 +161,6 @@ int coda_open(struct inode *coda_inode, struct file *coda_file)
159 161
160 BUG_ON(coda_file->private_data != NULL); 162 BUG_ON(coda_file->private_data != NULL);
161 coda_file->private_data = cfi; 163 coda_file->private_data = cfi;
162
163 unlock_kernel();
164 return 0; 164 return 0;
165} 165}
166 166
@@ -171,9 +171,7 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)
171 struct coda_file_info *cfi; 171 struct coda_file_info *cfi;
172 struct coda_inode_info *cii; 172 struct coda_inode_info *cii;
173 struct inode *host_inode; 173 struct inode *host_inode;
174 int err = 0; 174 int err;
175
176 lock_kernel();
177 175
178 cfi = CODA_FTOC(coda_file); 176 cfi = CODA_FTOC(coda_file);
179 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 177 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
@@ -185,18 +183,18 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)
185 cii = ITOC(coda_inode); 183 cii = ITOC(coda_inode);
186 184
187 /* did we mmap this file? */ 185 /* did we mmap this file? */
186 spin_lock(&cii->c_lock);
188 if (coda_inode->i_mapping == &host_inode->i_data) { 187 if (coda_inode->i_mapping == &host_inode->i_data) {
189 cii->c_mapcount -= cfi->cfi_mapcount; 188 cii->c_mapcount -= cfi->cfi_mapcount;
190 if (!cii->c_mapcount) 189 if (!cii->c_mapcount)
191 coda_inode->i_mapping = &coda_inode->i_data; 190 coda_inode->i_mapping = &coda_inode->i_data;
192 } 191 }
192 spin_unlock(&cii->c_lock);
193 193
194 fput(cfi->cfi_container); 194 fput(cfi->cfi_container);
195 kfree(coda_file->private_data); 195 kfree(coda_file->private_data);
196 coda_file->private_data = NULL; 196 coda_file->private_data = NULL;
197 197
198 unlock_kernel();
199
200 /* VFS fput ignores the return value from file_operations->release, so 198 /* VFS fput ignores the return value from file_operations->release, so
201 * there is no use returning an error here */ 199 * there is no use returning an error here */
202 return 0; 200 return 0;
@@ -207,7 +205,7 @@ int coda_fsync(struct file *coda_file, int datasync)
207 struct file *host_file; 205 struct file *host_file;
208 struct inode *coda_inode = coda_file->f_path.dentry->d_inode; 206 struct inode *coda_inode = coda_file->f_path.dentry->d_inode;
209 struct coda_file_info *cfi; 207 struct coda_file_info *cfi;
210 int err = 0; 208 int err;
211 209
212 if (!(S_ISREG(coda_inode->i_mode) || S_ISDIR(coda_inode->i_mode) || 210 if (!(S_ISREG(coda_inode->i_mode) || S_ISDIR(coda_inode->i_mode) ||
213 S_ISLNK(coda_inode->i_mode))) 211 S_ISLNK(coda_inode->i_mode)))
@@ -218,11 +216,8 @@ int coda_fsync(struct file *coda_file, int datasync)
218 host_file = cfi->cfi_container; 216 host_file = cfi->cfi_container;
219 217
220 err = vfs_fsync(host_file, datasync); 218 err = vfs_fsync(host_file, datasync);
221 if ( !err && !datasync ) { 219 if (!err && !datasync)
222 lock_kernel();
223 err = venus_fsync(coda_inode->i_sb, coda_i2f(coda_inode)); 220 err = venus_fsync(coda_inode->i_sb, coda_i2f(coda_inode));
224 unlock_kernel();
225 }
226 221
227 return err; 222 return err;
228} 223}