Skip to content

Commit 3bcb39b

Browse files
author
Al Viro
committed
cifs: have ->mkdir() handle race with another client sanely
if we have mkdir request reported successful *and* simulating lookup gets us a non-directory (which is possible if another client has managed to get rmdir and create in between), the sane action is not to mangle ->i_mode of non-directory inode to S_IFDIR | mode, it's "report success and return with dentry negative unhashed" - that way the next lookup will do the right thing. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 4ab5260 commit 3bcb39b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

fs/cifs/inode.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,16 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode,
17391739
if (rc)
17401740
return rc;
17411741

1742+
if (!S_ISDIR(inode->i_mode)) {
1743+
/*
1744+
* mkdir succeeded, but another client has managed to remove the
1745+
* sucker and replace it with non-directory. Return success,
1746+
* but don't leave the child in dcache.
1747+
*/
1748+
iput(inode);
1749+
d_drop(dentry);
1750+
return 0;
1751+
}
17421752
/*
17431753
* setting nlink not necessary except in cases where we failed to get it
17441754
* from the server or was set bogus. Also, since this is a brand new
@@ -1790,7 +1800,7 @@ cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode,
17901800
}
17911801
}
17921802
d_instantiate(dentry, inode);
1793-
return rc;
1803+
return 0;
17941804
}
17951805

17961806
static int

0 commit comments

Comments
 (0)