git: c5adb35ede60 - stable/13 - fdesc_lookup(): the condition to use vn_vget_ino() is always true

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 06 Apr 2023 18:04:30 UTC
The branch stable/13 has been updated by kib:

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

commit c5adb35ede6018f56697dcf9f30f701922fe3ca0
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-03-23 19:28:08 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-04-06 18:04:10 +0000

    fdesc_lookup(): the condition to use vn_vget_ino() is always true
    
    (cherry picked from commit 7dca8fd1cb3f91e7a3c07b7f57af6d9d43d0c71c)
---
 sys/fs/fdescfs/fdesc_vnops.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/sys/fs/fdescfs/fdesc_vnops.c b/sys/fs/fdescfs/fdesc_vnops.c
index ae52ef5c3bea..e8aa9f81dc2e 100644
--- a/sys/fs/fdescfs/fdesc_vnops.c
+++ b/sys/fs/fdescfs/fdesc_vnops.c
@@ -348,26 +348,24 @@ fdesc_lookup(struct vop_lookup_args *ap)
 		goto bad;
 	fdropped = false;
 
-	/* Make sure we're not looking up the dvp itself. */
-	if (VTOFDESC(dvp)->fd_ix != FD_DESC + fd) {
-		/*
-		 * Unlock our root node (dvp) when doing this, since we might
-		 * deadlock since the vnode might be locked by another thread
-		 * and the root vnode lock will be obtained afterwards (in case
-		 * we're looking up the fd of the root vnode), which will be the
-		 * opposite lock order. Vhold the root vnode first so we don't
-		 * lose it.
-		 */
-		arg.ftype = Fdesc;
-		arg.fd_fd = fd;
-		arg.ix = FD_DESC + fd;
-		arg.fp = fp;
-		arg.td = td;
-		arg.fdropped = fdropped;
-		error = vn_vget_ino_gen(dvp, fdesc_get_ino_alloc, &arg,
-		    LK_EXCLUSIVE, &fvp);
-		fdropped = arg.fdropped;
-	}
+	/*
+	 * Make sure we do not deadlock looking up the dvp itself.
+	 *
+	 * Unlock our root node (dvp) when doing this, since we might
+	 * deadlock since the vnode might be locked by another thread
+	 * and the root vnode lock will be obtained afterwards (in case
+	 * we're looking up the fd of the root vnode), which will be the
+	 * opposite lock order.
+	 */
+	arg.ftype = Fdesc;
+	arg.fd_fd = fd;
+	arg.ix = FD_DESC + fd;
+	arg.fp = fp;
+	arg.td = td;
+	arg.fdropped = fdropped;
+	error = vn_vget_ino_gen(dvp, fdesc_get_ino_alloc, &arg,
+	    LK_EXCLUSIVE, &fvp);
+	fdropped = arg.fdropped;
 
 	if (!fdropped) {
 		/*