git: 049c784eae5d - stable/15 - vfs: convert vfs_op_thread_* macros to static inlines

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sun, 21 Jun 2026 10:15:56 UTC
The branch stable/15 has been updated by kib:

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

commit 049c784eae5d482e78df7e2202e6e16944d2cdb0
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-04-24 01:26:11 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-06-21 10:05:27 +0000

    vfs: convert vfs_op_thread_* macros to static inlines
    
    (cherry picked from commit 32cf4514cad66ff69ffc96ede20d8debc9b96790)
---
 sys/kern/vfs_cache.c |  4 +--
 sys/kern/vfs_mount.c |  6 ++--
 sys/kern/vfs_subr.c  |  6 ++--
 sys/kern/vfs_vnops.c |  4 +--
 sys/sys/mount.h      | 97 +++++++++++++++++++++++++++++++---------------------
 5 files changed, 68 insertions(+), 49 deletions(-)

diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index a5e28665aed9..822c2e19ad04 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -5713,7 +5713,7 @@ cache_fplookup_climb_mount(struct cache_fpl *fpl)
 
 	prev_mp = NULL;
 	for (;;) {
-		if (!vfs_op_thread_enter_crit(mp, mpcpu)) {
+		if (!vfs_op_thread_enter_crit(mp, &mpcpu)) {
 			if (prev_mp != NULL)
 				vfs_op_thread_exit_crit(prev_mp, prev_mpcpu);
 			return (cache_fpl_partial(fpl));
@@ -5768,7 +5768,7 @@ cache_fplookup_cross_mount(struct cache_fpl *fpl)
 		return (0);
 	}
 
-	if (!vfs_op_thread_enter_crit(mp, mpcpu)) {
+	if (!vfs_op_thread_enter_crit(mp, &mpcpu)) {
 		return (cache_fpl_partial(fpl));
 	}
 	if (!vn_seqc_consistent(vp, vp_seqc)) {
diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
index 9cea2d8acc64..0a3cce26ee48 100644
--- a/sys/kern/vfs_mount.c
+++ b/sys/kern/vfs_mount.c
@@ -500,7 +500,7 @@ vfs_ref_from_vp(struct vnode *vp)
 	if (__predict_false(mp == NULL)) {
 		return (mp);
 	}
-	if (vfs_op_thread_enter(mp, mpcpu)) {
+	if (vfs_op_thread_enter(mp, &mpcpu)) {
 		if (__predict_true(mp == vp->v_mount)) {
 			vfs_mp_count_add_pcpu(mpcpu, ref, 1);
 			vfs_op_thread_exit(mp, mpcpu);
@@ -527,7 +527,7 @@ vfs_ref(struct mount *mp)
 	struct mount_pcpu *mpcpu;
 
 	CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
-	if (vfs_op_thread_enter(mp, mpcpu)) {
+	if (vfs_op_thread_enter(mp, &mpcpu)) {
 		vfs_mp_count_add_pcpu(mpcpu, ref, 1);
 		vfs_op_thread_exit(mp, mpcpu);
 		return;
@@ -645,7 +645,7 @@ vfs_rel(struct mount *mp)
 	struct mount_pcpu *mpcpu;
 
 	CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
-	if (vfs_op_thread_enter(mp, mpcpu)) {
+	if (vfs_op_thread_enter(mp, &mpcpu)) {
 		vfs_mp_count_sub_pcpu(mpcpu, ref, 1);
 		vfs_op_thread_exit(mp, mpcpu);
 		return;
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index d2894858fc94..01387b66392f 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -879,7 +879,7 @@ vfs_busy(struct mount *mp, int flags)
 	MPASS((flags & ~MBF_MASK) == 0);
 	CTR3(KTR_VFS, "%s: mp %p with flags %d", __func__, mp, flags);
 
-	if (vfs_op_thread_enter(mp, mpcpu)) {
+	if (vfs_op_thread_enter(mp, &mpcpu)) {
 		MPASS((mp->mnt_kern_flag & MNTK_DRAINING) == 0);
 		MPASS((mp->mnt_kern_flag & MNTK_UNMOUNT) == 0);
 		MPASS((mp->mnt_kern_flag & MNTK_REFEXPIRE) == 0);
@@ -942,7 +942,7 @@ vfs_unbusy(struct mount *mp)
 
 	CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
 
-	if (vfs_op_thread_enter(mp, mpcpu)) {
+	if (vfs_op_thread_enter(mp, &mpcpu)) {
 		MPASS((mp->mnt_kern_flag & MNTK_DRAINING) == 0);
 		vfs_mp_count_sub_pcpu(mpcpu, lockref, 1);
 		vfs_mp_count_sub_pcpu(mpcpu, ref, 1);
@@ -6978,7 +6978,7 @@ vfs_cache_root(struct mount *mp, int flags, struct vnode **vpp)
 	struct vnode *vp;
 	int error;
 
-	if (!vfs_op_thread_enter(mp, mpcpu))
+	if (!vfs_op_thread_enter(mp, &mpcpu))
 		return (vfs_cache_root_fallback(mp, flags, vpp));
 	vp = atomic_load_ptr(&mp->mnt_rootvnode);
 	if (vp == NULL || VN_IS_DOOMED(vp)) {
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 1746d344aa64..a3ee9216645c 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -2087,7 +2087,7 @@ vn_start_write_refed(struct mount *mp, int flags)
 	struct mount_pcpu *mpcpu;
 	int error, mflags;
 
-	if ((flags & V_XSLEEP) == 0 && vfs_op_thread_enter(mp, mpcpu)) {
+	if ((flags & V_XSLEEP) == 0 && vfs_op_thread_enter(mp, &mpcpu)) {
 		MPASS((mp->mnt_kern_flag & MNTK_SUSPEND) == 0);
 		vfs_mp_count_add_pcpu(mpcpu, writeopcount, 1);
 		vfs_op_thread_exit(mp, mpcpu);
@@ -2256,7 +2256,7 @@ vn_finished_write(struct mount *mp)
 	if (mp == NULL)
 		return;
 
-	if (vfs_op_thread_enter(mp, mpcpu)) {
+	if (vfs_op_thread_enter(mp, &mpcpu)) {
 		vfs_mp_count_sub_pcpu(mpcpu, writeopcount, 1);
 		vfs_mp_count_sub_pcpu(mpcpu, ref, 1);
 		vfs_op_thread_exit(mp, mpcpu);
diff --git a/sys/sys/mount.h b/sys/sys/mount.h
index 18f85192f6c3..1564d2cc22c4 100644
--- a/sys/sys/mount.h
+++ b/sys/sys/mount.h
@@ -36,8 +36,10 @@
 #include <sys/ucred.h>
 #include <sys/queue.h>
 #ifdef _KERNEL
+#include <sys/systm.h>
 #include <sys/lock.h>
 #include <sys/lockmgr.h>
+#include <sys/proc.h>
 #include <sys/tslog.h>
 #include <sys/_mutex.h>
 #include <sys/_sx.h>
@@ -1138,47 +1140,64 @@ void resume_all_fs(void);
  */
 #define	vfs_mount_pcpu(mp)		zpcpu_get(mp->mnt_pcpu)
 #define	vfs_mount_pcpu_remote(mp, cpu)	zpcpu_get_cpu(mp->mnt_pcpu, cpu)
+static void vfs_op_thread_exit_crit(struct mount *mp, struct mount_pcpu *mpcpu);
 
-#define vfs_op_thread_entered(mp) ({				\
-	MPASS(curthread->td_critnest > 0);			\
-	struct mount_pcpu *_mpcpu = vfs_mount_pcpu(mp);		\
-	_mpcpu->mntp_thread_in_ops == 1;			\
-})
-
-#define vfs_op_thread_enter_crit(mp, _mpcpu) ({			\
-	bool _retval_crit = true;				\
-	MPASS(curthread->td_critnest > 0);			\
-	_mpcpu = vfs_mount_pcpu(mp);				\
-	MPASS(mpcpu->mntp_thread_in_ops == 0);			\
-	_mpcpu->mntp_thread_in_ops = 1;				\
-	atomic_interrupt_fence();					\
-	if (__predict_false(mp->mnt_vfs_ops > 0)) {		\
-		vfs_op_thread_exit_crit(mp, _mpcpu);		\
-		_retval_crit = false;				\
-	}							\
-	_retval_crit;						\
-})
-
-#define vfs_op_thread_enter(mp, _mpcpu) ({			\
-	bool _retval;						\
-	critical_enter();					\
-	_retval = vfs_op_thread_enter_crit(mp, _mpcpu);		\
-	if (__predict_false(!_retval))				\
-		critical_exit();				\
-	_retval;						\
-})
-
-#define vfs_op_thread_exit_crit(mp, _mpcpu) do {		\
-	MPASS(_mpcpu == vfs_mount_pcpu(mp));			\
-	MPASS(_mpcpu->mntp_thread_in_ops == 1);			\
-	atomic_interrupt_fence();					\
-	_mpcpu->mntp_thread_in_ops = 0;				\
-} while (0)
+static inline bool
+vfs_op_thread_entered(struct mount *mp)
+{
+	struct mount_pcpu *mpcpu = vfs_mount_pcpu(mp);
 
-#define vfs_op_thread_exit(mp, _mpcpu) do {			\
-	vfs_op_thread_exit_crit(mp, _mpcpu);			\
-	critical_exit();					\
-} while (0)
+	MPASS(curthread->td_critnest > 0);
+	return (mpcpu->mntp_thread_in_ops == 1);
+}
+
+static inline bool
+vfs_op_thread_enter_crit(struct mount *mp, struct mount_pcpu **mpcpup)
+{
+	struct mount_pcpu *mpcpu;
+	bool retval_crit = true;
+
+	MPASS(curthread->td_critnest > 0);
+	mpcpu = vfs_mount_pcpu(mp);
+	MPASS(mpcpu->mntp_thread_in_ops == 0);
+	mpcpu->mntp_thread_in_ops = 1;
+	atomic_interrupt_fence();
+	if (__predict_false(mp->mnt_vfs_ops > 0)) {
+		vfs_op_thread_exit_crit(mp, mpcpu);
+		retval_crit = false;
+	}
+	*mpcpup = mpcpu;
+	return (retval_crit);
+}
+
+static inline bool
+vfs_op_thread_enter(struct mount *mp, struct mount_pcpu **mpcpup)
+{
+	bool retval;
+
+	critical_enter();
+	retval = vfs_op_thread_enter_crit(mp, mpcpup);
+	if (__predict_false(!retval))
+		critical_exit();
+	return (retval);
+}
+
+static inline void
+vfs_op_thread_exit_crit(struct mount *mp, struct mount_pcpu *mpcpu)
+{
+	MPASS(mpcpu == vfs_mount_pcpu(mp));
+	MPASS(mpcpu->mntp_thread_in_ops == 1);
+
+	atomic_interrupt_fence();
+	mpcpu->mntp_thread_in_ops = 0;
+}
+
+static inline void
+vfs_op_thread_exit(struct mount *mp, struct mount_pcpu *mpcpu)
+{
+	vfs_op_thread_exit_crit(mp, mpcpu);
+	critical_exit();
+}
 
 #define vfs_mp_count_add_pcpu(_mpcpu, count, val) do {		\
 	MPASS(_mpcpu->mntp_thread_in_ops == 1);			\