git: 1d97ad676d58 - main - lockmgr(9): add lockcanrecurse(9)

Konstantin Belousov <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a75a0ed.1bd7e.20bcdbbf__23879.354568065$1786093832$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by kib:

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

commit 1d97ad676d586aa5d91227ebaa39bd9c3b1d68fe
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-07-31 04:11:05 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-08-07 09:09:50 +0000

    lockmgr(9): add lockcanrecurse(9)
    
    Also add vnode locking wrappers for lockcanrecurse(9) and
    lockdisablerecurse(9).
    
    Reviewed by:    jah
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D58567
---
 sys/kern/kern_lock.c | 7 +++++++
 sys/sys/lockmgr.h    | 1 +
 sys/sys/vnode.h      | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c
index 76f68677e292..b12d5bc2f12c 100644
--- a/sys/kern/kern_lock.c
+++ b/sys/kern/kern_lock.c
@@ -495,6 +495,13 @@ lockdisablerecurse(struct lock *lk)
 	lk->lock_object.lo_flags &= ~LO_RECURSABLE;
 }
 
+bool
+lockcanrecurse(struct lock *lk)
+{
+	lockmgr_assert(lk, KA_LOCKED);
+	return ((lk->lock_object.lo_flags & LO_RECURSABLE) != 0);
+}
+
 void
 lockdestroy(struct lock *lk)
 {
diff --git a/sys/sys/lockmgr.h b/sys/sys/lockmgr.h
index 48eea47c60da..ca066148d7d3 100644
--- a/sys/sys/lockmgr.h
+++ b/sys/sys/lockmgr.h
@@ -82,6 +82,7 @@ void	 _lockmgr_disown(struct lock *lk, const char *file, int line);
 
 void	 lockallowrecurse(struct lock *lk);
 void	 lockallowshare(struct lock *lk);
+bool	 lockcanrecurse(struct lock *lk);
 void	 lockdestroy(struct lock *lk);
 void	 lockdisablerecurse(struct lock *lk);
 void	 lockdisableshare(struct lock *lk);
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 9d17dde1e73d..2fa1a51ce1cc 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -480,6 +480,8 @@ extern	u_int vn_lock_pair_pause_max;
 #define	VI_MTX(vp)	(&(vp)->v_interlock)
 
 #define	VN_LOCK_AREC(vp)	lockallowrecurse((vp)->v_vnlock)
+#define	VN_LOCK_DREC(vp)	lockdisablerecurse((vp)->v_vnlock)
+#define	VN_LOCK_CANREC(vp)	lockcanrecurse((vp)->v_vnlock)
 #define	VN_LOCK_ASHARE(vp)	lockallowshare((vp)->v_vnlock)
 #define	VN_LOCK_DSHARE(vp)	lockdisableshare((vp)->v_vnlock)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.