git: c53e990b8d04 - main - DEBUG_VFS_LOCKS: restore diagnostic for the witness use case

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 11 Apr 2023 13:20:56 UTC
The branch main has been updated by kib:

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

commit c53e990b8d0444b5ad59ddb18742a71434e30ee2
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-04-10 08:52:43 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-04-11 12:59:55 +0000

    DEBUG_VFS_LOCKS: restore diagnostic for the witness use case
    
    Reviewed by:    jah, markj
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D39477
---
 sys/kern/vfs_subr.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 7e7315f827a1..60d3a71667a1 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -5456,14 +5456,13 @@ assert_vop_locked(struct vnode *vp, const char *str)
 		return;
 
 #ifdef WITNESS
-	if ((vp->v_irflag & VIRF_CROSSMP) == 0)
-		witness_assert(&vp->v_vnlock->lock_object, LA_LOCKED,
-		    __FILE__, __LINE__);
+	if ((vp->v_irflag & VIRF_CROSSMP) == 0 &&
+	    witness_is_owned(&vp->v_vnlock->lock_object) == -1)
 #else
 	int locked = VOP_ISLOCKED(vp);
 	if (locked == 0 || locked == LK_EXCLOTHER)
-		vfs_badlock("is not locked but should be", str, vp);
 #endif
+		vfs_badlock("is not locked but should be", str, vp);
 }
 
 void
@@ -5473,13 +5472,12 @@ assert_vop_unlocked(struct vnode *vp, const char *str)
 		return;
 
 #ifdef WITNESS
-	if ((vp->v_irflag & VIRF_CROSSMP) == 0)
-		witness_assert(&vp->v_vnlock->lock_object, LA_UNLOCKED,
-		    __FILE__, __LINE__);
+	if ((vp->v_irflag & VIRF_CROSSMP) == 0 &&
+	    witness_is_owned(&vp->v_vnlock->lock_object) == 1)
 #else
 	if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE)
-		vfs_badlock("is locked but should not be", str, vp);
 #endif
+		vfs_badlock("is locked but should not be", str, vp);
 }
 
 void