Skip to content

Commit 73f5071

Browse files
kvaneeshericvh
authored andcommitted
fs/9p: Always ask new inode in lookup for cache mode disabled
This make sure we don't end up reusing the unlinked inode object. The ideal way is to use inode i_generation. But i_generation is not available in userspace always. Signed-off-by: Aneesh Kumar K.V <[email protected]>
1 parent f88657c commit 73f5071

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

fs/9p/vfs_inode.c

+21-7
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
825825
struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
826826
struct nameidata *nameidata)
827827
{
828+
struct dentry *res;
828829
struct super_block *sb;
829830
struct v9fs_session_info *v9ses;
830831
struct p9_fid *dfid, *fid;
@@ -856,22 +857,35 @@ struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
856857

857858
return ERR_PTR(result);
858859
}
859-
860-
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
860+
/*
861+
* Make sure we don't use a wrong inode due to parallel
862+
* unlink. For cached mode create calls request for new
863+
* inode. But with cache disabled, lookup should do this.
864+
*/
865+
if (v9ses->cache)
866+
inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
867+
else
868+
inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
861869
if (IS_ERR(inode)) {
862870
result = PTR_ERR(inode);
863871
inode = NULL;
864872
goto error;
865873
}
866-
867874
result = v9fs_fid_add(dentry, fid);
868875
if (result < 0)
869876
goto error_iput;
870-
871877
inst_out:
872-
d_add(dentry, inode);
873-
return NULL;
874-
878+
/*
879+
* If we had a rename on the server and a parallel lookup
880+
* for the new name, then make sure we instantiate with
881+
* the new name. ie look up for a/b, while on server somebody
882+
* moved b under k and client parallely did a lookup for
883+
* k/b.
884+
*/
885+
res = d_materialise_unique(dentry, inode);
886+
if (!IS_ERR(res))
887+
return res;
888+
result = PTR_ERR(res);
875889
error_iput:
876890
iput(inode);
877891
error:

0 commit comments

Comments
 (0)