Commit 5a7e0a8c authored by Aneesh Kumar K.V's avatar Aneesh Kumar K.V Committed by Eric Van Hensbergen

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: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: default avatarVenkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>
parent f741a79e
...@@ -130,6 +130,7 @@ struct v9fs_inode { ...@@ -130,6 +130,7 @@ struct v9fs_inode {
#endif #endif
unsigned int cache_validity; unsigned int cache_validity;
struct p9_fid *writeback_fid; struct p9_fid *writeback_fid;
struct mutex v_mutex;
struct inode vfs_inode; struct inode vfs_inode;
}; };
......
...@@ -90,6 +90,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) ...@@ -90,6 +90,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
} }
file->private_data = fid; file->private_data = fid;
mutex_lock(&v9inode->v_mutex);
if (v9ses->cache && !v9inode->writeback_fid) { if (v9ses->cache && !v9inode->writeback_fid) {
/* /*
* clone a fid and add it to writeback_fid * clone a fid and add it to writeback_fid
...@@ -101,10 +102,12 @@ int v9fs_file_open(struct inode *inode, struct file *file) ...@@ -101,10 +102,12 @@ int v9fs_file_open(struct inode *inode, struct file *file)
fid = v9fs_writeback_fid(file->f_path.dentry); fid = v9fs_writeback_fid(file->f_path.dentry);
if (IS_ERR(fid)) { if (IS_ERR(fid)) {
err = PTR_ERR(fid); err = PTR_ERR(fid);
mutex_unlock(&v9inode->v_mutex);
goto out_error; goto out_error;
} }
v9inode->writeback_fid = (void *) fid; v9inode->writeback_fid = (void *) fid;
} }
mutex_unlock(&v9inode->v_mutex);
#ifdef CONFIG_9P_FSCACHE #ifdef CONFIG_9P_FSCACHE
if (v9ses->cache) if (v9ses->cache)
v9fs_cache_inode_set_cookie(inode, file); v9fs_cache_inode_set_cookie(inode, file);
......
...@@ -221,6 +221,7 @@ struct inode *v9fs_alloc_inode(struct super_block *sb) ...@@ -221,6 +221,7 @@ struct inode *v9fs_alloc_inode(struct super_block *sb)
#endif #endif
v9inode->writeback_fid = NULL; v9inode->writeback_fid = NULL;
v9inode->cache_validity = 0; v9inode->cache_validity = 0;
mutex_init(&v9inode->v_mutex);
return &v9inode->vfs_inode; return &v9inode->vfs_inode;
} }
...@@ -650,6 +651,7 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, ...@@ -650,6 +651,7 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
/* if we are opening a file, assign the open fid to the file */ /* if we are opening a file, assign the open fid to the file */
if (nd && nd->flags & LOOKUP_OPEN) { if (nd && nd->flags & LOOKUP_OPEN) {
v9inode = V9FS_I(dentry->d_inode); v9inode = V9FS_I(dentry->d_inode);
mutex_lock(&v9inode->v_mutex);
if (v9ses->cache && !v9inode->writeback_fid) { if (v9ses->cache && !v9inode->writeback_fid) {
/* /*
* clone a fid and add it to writeback_fid * 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,10 +663,12 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
inode_fid = v9fs_writeback_fid(dentry); inode_fid = v9fs_writeback_fid(dentry);
if (IS_ERR(inode_fid)) { if (IS_ERR(inode_fid)) {
err = PTR_ERR(inode_fid); err = PTR_ERR(inode_fid);
mutex_unlock(&v9inode->v_mutex);
goto error; goto error;
} }
v9inode->writeback_fid = (void *) inode_fid; v9inode->writeback_fid = (void *) inode_fid;
} }
mutex_unlock(&v9inode->v_mutex);
filp = lookup_instantiate_filp(nd, dentry, generic_file_open); filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
if (IS_ERR(filp)) { if (IS_ERR(filp)) {
err = PTR_ERR(filp); err = PTR_ERR(filp);
......
...@@ -245,6 +245,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode, ...@@ -245,6 +245,7 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
v9fs_set_create_acl(dentry, dacl, pacl); v9fs_set_create_acl(dentry, dacl, pacl);
v9inode = V9FS_I(inode); v9inode = V9FS_I(inode);
mutex_lock(&v9inode->v_mutex);
if (v9ses->cache && !v9inode->writeback_fid) { if (v9ses->cache && !v9inode->writeback_fid) {
/* /*
* clone a fid and add it to writeback_fid * 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,10 +257,12 @@ v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
inode_fid = v9fs_writeback_fid(dentry); inode_fid = v9fs_writeback_fid(dentry);
if (IS_ERR(inode_fid)) { if (IS_ERR(inode_fid)) {
err = PTR_ERR(inode_fid); err = PTR_ERR(inode_fid);
mutex_unlock(&v9inode->v_mutex);
goto error; goto error;
} }
v9inode->writeback_fid = (void *) inode_fid; v9inode->writeback_fid = (void *) inode_fid;
} }
mutex_unlock(&v9inode->v_mutex);
/* Since we are opening a file, assign the open fid to the file */ /* Since we are opening a file, assign the open fid to the file */
filp = lookup_instantiate_filp(nd, dentry, generic_file_open); filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
if (IS_ERR(filp)) { if (IS_ERR(filp)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment