]> xenbits.xensource.com Git - freebsd.git/commitdiff
vfs: tidy up assertions in vfs_subr
authormjg <mjg@FreeBSD.org>
Fri, 30 Aug 2019 00:45:53 +0000 (00:45 +0000)
committermjg <mjg@FreeBSD.org>
Fri, 30 Aug 2019 00:45:53 +0000 (00:45 +0000)
- assert unlocked vnode interlock in vref
- assert right counts in vputx
- print debug info for panic in vdrop

Sponsored by: The FreeBSD Foundation

sys/kern/vfs_subr.c

index b6ec815fca071b61018ab6e2ab12829fe6745835..6a8dfca846845d85ccc88578f14a02e67fb02b6e 100644 (file)
@@ -2778,6 +2778,7 @@ void
 vref(struct vnode *vp)
 {
 
+       ASSERT_VI_UNLOCKED(vp, __func__);
        CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
        _vhold(vp, false);
        v_incr_usecount(vp);
@@ -2853,6 +2854,9 @@ vputx(struct vnode *vp, int func)
        else
                KASSERT(func == VPUTX_VRELE, ("vputx: wrong func"));
        ASSERT_VI_UNLOCKED(vp, __func__);
+       VNASSERT(vp->v_holdcnt > 0 && vp->v_usecount > 0, vp,
+           ("%s: wrong ref counts", __func__));
+
        CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
 
        if (vp->v_type != VCHR &&
@@ -3069,8 +3073,10 @@ _vdrop(struct vnode *vp, bool locked)
        else
                ASSERT_VI_UNLOCKED(vp, __func__);
        CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
-       if ((int)vp->v_holdcnt <= 0)
-               panic("vdrop: holdcnt %d", vp->v_holdcnt);
+       if (__predict_false((int)vp->v_holdcnt <= 0)) {
+               vn_printf(vp, "vdrop: holdcnt %d", vp->v_holdcnt);
+               panic("vdrop: wrong holdcnt");
+       }
        if (!locked) {
                if (refcount_release_if_not_last(&vp->v_holdcnt))
                        return;