Date: Sun, 03 May 2026 19:59:10 +0000 From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: a61a696e78a9 - main - vfs: convert vfs_op_thread_* macros to static inlines Message-ID: <69f7a90e.3fd42.7d53d252@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a61a696e78a967b149a6e39b1f98ada26217a6bb commit a61a696e78a967b149a6e39b1f98ada26217a6bb Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2026-04-24 01:26:11 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2026-05-03 19:58:37 +0000 vfs: convert vfs_op_thread_* macros to static inlines Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D56611 --- 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 3f8591bd0ba7..66210bf58a7c 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -5737,7 +5737,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)); @@ -5792,7 +5792,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 ddc5a1b70887..fff05a627162 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 58975f7ac932..b008db45a8b7 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); @@ -6988,7 +6988,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 4061b2272193..15704634ff62 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -2083,7 +2083,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); @@ -2252,7 +2252,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); \home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69f7a90e.3fd42.7d53d252>
