git: d9ea7e2b1e69 - main - vfs: factor FAILIFEXISTS handling out of vfs_lookup

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Thu, 24 Mar 2022 11:22:33 UTC
The branch main has been updated by mjg:

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

commit d9ea7e2b1e696697b532535678c05a10d6635084
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2022-03-13 17:36:51 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2022-03-24 11:22:20 +0000

    vfs: factor FAILIFEXISTS handling out of vfs_lookup
---
 sys/kern/vfs_lookup.c | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index f4fabe55b06e..29db916382b1 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -853,6 +853,32 @@ bad:
 	return (error);
 }
 
+/*
+ * FAILIFEXISTS handling.
+ *
+ * XXX namei called with LOCKPARENT but not LOCKLEAF has the strange
+ * behaviour of leaving the vnode unlocked if the target is the same
+ * vnode as the parent.
+ */
+static int __noinline
+vfs_lookup_failifexists(struct nameidata *ndp)
+{
+	struct componentname *cnp __diagused;
+
+	cnp = &ndp->ni_cnd;
+
+	MPASS((cnp->cn_flags & ISSYMLINK) == 0);
+	if (ndp->ni_vp == ndp->ni_dvp)
+		vrele(ndp->ni_dvp);
+	else
+		vput(ndp->ni_dvp);
+	vrele(ndp->ni_vp);
+	ndp->ni_dvp = NULL;
+	ndp->ni_vp = NULL;
+	NDFREE_PNBUF(ndp);
+	return (EEXIST);
+}
+
 /*
  * Search a pathname.
  * This is a very central and rather complicated routine.
@@ -1388,7 +1414,7 @@ success_right_lock:
 		if ((cnp->cn_flags & ISDOTDOT) == 0)
 			nameicap_tracker_add(ndp, ndp->ni_vp);
 		if ((cnp->cn_flags & (FAILIFEXISTS | ISSYMLINK)) == FAILIFEXISTS)
-			goto bad_eexist;
+			return (vfs_lookup_failifexists(ndp));
 	}
 	return (0);
 
@@ -1405,24 +1431,6 @@ bad:
 bad_unlocked:
 	ndp->ni_vp = NULL;
 	return (error);
-bad_eexist:
-	/*
-	 * FAILIFEXISTS handling.
-	 *
-	 * XXX namei called with LOCKPARENT but not LOCKLEAF has the strange
-	 * behaviour of leaving the vnode unlocked if the target is the same
-	 * vnode as the parent.
-	 */
-	MPASS((cnp->cn_flags & ISSYMLINK) == 0);
-	if (ndp->ni_vp == ndp->ni_dvp)
-		vrele(ndp->ni_dvp);
-	else
-		vput(ndp->ni_dvp);
-	vrele(ndp->ni_vp);
-	ndp->ni_dvp = NULL;
-	ndp->ni_vp = NULL;
-	NDFREE_PNBUF(ndp);
-	return (EEXIST);
 }
 
 /*