git: 4603a50fa323 - stable/14 - fuse_vnop_copy_file_range(): use vn_lock_pair()

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 23 Nov 2023 04:01:04 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=4603a50fa32346f838c1f304d755e1204f6ad59a

commit 4603a50fa32346f838c1f304d755e1204f6ad59a
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-11-14 22:48:47 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-11-23 04:00:36 +0000

    fuse_vnop_copy_file_range(): use vn_lock_pair()
    
    (cherry picked from commit 318c56714aa8c170132ebe008f52904e0f119b5f)
---
 sys/fs/fuse/fuse_vnops.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c
index 3249e5988801..aead188276ec 100644
--- a/sys/fs/fuse/fuse_vnops.c
+++ b/sys/fs/fuse/fuse_vnops.c
@@ -879,23 +879,11 @@ fuse_vnop_copy_file_range(struct vop_copy_file_range_args *ap)
 		td = ap->a_fsizetd;
 	pid = td->td_proc->p_pid;
 
-	/* Lock both vnodes, avoiding risk of deadlock. */
-	do {
-		err = vn_lock(outvp, LK_EXCLUSIVE);
-		if (invp == outvp)
-			break;
-		if (err == 0) {
-			err = vn_lock(invp, LK_SHARED | LK_NOWAIT);
-			if (err == 0)
-				break;
-			VOP_UNLOCK(outvp);
-			err = vn_lock(invp, LK_SHARED);
-			if (err == 0)
-				VOP_UNLOCK(invp);
-		}
-	} while (err == 0);
-	if (err != 0)
-		return (err);
+	vn_lock_pair(invp, false, LK_SHARED, outvp, false, LK_EXCLUSIVE);
+	if (invp->v_data == NULL || outvp->v_data == NULL) {
+		err = EBADF;
+		goto unlock;
+	}
 
 	err = fuse_filehandle_getrw(invp, FREAD, &infufh, incred, pid);
 	if (err)