Skip to contentSkip to conversation

PATCH New NeilBrown 1 participant 9 messages Nov 30

Subsystems (2)
lore
Share & tools
lore

NeilBrown

author
#0 lore raw

In this v6 I've removed the change to d_revalidate in 1/8 as discussed with Trond, and clarified/improved some barriers in 2/8.

Thanks,
NeilBrown

[PATCH v6 1/8] nfs: fix open-blocking with d_fsdata [PATCH v6 2/8] nfs: remove d_drop()/d_alloc_parallel() from [PATCH v6 3/8] nfs: use d_splice_alias() in nfs_link() [PATCH v6 4/8] nfs: don't d_drop() before d_splice_alias() [PATCH v6 5/8] nfs: don't d_drop() before d_splice_alias() in [PATCH v6 6/8] nfs: Use d_alloc_trylock() in nfs_prime_dcache() [PATCH v6 7/8] nfs: use d_alloc_trylock() in silly-rename [PATCH v6 8/8] nfs: use d_duplicate()

author
#1 lore raw

PATCH v6 1/8 nfs: fix open-blocking with d_fsdata

From: NeilBrown <[email protected]>

The logic described in block_revalidate() that ->d_lock must be taken in lookup_open() missed the fact that sometimes lookup_open() isn't called.

If open_last_lookups() is called while still in RCU-walk and lookup_fast() finds a dentry, it does not take ->d_lock or increment d_count() before calling d_revalidate() - only afterwards.

So on that path d_count() can be incremented and the file opened *after* nfs_unlink() has checked d_count() and set NFS_FSDATA_BLOCKED. So an application could have the file open when it is unlinked on the server.

To fix this we need block_revalidate() to ensure the RCU-walk path is blocked as well. This is easily done with
write_seqcount_invalidate(&dentry->d_seq);
*after* setting ->d_fsdata.

legitimize_path() will increment d_count() and then check d_seq. The write_seqcount_invalidate() call will cause that check to fail if nfs_unlink() has already seen d_count() being only 1. So the RCU-walk will fail with -ECHILD and it will be retried as a ref-walk. This requires that in RCU-walk, ->d_fsdata is loaded *after* read_seqcount_begin() loaded ->d_seq, which is assured e.g the read_seqcount_retry() calls on ->d_seq in lookup_fast.

Further, the test on NFS_FSDATA_BLOCKED in the LOOKUP_RCU case of __nfs_lookup_validate() should use smp_load_acquire() just like the non-LOOKUP_RCU case. This ensures that if d_fsdata is seen to be NULL, then any writes before unblock_revalidate() will be visible in the remainder of the nfs_lookup_revalidate() handling.

Fixes 3c59366c207e ("NFS: don't unhash dentry during unlink/rename")
Fixes 99bc9f2eb3f7 ("NFS: add barriers when testing for NFS_FSDATA_BLOCKED")
---
 fs/nfs/dir.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)
fs/nfs/dir.c +21 -6
index 49437037f948..6938850d7a94 100644
@@ -1834,7 +1834,8 @@ static int
 __nfs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
 {
 	if (flags & LOOKUP_RCU) {
-		if (dentry->d_fsdata == NFS_FSDATA_BLOCKED)
+		/* acquire barrier matches release in unblock_revalidate(). */
+		if (smp_load_acquire(&dentry->d_fsdata) == NFS_FSDATA_BLOCKED)
 			return -ECHILD;
 	} else {
 		/* Wait for unlink to complete - see unblock_revalidate() */
@@ -1858,15 +1859,29 @@ static void block_revalidate(struct dentry *dentry)
 	/* old devname - just in case */
 	kfree(dentry->d_fsdata);
 
+	dentry->d_fsdata = NFS_FSDATA_BLOCKED;
+
 	/* Any new reference that could lead to an open
-	 * will take ->d_lock in lookup_open() -> d_lookup().
-	 * Holding this lock ensures we cannot race with
-	 * __nfs_lookup_revalidate() and removes and need
-	 * for further barriers.
+	 * will either:
+	 *  - take ->d_lock in lookup_open() -> d_lookup() or
+	 *  - will check d_seq in legitimize_path() or similar
+	 *    after taking the reference.
+	 *
+	 * Holding this lock and invalidating ->d_seq *after* recording
+	 * NFS_FSDATA_BLOCKED ensures we cannot race with
+	 * __nfs_lookup_revalidate().
+	 * If __nfs_lookup_revalidate() doesn't see NFS_FSDATA_BLOCKED then:
+	 * In the ref-walk case - d_lookup() will have incremented
+	 * d_count() before we check it.
+	 * In the RCU-walk case - ->d_seq must have been sampled before
+	 * we call write_seqcount_invalidate() below (because it was sampled
+	 * before we set NFS_FSDATA_BLOCKED) so d_count() will have been
+	 * incremented or the d_seq check will fail in legitimize_path()
+	 * (or both).
 	 */
 	lockdep_assert_held(&dentry->d_lock);
+	write_seqcount_invalidate(&dentry->d_seq);
 
-	dentry->d_fsdata = NFS_FSDATA_BLOCKED;
 }
 
 static void unblock_revalidate(struct dentry *dentry)

base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d

Signature · 1 line
2.50.0.107.gf914562f5916.dirty
author
#2 lore raw

PATCH v6 2/8 nfs: remove d_drop()/d_alloc_parallel() from nfs_atomic_open()

In reply to NeilBrown

From: NeilBrown <[email protected]>

It is important that two non-create NFS "open"s of a negative dentry don't race. They both have only a shared lock on i_rwsem and so could run concurrently, but they might both try to call d_splice_alias() at the same time which is confusing at best.

nfs_atomic_open() currently avoids this by discarding the negative dentry and creating a new one using d_alloc_parallel(). Only one thread can successfully get the d_in_lookup() dentry, the other will wait for the first to finish, and can use the result of that first lookup.

A proposed locking change inverts the order between i_rwsem and d_alloc_parallel() so it will not be safe to call d_alloc_parallel() while holding i_rwsem - even shared.

This care should not be necessary. The only case where it is currently needed is when O_CREAT was not requested, and a negative dentry exists in the dcache and was approved as valid by ->d_revalidate. lookup_fast_for_open() will find such a dentry so open_last_lookups() will bypass lookup_open() and no call to nfs_atomic_open() will be attempted. Unless...

If lookup_fast_for_open() does *not* find a dentry, but a concurrent thread starts a lookup immediately afterwards, the result of the lookup may be found in lookup_open() (by d_lookup() or d_alloc_parallel()). In this case and this case only a negative hashed dentry will be passed to ->atomic_open() while the parent lock is held shared.

It might be good for lookup_open() to detect this and handle it the same way that a result from lookup_fast_for_open() is handled. However nfs_atomic_open() can achieve the same result without that help.

nfs_atomic_open() cannot rely on O_CREAT to determine if nfs4_lookup_revalidate() was called with LOOKUP_CREATE or not as O_CREAT might be cleared if there are permission issues. However it can rely on the "mode" argument which will be zero when O_CREAT was not requested (build_open_flags() and others ensure this).

So if nfs_atomic_open() is called with a hashed negative dentry and with mode of zero, then it can be certain that nfs4_lookup_revalidate() was called without LOOKUP_CREATE so nfs_lookup_revalidate_negative() will have done a proper revalidation and the target is known not to exist. In that case it can safely return -ENOENT.

The other possible cases are:
- the dentry is in-lookup (it cannot be hashed-positive)
- mode is non-zero, so O_CREAT was requested and exclusive lock was taken on the parent.
In both these cases nfs_atomic_open() has exclusive access to the dentry and creating a new in-lookup dentry is not needed.

This means that the d_drop() and d_alloc_parallel() calls in nfs_atomic_open() are no longer needed to provide exclusion and can be removed.

There is still a d_drop() which allowed d_splice_alias() to succeed. This will be removed in a future patch.

nfs_atomic_open() already returns -ENOENT for a non-d_in_lookup() dentry in the O_DIRECTORY case. In this case mode must be zero, so this can be combined with the new test to have a single place that checks d_in_lookup().

---
 fs/nfs/dir.c | 39 ++++++++-------------------------------
 1 file changed, 8 insertions(+), 31 deletions(-)
fs/nfs/dir.c +8 -31
index 6938850d7a94..06708ee96b04 100644
@@ -2129,7 +2129,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 	struct inode *inode;
 	unsigned int lookup_flags = 0;
 	unsigned long dir_verifier;
-	bool switched = false;
 	int created = 0;
 	int err;
 
@@ -2143,16 +2142,16 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 	if (err)
 		return err;
 
+	if (mode == 0 && !d_in_lookup(dentry)) {
+		/*
+		 * Create was not requested, ->d_revalidated accepted
+		 * this negative dentry, so no need to lookup or open.
+		 */
+		return -ENOENT;
+	}
+
 	/* NFS only supports OPEN on regular files */
 	if ((open_flags & O_DIRECTORY)) {
-		if (!d_in_lookup(dentry)) {
-			/*
-			 * Hashed negative dentry with O_DIRECTORY: dentry was
-			 * revalidated and is fine, no need to perform lookup
-			 * again
-			 */
-			return -ENOENT;
-		}
 		lookup_flags = LOOKUP_OPEN|LOOKUP_DIRECTORY;
 		goto no_open;
 	}
@@ -2174,17 +2173,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 		attr.ia_size = 0;
 	}
 
-	if (!(open_flags & O_CREAT) && !d_in_lookup(dentry)) {
-		d_drop(dentry);
-		switched = true;
-		dentry = d_alloc_parallel(dentry->d_parent,
-					  &dentry->d_name);
-		if (IS_ERR(dentry))
-			return PTR_ERR(dentry);
-		if (unlikely(!d_in_lookup(dentry)))
-			return finish_no_open(file, dentry);
-	}
-
 	ctx = create_nfs_open_context(dentry, open_flags, file);
 	err = PTR_ERR(ctx);
 	if (IS_ERR(ctx))
@@ -2235,10 +2223,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 	trace_nfs_atomic_open_exit(dir, ctx, open_flags, err);
 	put_nfs_open_context(ctx);
 out:
-	if (unlikely(switched)) {
-		d_lookup_done(dentry);
-		dput(dentry);
-	}
 	return err;
 
 no_open:
@@ -2261,13 +2245,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 			res = ERR_PTR(-EOPENSTALE);
 		}
 	}
-	if (switched) {
-		d_lookup_done(dentry);
-		if (!res)
-			res = dentry;
-		else
-			dput(dentry);
-	}
 	return finish_no_open(file, res);
 }
 EXPORT_SYMBOL_GPL(nfs_atomic_open);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
author
#3 lore raw

PATCH v6 3/8 nfs: use d_splice_alias() in nfs_link()

In reply to NeilBrown

From: NeilBrown <[email protected]>

When filename_linkat() calls filename_create() which ultimately calls ->lookup, the flags LOOKUP_CREATE|LOOKUP_EXCL are passed. nfs_lookup() treats this as an exclusive create (which it is) and skips the ->lookup, leaving the dentry unchanged.

Currently that means nfs_link() can get a hashed dentry (if the name was already in the cache) or an unhashed dentry (if it wasn't). As none of d_add(), d_instantiate(), d_splice_alias() could handle both of these, nfs_link() calls d_drop() and then d_add().

Recent changes to d_splice_alias() mean that it *can* work with either hashed or unhashed dentries. Future changes to locking mean that it will be unsafe to d_drop() a dentry while an operation (in this case "link()") is still ongoing.

So change to use d_splice_alias(), and not to d_drop() until an error is detected (as in that case was can't be sure what is actually on the server).

Also update the comment for nfs_is_exclusive_create() to note that link(), mkdir(), mknod(), symlink() all appear as exclusive creates. Those other than link() already used d_splice_alias() via nfs_add_or_obtain().

Possibly nfs_is_exclusive_create() should return true even with NFSv2 when the request isn't an open (not LOOKUP_OPEN).

---
 fs/nfs/dir.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/nfs/dir.c +6 -2
index 06708ee96b04..836be9e37341 100644
@@ -1572,6 +1572,9 @@ static int nfs_check_verifier(struct inode *dir, struct dentry *dentry,
 /*
  * Use intent information to check whether or not we're going to do
  * an O_EXCL create using this path component.
+ * Note that link(), mkdir(), mknod(), symlink() all appear as
+ * exclusive creation.  Regular file creation could be distinguished
+ * with LOOKUP_OPEN.
  */
 static int nfs_is_exclusive_create(struct inode *dir, unsigned int flags)
 {
@@ -2702,14 +2705,15 @@ nfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
 		old_dentry, dentry);
 
 	trace_nfs_link_enter(inode, dir, dentry);
-	d_drop(dentry);
 	if (S_ISREG(inode->i_mode))
 		nfs_sync_inode(inode);
 	error = NFS_PROTO(dir)->link(inode, dir, &dentry->d_name);
 	if (error == 0) {
 		nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
 		ihold(inode);
-		d_add(dentry, inode);
+		d_splice_alias(inode, dentry);
+	} else {
+		d_drop(dentry);
 	}
 	trace_nfs_link_exit(inode, dir, dentry, error);
 	return error;
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
author
#4 lore raw

PATCH v6 4/8 nfs: don't d_drop() before d_splice_alias()

In reply to NeilBrown

From: NeilBrown <[email protected]>

nfs_add_or_obtain() is used, often via nfs_instantiate(), to attach a newly created inode to the appropriate dentry - or to provide an alternate dentry.
It has to drop the dentry first, which is problematic for proposed locking changes.

As d_splice_alias() now works with hashed dentries, the d_drop() is no longer needed.

However we still d_drop() on error as the status of the name is uncertain.

_nfs4_open_and_get_state() is only used for files so we should be able to use d_instantiate(). However as that depends on the server for correctness, it is safer to stay with the current code pattern and use d_splice_alias() there too.

---
 fs/nfs/dir.c      | 4 ++--
 fs/nfs/nfs4proc.c | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)
fs/nfs/dir.c +2 -2
index 836be9e37341..fe04762eb10a 100644
@@ -2355,8 +2355,6 @@ nfs_add_or_obtain(struct dentry *dentry, struct nfs_fh *fhandle,
 	struct dentry *d;
 	int error;
 
-	d_drop(dentry);
-
 	if (fhandle->size == 0) {
 		error = NFS_PROTO(dir)->lookup(dir, dentry, &dentry->d_name,
 					       fhandle, fattr);
@@ -2374,6 +2372,8 @@ nfs_add_or_obtain(struct dentry *dentry, struct nfs_fh *fhandle,
 	inode = nfs_fhget(dentry->d_sb, fhandle, fattr);
 	d = d_splice_alias(inode, dentry);
 out:
+	if (IS_ERR(d))
+		d_drop(dentry);
 	dput(parent);
 	return d;
 out_error:
fs/nfs/nfs4proc.c +0 -1
index 6759fa61b9b4..1781bea5e3d2 100644
@@ -3118,7 +3118,6 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
 	nfs_set_verifier(dentry, dir_verifier);
 	if (d_really_is_negative(dentry)) {
 		struct dentry *alias;
-		d_drop(dentry);
 		alias = d_splice_alias(igrab(state->inode), dentry);
 		/* d_splice_alias() can't fail here - it's a non-directory */
 		if (alias) {
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
author
#5 lore raw

PATCH v6 5/8 nfs: don't d_drop() before d_splice_alias() in atomic_create.

In reply to NeilBrown

From: NeilBrown <[email protected]>

When atomic_create fails with -ENOENT we currently d_drop() the dentry and then re-add it (d_splice_alias()) with a NULL inode. This was because the dentry could be in-lookup or could be hashed-negative and d_splice_alias() couldn't handled hashed-negative dentries.

This drop-and-re-add will not work with proposed locking changes.

As d_splice_alias() now supports hashed dentries, we don't need the d_drop() until it is determined that some other error has occurred.

---
 fs/nfs/dir.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/nfs/dir.c +4 -3
index fe04762eb10a..779a0fde9299 100644
@@ -2189,7 +2189,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 		err = PTR_ERR(inode);
 		trace_nfs_atomic_open_exit(dir, ctx, open_flags, err);
 		put_nfs_open_context(ctx);
-		d_drop(dentry);
 		switch (err) {
 		case -ENOENT:
 			if (nfs_server_capable(dir, NFS_CAP_CASE_INSENSITIVE))
@@ -2198,7 +2197,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 				dir_verifier = nfs_save_change_attribute(dir);
 			nfs_set_verifier(dentry, dir_verifier);
 			d_splice_alias(NULL, dentry);
-			break;
+			goto out;
 		case -EISDIR:
 		case -ENOTDIR:
 			if (open_flags & __O_REGULAR) {
@@ -2214,6 +2213,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 		default:
 			break;
 		}
+		d_drop(dentry);
 		goto out;
 	}
 	file->f_mode |= FMODE_CAN_ODIRECT;
@@ -2247,7 +2247,8 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
 			dput(res);
 			res = ERR_PTR(-EOPENSTALE);
 		}
-	}
+	} else
+		d_drop(dentry);
 	return finish_no_open(file, res);
 }
 EXPORT_SYMBOL_GPL(nfs_atomic_open);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
author
#6 lore raw

PATCH v6 6/8 nfs: Use d_alloc_trylock() in nfs_prime_dcache()

In reply to NeilBrown

From: NeilBrown <[email protected]>

NFS uses the results of readdir to prime the dcache. Using d_alloc_parallel() can block if there is a concurrent lookup. Blocking in that case is pointless as the lookup will add info to the dcache and there is no value in the readdir waiting to see if it should add the info too.

Also this call to d_alloc_parallel() is made while the parent directory is locked. A proposed change to locking will lock the parent later, after d_alloc_parallel(). This means it won't be safe to wait in d_alloc_parallel() while holding the directory lock.

So change to use d_alloc_trylock(), which removes the need for calculating the hash or doing a preliminary lookup.

---
 fs/nfs/dir.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
fs/nfs/dir.c +4 -7
index 779a0fde9299..d42973bc7e5b 100644
@@ -749,15 +749,12 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry,
 		if (filename.len == 2 && filename.name[1] == '.')
 			return;
 	}
-	filename.hash = full_name_hash(parent, filename.name, filename.len);
 
-	dentry = d_lookup(parent, &filename);
 again:
-	if (!dentry) {
-		dentry = d_alloc_parallel(parent, &filename);
-		if (IS_ERR(dentry))
-			return;
-	}
+	dentry = d_alloc_trylock(parent, &filename);
+	if (IS_ERR(dentry))
+		return;
+
 	if (!d_in_lookup(dentry)) {
 		/* Is there a mountpoint here? If so, just exit */
 		if (!nfs_fsid_equal(&NFS_SB(dentry->d_sb)->fsid,
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
author
#7 lore raw

PATCH v6 7/8 nfs: use d_alloc_trylock() in silly-rename

In reply to NeilBrown

From: NeilBrown <[email protected]>

Rather than performing a normal lookup (which will be awkward with future locking changes) use d_alloc_trylock() to find a dentry for an unused name, and then open-code the rest of lookup_slow() to see if it is free on the server.

---
 fs/nfs/unlink.c | 59 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 20 deletions(-)
fs/nfs/unlink.c +39 -20
index c8d712204e64..15c42d82a8d4 100644
@@ -448,7 +448,7 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)
 	static unsigned int sillycounter;
 	unsigned char silly[SILLYNAME_LEN + 1];
 	unsigned long long fileid;
-	struct dentry *sdentry;
+	struct dentry *sdentry, *old;
 	struct inode *inode = d_inode(dentry);
 	struct rpc_task *task;
 	int            error = -EBUSY;
@@ -465,26 +465,45 @@ nfs_sillyrename(struct inode *dir, struct dentry *dentry)
 
 	fileid = d_inode(dentry)->i_ino;
 
-	sdentry = NULL;
-	do {
+newname:
+	sillycounter++;
+	scnprintf(silly, sizeof(silly),
+		  SILLYNAME_PREFIX "%0*llx%0*x",
+		  SILLYNAME_FILEID_LEN, fileid,
+		  SILLYNAME_COUNTER_LEN, sillycounter);
+
+	dfprintk(VFS, "NFS: trying to rename %pd to %s\n", dentry, silly);
+	sdentry = d_alloc_trylock(dentry->d_parent, &QSTR(silly));
+	if (sdentry == ERR_PTR(-EWOULDBLOCK))
+		/* Name currently being looked up */
+		goto newname;
+	if (IS_ERR(sdentry))
+		goto out;
+	if (!d_in_lookup(sdentry)) {
+		if (d_really_is_negative(sdentry)) {
+			/* try to get an in-lookup dentry */
+			d_drop(sdentry);
+			sillycounter--;
+		}
 		dput(sdentry);
-		sillycounter++;
-		scnprintf(silly, sizeof(silly),
-			  SILLYNAME_PREFIX "%0*llx%0*x",
-			  SILLYNAME_FILEID_LEN, fileid,
-			  SILLYNAME_COUNTER_LEN, sillycounter);
-
-		dfprintk(VFS, "NFS: trying to rename %pd to %s\n",
-				dentry, silly);
-
-		sdentry = lookup_noperm(&QSTR(silly), dentry->d_parent);
-		/*
-		 * N.B. Better to return EBUSY here ... it could be
-		 * dangerous to delete the file while it's in use.
-		 */
-		if (IS_ERR(sdentry))
-			goto out;
-	} while (d_inode(sdentry) != NULL); /* need negative lookup */
+		goto newname;
+	}
+	/* This name isn't known locally - check on server */
+	old = nfs_lookup(dir, sdentry, 0);
+	d_lookup_done(sdentry);
+	/*
+	 * N.B. Better to return EBUSY here ... it could be
+	 * dangerous to delete the file while it's in use.
+	 */
+	if (IS_ERR(old)) {
+		dput(sdentry);
+		goto out;
+	}
+	if (old || d_is_positive(sdentry)) {
+		dput(old);
+		dput(sdentry);
+		goto newname;
+	}
 
 	ihold(inode);
 
Signature · 1 line
2.50.0.107.gf914562f5916.dirty
author
#8 lore raw

PATCH v6 8/8 nfs: use d_duplicate()

In reply to NeilBrown

From: NeilBrown <[email protected]>

As preparation for d_alloc_parallel() being allowed without the directory locked, use d_duplicate() to duplicate a dentry for silly rename.

This results in an in-lookup name, so d_lookup_done() must be called.

---
 fs/nfs/dir.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/nfs/dir.c +8 -5
index d42973bc7e5b..5a31363ec303 100644
@@ -2806,11 +2806,12 @@ int nfs_rename(const struct mnt_idmap *idmap, struct inode *old_dir,
 			spin_unlock(&new_dentry->d_lock);
 
 			/* copy the target dentry's name */
-			dentry = d_alloc(new_dentry->d_parent,
-					 &new_dentry->d_name);
-			if (!dentry)
+			dentry = d_duplicate(new_dentry);
+			if (IS_ERR(dentry)) {
+				/* Keep using -ETXTBSY error */
+				dentry = NULL;
 				goto out;
-
+			}
 			/* silly-rename the existing target ... */
 			err = nfs_sillyrename(new_dir, new_dentry);
 			if (err)
@@ -2875,8 +2876,10 @@ int nfs_rename(const struct mnt_idmap *idmap, struct inode *old_dir,
 		nfs_dentry_handle_enoent(old_dentry);
 
 	/* new dentry created? */
-	if (dentry)
+	if (dentry) {
+		d_lookup_done(dentry);
 		dput(dentry);
+	}
 	return error;
 }
 EXPORT_SYMBOL_GPL(nfs_rename);
Signature · 1 line
2.50.0.107.gf914562f5916.dirty