git: 2a7e4cf84311 - main - Revert b58ca5df0bb7 ("vfs: remove the now unused insmntque1")

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Thu, 27 Jan 2022 16:34:40 UTC
The branch main has been updated by mjg:

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

commit 2a7e4cf84311c9ec6cc5366d24fadfb188e6ccdc
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2022-01-27 16:24:32 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2022-01-27 16:32:22 +0000

    Revert b58ca5df0bb7 ("vfs: remove the now unused insmntque1")
    
    I was somehow convinced that insmntque calls insmntque1 with a NULL
    destructor. Unfortunately this worked well enough to not immediately
    blow up in simple testing.
    
    Keep not using the destructor in previously patched filesystems though
    as it avoids unnecessary casts.
    
    Noted by:       kib
    Reported by:    pho
---
 sys/fs/devfs/devfs_vnops.c   |  2 +-
 sys/fs/fdescfs/fdesc_vnops.c |  2 +-
 sys/fs/nullfs/null_subr.c    |  4 ++--
 sys/fs/tmpfs/tmpfs_subr.c    |  2 +-
 sys/fs/unionfs/union_subr.c  |  2 +-
 sys/kern/vfs_subr.c          | 12 +++++++++++-
 sys/sys/param.h              |  2 +-
 sys/sys/vnode.h              |  2 ++
 8 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c
index dae4079c2c6c..38d581db9154 100644
--- a/sys/fs/devfs/devfs_vnops.c
+++ b/sys/fs/devfs/devfs_vnops.c
@@ -615,7 +615,7 @@ loop:
 	vp->v_data = de;
 	de->de_vnode = vp;
 	mtx_unlock(&devfs_de_interlock);
-	error = insmntque(vp, mp);
+	error = insmntque1(vp, mp, NULL, NULL);
 	if (error != 0) {
 		devfs_insmntque_dtr(vp, de);
 		(void) devfs_allocv_drop_refs(1, dmp, de);
diff --git a/sys/fs/fdescfs/fdesc_vnops.c b/sys/fs/fdescfs/fdesc_vnops.c
index 0f6111586a38..1dead8f1153c 100644
--- a/sys/fs/fdescfs/fdesc_vnops.c
+++ b/sys/fs/fdescfs/fdesc_vnops.c
@@ -191,7 +191,7 @@ loop:
 	fd->fd_ix = ix;
 	if (ftype == Fdesc && fmp->flags & FMNT_LINRDLNKF)
 		vp->v_vflag |= VV_READLINK;
-	error = insmntque(vp, mp);
+	error = insmntque1(vp, mp, NULL, NULL);
 	if (error != 0) {
 		vgone(vp);
 		vput(vp);
diff --git a/sys/fs/nullfs/null_subr.c b/sys/fs/nullfs/null_subr.c
index 982c7d798bb2..acf77d5cfd47 100644
--- a/sys/fs/nullfs/null_subr.c
+++ b/sys/fs/nullfs/null_subr.c
@@ -202,7 +202,7 @@ null_nodeget(struct mount *mp, struct vnode *lowervp, struct vnode **vpp)
 	}
 
 	/*
-	 * The insmntque() call below requires the exclusive lock on
+	 * The insmntque1() call below requires the exclusive lock on
 	 * the nullfs vnode.  Upgrade the lock now if hash failed to
 	 * provide ready to use vnode.
 	 */
@@ -235,7 +235,7 @@ null_nodeget(struct mount *mp, struct vnode *lowervp, struct vnode **vpp)
 	vp->v_type = lowervp->v_type;
 	vp->v_data = xp;
 	vp->v_vnlock = lowervp->v_vnlock;
-	error = insmntque(vp, mp);
+	error = insmntque1(vp, mp, NULL, NULL);
 	if (error != 0) {
 		vput(lowervp);
 		null_destroy_proto(vp, xp);
diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c
index 234984b47c59..c6ac1b0bf357 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -983,7 +983,7 @@ loop:
 	if (vp->v_type != VFIFO)
 		VN_LOCK_ASHARE(vp);
 
-	error = insmntque(vp, mp);
+	error = insmntque1(vp, mp, NULL, NULL);
 	if (error != 0) {
 		tmpfs_insmntque_dtr(vp);
 		vp = NULL;
diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c
index 57b6051104de..e051d42c07cc 100644
--- a/sys/fs/unionfs/union_subr.c
+++ b/sys/fs/unionfs/union_subr.c
@@ -386,7 +386,7 @@ unionfs_nodeget(struct mount *mp, struct vnode *uppervp,
 		vp->v_vflag |= VV_ROOT;
 
 	vn_lock_pair(lowervp, false, uppervp, false); 
-	error = insmntque(vp, mp);
+	error = insmntque1(vp, mp, NULL, NULL);
 	if (error != 0) {
 		unionfs_nodeget_cleanup(vp, unp);
 		return (error);
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index a29f64fddd34..3218a3f7b6a0 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1948,7 +1948,8 @@ insmntque_stddtr(struct vnode *vp, void *dtr_arg)
  * Insert into list of vnodes for the new mount point, if available.
  */
 int
-insmntque(struct vnode *vp, struct mount *mp)
+insmntque1(struct vnode *vp, struct mount *mp,
+	void (*dtr)(struct vnode *, void *), void *dtr_arg)
 {
 
 	KASSERT(vp->v_mount == NULL,
@@ -1973,6 +1974,8 @@ insmntque(struct vnode *vp, struct mount *mp)
 	    (vp->v_vflag & VV_FORCEINSMQ) == 0) {
 		VI_UNLOCK(vp);
 		MNT_IUNLOCK(mp);
+		if (dtr != NULL)
+			dtr(vp, dtr_arg);
 		return (EBUSY);
 	}
 	vp->v_mount = mp;
@@ -1986,6 +1989,13 @@ insmntque(struct vnode *vp, struct mount *mp)
 	return (0);
 }
 
+int
+insmntque(struct vnode *vp, struct mount *mp)
+{
+
+	return (insmntque1(vp, mp, insmntque_stddtr, NULL));
+}
+
 /*
  * Flush out and invalidate all buffers associated with a bufobj
  * Called with the underlying object locked.
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 6bf688105329..948a34da94ec 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -76,7 +76,7 @@
  * cannot include sys/param.h and should only be updated here.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1400052
+#define __FreeBSD_version 1400051
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 390cb8791f54..a1dbdcff4cb5 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -689,6 +689,8 @@ int	getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops,
 	    struct vnode **vpp);
 void	getnewvnode_reserve(void);
 void	getnewvnode_drop_reserve(void);
+int	insmntque1(struct vnode *vp, struct mount *mp,
+	    void (*dtr)(struct vnode *, void *), void *dtr_arg);
 int	insmntque(struct vnode *vp, struct mount *mp);
 u_quad_t init_va_filerev(void);
 int	speedup_syncer(void);