aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>2011-03-08 06:09:46 -0500
committerEric Van Hensbergen <ericvh@gmail.com>2011-03-22 16:43:35 -0400
commit5a7e0a8cf50cf905403f5a498e86d1f97cfcf51b (patch)
tree3f20f98db76f7a221f397630a03e6089c1208510
parentf741a79e982cf56d7584435bad663553ffe6715f (diff)
fs/9p: Fix race in initializing writeback fid
When two process open the same file we can end up with both of them allocating the writeback_fid. Add a new mutex which can be used for synchronizing v9fs_inode member values. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
-rw-r--r--fs/9p/v9fs.h1
-rw-r--r--fs/9p/vfs_file.c3
-rw-r--r--fs/9p/vfs_inode.c4
-rw-r--r--fs/9p/vfs_inode_dotl.c3
4 files changed, 11 insertions, 0 deletions
diff --git a/fs/9p/v9fs.h b/fs/9p/v9fs.h
index bd8496db135b..89657e865162 100644
--- a/fs/9p/v9fs.h
+++ b/fs/9p/v9fs.h
@@ -130,6 +130,7 @@ struct v9fs_inode {
130#endif 130#endif
131 unsigned int cache_validity; 131 unsigned int cache_validity;
132 struct p9_fid *writeback_fid; 132 struct p9_fid *writeback_fid;
133 struct mutex v_mutex;
133 struct inode vfs_inode; 134 struct inode vfs_inode;
134}; 135};
135 136
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index 78bcb97c3425..3337d58d0fc5 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -90,6 +90,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
90 } 90 }
91 91
92 file->private_data = fid; 92 file->private_data = fid;
93 mutex_lock(&v9inode->v_mutex);
93 if (v9ses->cache && !v9inode->writeback_fid) { 94 if (v9ses->cache && !v9inode->writeback_fid) {
94 /* 95 /*
95 * clone a fid and add it to writeback_fid 96 * clone a fid and add it to writeback_fid
@@ -101,10 +102,12 @@ int v9fs_file_open(struct inode *inode, struct file *file)
101 fid = v9fs_writeback_fid(file->f_path.dentry); 102 fid = v9fs_writeback_fid(file->f_path.dentry);
102 if (IS_ERR(fid)) { 103 if (IS_ERR(fid)) {
103 err = PTR_ERR(fid); 104 err = PTR_ERR(fid);
105 mutex_unlock(&v9inode->v_mutex);
104 goto out_error; 106 goto out_error;
105 } 107 }
106 v9inode->writeback_fid = (void *) fid; 108 v9inode->writeback_fid = (void *) fid;
107 } 109 }
110 mutex_unlock(&v9inode->v_mutex);
108#ifdef CONFIG_9P_FSCACHE 111#ifdef CONFIG_9P_FSCACHE
109 if (v9ses->cache) 112 if (v9ses->cache)
110 v9fs_cache_inode_set_cookie(inode, file); 113 v9fs_cache_inode_set_cookie(inode, file);
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 8a2c232f708a..c6cef2495f00 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -221,6 +221,7 @@ struct inode *v9fs_alloc_inode(struct super_block *sb)
221#endif 221#endif
222 v9inode->writeback_fid = NULL; 222 v9inode->writeback_fid = NULL;
223 v9inode->cache_validity = 0; 223 v9inode->cache_validity = 0;
224 mutex_init(&v9inode->v_mutex);
224 return &v9inode->vfs_inode; 225 return &v9inode->vfs_inode;
225} 226}
226 227
@@ -650,6 +651,7 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
650 /* if we are opening a file, assign the open fid to the file */ 651 /* if we are opening a file, assign the open fid to the file */
651 if (nd && nd->flags & LOOKUP_OPEN) { 652 if (nd && nd->flags & LOOKUP_OPEN) {
652 v9inode = V9FS_I(dentry->d_inode); 653 v9inode = V9FS_I(dentry->d_inode);
654 mutex_lock(&v9inode->v_mutex);
653 if (v9ses->cache && !v9inode->writeback_fid) { 655 if (v9ses->cache && !v9inode->writeback_fid) {
654 /* 656 /*
655 * clone a fid and add it to writeback_fid 657 * clone a fid and add it to writeback_fid
@@ -661,10 +663,12 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
661 inode_fid = v9fs_writeback_fid(dentry); 663 inode_fid = v9fs_writeback_fid(dentry);
662 if (IS_ERR(inode_fid)) { 664 if (IS_ERR(inode_fid)) {
663 err = PTR_ERR(inode_fid); 665 err = PTR_ERR(inode_fid);
666 mutex_unlock(&v9inode->v_mutex);
664 goto error; 667 goto error;
665 } 668 }
666 v9inode->writeback_fid = (void *) inode_fid; 669 v9inode->writeback_fid = (void *) inode_fid;
667 } 670 }
671 mutex_unlock(&v9inode->v_mutex);
668 filp = lookup_instantiate_filp(nd, dentry, generic_file_open); 672 filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
669 if (IS_ERR(filp)) { 673 if (IS_ERR(filp)) {
670 err = PTR_ERR(filp); 674 err = PTR_ERR(filp);
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index 67c138e94feb..327c578c7ba6 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -245,6 +245,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
245 v9fs_set_create_acl(dentry, dacl, pacl); 245 v9fs_set_create_acl(dentry, dacl, pacl);
246 246
247 v9inode = V9FS_I(inode); 247 v9inode = V9FS_I(inode);
248 mutex_lock(&v9inode->v_mutex);
248 if (v9ses->cache && !v9inode->writeback_fid) { 249 if (v9ses->cache && !v9inode->writeback_fid) {
249 /* 250 /*
250 * clone a fid and add it to writeback_fid 251 * clone a fid and add it to writeback_fid
@@ -256,10 +257,12 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
256 inode_fid = v9fs_writeback_fid(dentry); 257 inode_fid = v9fs_writeback_fid(dentry);
257 if (IS_ERR(inode_fid)) { 258 if (IS_ERR(inode_fid)) {
258 err = PTR_ERR(inode_fid); 259 err = PTR_ERR(inode_fid);
260 mutex_unlock(&v9inode->v_mutex);
259 goto error; 261 goto error;
260 } 262 }
261 v9inode->writeback_fid = (void *) inode_fid; 263 v9inode->writeback_fid = (void *) inode_fid;
262 } 264 }
265 mutex_unlock(&v9inode->v_mutex);
263 /* Since we are opening a file, assign the open fid to the file */ 266 /* Since we are opening a file, assign the open fid to the file */
264 filp = lookup_instantiate_filp(nd, dentry, generic_file_open); 267 filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
265 if (IS_ERR(filp)) { 268 if (IS_ERR(filp)) {