Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Jul 2022 12:33:51 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 36960099a008 - stable/13 - vfs_mount.c: convert explicit panics and KASSERTs to MPASSERT/MPPASS
Message-ID:  <202207061233.266CXpjW017896@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib:

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

commit 36960099a008f6fbdfee1b6c43e0226832da2cbf
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-06-29 11:37:58 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-07-06 12:33:30 +0000

    vfs_mount.c: convert explicit panics and KASSERTs to MPASSERT/MPPASS
    
    (cherry picked from commit ad175a107b4e0fdc0128c98c3ca9d6cf8006aba7)
---
 sys/kern/vfs_mount.c | 57 +++++++++++++++++++++-------------------------------
 1 file changed, 23 insertions(+), 34 deletions(-)

diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
index e14b1e882501..6e2945c91e1c 100644
--- a/sys/kern/vfs_mount.c
+++ b/sys/kern/vfs_mount.c
@@ -542,12 +542,10 @@ vfs_mount_alloc(struct vnode *vp, struct vfsconf *vfsp, const char *fspath,
 	mp->mnt_nvnodelistsize = 0;
 	TAILQ_INIT(&mp->mnt_lazyvnodelist);
 	mp->mnt_lazyvnodelistsize = 0;
-	if (mp->mnt_ref != 0 || mp->mnt_lockref != 0 ||
-	    mp->mnt_writeopcount != 0)
-		panic("%s: non-zero counters on new mp %p\n", __func__, mp);
-	if (mp->mnt_vfs_ops != 1)
-		panic("%s: vfs_ops should be 1 but %d found\n", __func__,
-		    mp->mnt_vfs_ops);
+	MPPASS(mp->mnt_ref == 0 && mp->mnt_lockref == 0 &&
+	    mp->mnt_writeopcount == 0, mp);
+	MPASSERT(mp->mnt_vfs_ops == 1, mp,
+	    ("vfs_ops should be 1 but %d found", mp->mnt_vfs_ops));
 	(void) vfs_busy(mp, MBF_NOWAIT);
 	atomic_add_acq_int(&vfsp->vfc_refcount, 1);
 	mp->mnt_op = vfsp->vfc_vfsops;
@@ -576,8 +574,7 @@ void
 vfs_mount_destroy(struct mount *mp)
 {
 
-	if (mp->mnt_vfs_ops == 0)
-		panic("%s: entered with zero vfs_ops\n", __func__);
+	MPPASS(mp->mnt_vfs_ops != 0, mp);
 
 	vfs_assert_mount_counters(mp);
 
@@ -592,10 +589,8 @@ vfs_mount_destroy(struct mount *mp)
 	KASSERT(mp->mnt_ref == 0,
 	    ("%s: invalid refcount in the drain path @ %s:%d", __func__,
 	    __FILE__, __LINE__));
-	if (mp->mnt_writeopcount != 0)
-		panic("vfs_mount_destroy: nonzero writeopcount");
-	if (mp->mnt_secondary_writes != 0)
-		panic("vfs_mount_destroy: nonzero secondary_writes");
+	MPPASS(mp->mnt_writeopcount == 0, mp);
+	MPPASS(mp->mnt_secondary_writes == 0, mp);
 	atomic_subtract_rel_int(&mp->mnt_vfc->vfc_refcount, 1);
 	if (!TAILQ_EMPTY(&mp->mnt_nvnodelist)) {
 		struct vnode *vp;
@@ -605,21 +600,16 @@ vfs_mount_destroy(struct mount *mp)
 		panic("unmount: dangling vnode");
 	}
 	KASSERT(TAILQ_EMPTY(&mp->mnt_uppers), ("mnt_uppers"));
-	if (mp->mnt_nvnodelistsize != 0)
-		panic("vfs_mount_destroy: nonzero nvnodelistsize");
-	if (mp->mnt_lazyvnodelistsize != 0)
-		panic("vfs_mount_destroy: nonzero lazyvnodelistsize");
-	if (mp->mnt_lockref != 0)
-		panic("vfs_mount_destroy: nonzero lock refcount");
+	MPPASS(mp->mnt_nvnodelistsize == 0, mp);
+	MPPASS(mp->mnt_lazyvnodelistsize == 0, mp);
+	MPPASS(mp->mnt_lockref == 0, mp);
 	MNT_IUNLOCK(mp);
 
-	if (mp->mnt_vfs_ops != 1)
-		panic("%s: vfs_ops should be 1 but %d found\n", __func__,
-		    mp->mnt_vfs_ops);
+	MPASSERT(mp->mnt_vfs_ops == 1, mp,
+	    ("vfs_ops should be 1 but %d found", mp->mnt_vfs_ops));
 
-	if (mp->mnt_rootvnode != NULL)
-		panic("%s: mount point still has a root vnode %p\n", __func__,
-		    mp->mnt_rootvnode);
+	MPASSERT(mp->mnt_rootvnode == NULL, mp,
+	    ("mount point still has a root vnode %p", mp->mnt_rootvnode));
 
 	if (mp->mnt_vnodecovered != NULL)
 		vrele(mp->mnt_vnodecovered);
@@ -1589,9 +1579,10 @@ vfs_op_enter(struct mount *mp)
 		mp->mnt_writeopcount += mpcpu->mntp_writeopcount;
 		mpcpu->mntp_writeopcount = 0;
 	}
-	if (mp->mnt_ref <= 0 || mp->mnt_lockref < 0 || mp->mnt_writeopcount < 0)
-		panic("%s: invalid count(s) on mp %p: ref %d lockref %d writeopcount %d\n",
-		    __func__, mp, mp->mnt_ref, mp->mnt_lockref, mp->mnt_writeopcount);
+	MPASSERT(mp->mnt_ref > 0 && mp->mnt_lockref >= 0 &&
+	    mp->mnt_writeopcount >= 0, mp,
+	    ("invalid count(s): ref %d lockref %d writeopcount %d",
+	    mp->mnt_ref, mp->mnt_lockref, mp->mnt_writeopcount));
 	MNT_IUNLOCK(mp);
 	vfs_assert_mount_counters(mp);
 }
@@ -1602,13 +1593,11 @@ vfs_op_exit_locked(struct mount *mp)
 
 	mtx_assert(MNT_MTX(mp), MA_OWNED);
 
-	if (mp->mnt_vfs_ops <= 0)
-		panic("%s: invalid vfs_ops count %d for mp %p\n",
-		    __func__, mp->mnt_vfs_ops, mp);
-	KASSERT(mp->mnt_vfs_ops > 1 ||
-	    (mp->mnt_kern_flag & (MNTK_UNMOUNT | MNTK_SUSPEND)) == 0,
-	    ("%s: vfs_ops too low (%d) for mp %p in unmount or suspend",
-	    __func__, mp->mnt_vfs_ops, mp));
+	MPASSERT(mp->mnt_vfs_ops > 0, mp,
+	    ("invalid vfs_ops count %d", mp->mnt_vfs_ops));
+	MPASSERT(mp->mnt_vfs_ops > 1 ||
+	    (mp->mnt_kern_flag & (MNTK_UNMOUNT | MNTK_SUSPEND)) == 0, mp,
+	    ("vfs_ops too low %d in unmount or suspend", mp->mnt_vfs_ops));
 	mp->mnt_vfs_ops--;
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202207061233.266CXpjW017896>