nfs: dont unhash target if renaming a directory
Move unhashing the target to after the check for existence and being a non-directory. If renaming a directory then the VFS already unhashes the target if it is not busy. If it's busy then acquiring more references during the rename makes no difference. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
committed by
Trond Myklebust
parent
28f79a1a69
commit
27226104e6
24
fs/nfs/dir.c
24
fs/nfs/dir.c
@@ -1579,15 +1579,6 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|||||||
struct dentry *dentry = NULL, *rehash = NULL;
|
struct dentry *dentry = NULL, *rehash = NULL;
|
||||||
int error = -EBUSY;
|
int error = -EBUSY;
|
||||||
|
|
||||||
/*
|
|
||||||
* To prevent any new references to the target during the rename,
|
|
||||||
* we unhash the dentry in advance.
|
|
||||||
*/
|
|
||||||
if (!d_unhashed(new_dentry)) {
|
|
||||||
d_drop(new_dentry);
|
|
||||||
rehash = new_dentry;
|
|
||||||
}
|
|
||||||
|
|
||||||
dfprintk(VFS, "NFS: rename(%s/%s -> %s/%s, ct=%d)\n",
|
dfprintk(VFS, "NFS: rename(%s/%s -> %s/%s, ct=%d)\n",
|
||||||
old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
|
old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
|
||||||
new_dentry->d_parent->d_name.name, new_dentry->d_name.name,
|
new_dentry->d_parent->d_name.name, new_dentry->d_name.name,
|
||||||
@@ -1599,9 +1590,19 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|||||||
* silly-rename succeeds, the copied dentry is hashed and becomes
|
* silly-rename succeeds, the copied dentry is hashed and becomes
|
||||||
* the new target.
|
* the new target.
|
||||||
*/
|
*/
|
||||||
if (new_inode && !S_ISDIR(new_inode->i_mode) &&
|
if (new_inode && !S_ISDIR(new_inode->i_mode)) {
|
||||||
atomic_read(&new_dentry->d_count) > 2) {
|
/*
|
||||||
|
* To prevent any new references to the target during the
|
||||||
|
* rename, we unhash the dentry in advance.
|
||||||
|
*/
|
||||||
|
if (!d_unhashed(new_dentry)) {
|
||||||
|
d_drop(new_dentry);
|
||||||
|
rehash = new_dentry;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (atomic_read(&new_dentry->d_count) > 2) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* copy the target dentry's name */
|
/* copy the target dentry's name */
|
||||||
dentry = d_alloc(new_dentry->d_parent,
|
dentry = d_alloc(new_dentry->d_parent,
|
||||||
&new_dentry->d_name);
|
&new_dentry->d_name);
|
||||||
@@ -1619,6 +1620,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|||||||
/* dentry still busy? */
|
/* dentry still busy? */
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ... prune child dentries and writebacks if needed.
|
* ... prune child dentries and writebacks if needed.
|
||||||
|
Reference in New Issue
Block a user