git: 1cb0045c971b - main - vfs: add MNTK_UNLOCKED_INSMNTQUE

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Sat, 19 Mar 2022 10:50:33 UTC
The branch main has been updated by mjg:

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

commit 1cb0045c971be75bea76e4aa3e1df2f92f1978bc
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2022-03-07 11:40:04 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2022-03-19 10:46:40 +0000

    vfs: add MNTK_UNLOCKED_INSMNTQUE
    
    Can be used when the fs at hand can synchronize insmntque with other
    means than the vnode lock.
    
    Reviewed by:    markj
    Tested by:      pho (previous version)
    Differential Revision:  https://reviews.freebsd.org/D34466
---
 sys/kern/vfs_subr.c | 11 +++++++++--
 sys/sys/mount.h     |  2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index c184530bbda6..7442153371a6 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1965,7 +1965,13 @@ insmntque1_int(struct vnode *vp, struct mount *mp, bool dtr)
 	KASSERT(vp->v_mount == NULL,
 		("insmntque: vnode already on per mount vnode list"));
 	VNASSERT(mp != NULL, vp, ("Don't call insmntque(foo, NULL)"));
-	ASSERT_VOP_ELOCKED(vp, "insmntque: non-locked vp");
+	if ((mp->mnt_kern_flag & MNTK_UNLOCKED_INSMNTQUE) == 0) {
+		ASSERT_VOP_ELOCKED(vp, "insmntque: non-locked vp");
+	} else {
+		KASSERT(!dtr,
+		    ("%s: can't have MNTK_UNLOCKED_INSMNTQUE and cleanup",
+		    __func__));
+	}
 
 	/*
 	 * We acquire the vnode interlock early to ensure that the
@@ -4400,6 +4406,7 @@ DB_SHOW_COMMAND(mount, db_show_mount)
 	MNT_KERN_FLAG(MNTK_RECURSE);
 	MNT_KERN_FLAG(MNTK_UPPER_WAITER);
 	MNT_KERN_FLAG(MNTK_LOOKUP_EXCL_DOTDOT);
+	MNT_KERN_FLAG(MNTK_UNLOCKED_INSMNTQUE);
 	MNT_KERN_FLAG(MNTK_USES_BCACHE);
 	MNT_KERN_FLAG(MNTK_FPLOOKUP);
 	MNT_KERN_FLAG(MNTK_TASKQUEUE_WAITER);
@@ -5031,7 +5038,7 @@ vfs_allocate_syncvnode(struct mount *mp)
 	vp->v_type = VNON;
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 	vp->v_vflag |= VV_FORCEINSMQ;
-	error = insmntque(vp, mp);
+	error = insmntque1(vp, mp);
 	if (error != 0)
 		panic("vfs_allocate_syncvnode: insmntque() failed");
 	vp->v_vflag &= ~VV_FORCEINSMQ;
diff --git a/sys/sys/mount.h b/sys/sys/mount.h
index ae3eebd94c53..15aa7dff1e27 100644
--- a/sys/sys/mount.h
+++ b/sys/sys/mount.h
@@ -487,7 +487,7 @@ struct mntoptnames {
 #define	MNTK_RECURSE		0x00000200 /* pending recursive unmount */
 #define	MNTK_UPPER_WAITER	0x00000400 /* waiting to drain MNTK_UPPER_PENDING */
 #define	MNTK_LOOKUP_EXCL_DOTDOT	0x00000800
-/* UNUSED			0x00001000 */
+#define	MNTK_UNLOCKED_INSMNTQUE	0x00001000 /* fs does not lock the vnode for insmntque */
 #define	MNTK_UNMAPPED_BUFS	0x00002000
 #define	MNTK_USES_BCACHE	0x00004000 /* FS uses the buffer cache. */
 /* UNUSED			0x00008000 */