From 25c8d940ab5b46b2fb7072a711f275e4fcabd684 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Fri, 23 Aug 2019 21:05:37 +0000 Subject: [PATCH] vfs: assert the lock held in MNT_REF/MNT_REL Sponsored by: The FreeBSD Foundation --- sys/sys/mount.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 2b7f988b763..50f0663537c 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -265,8 +265,12 @@ void __mnt_vnode_markerfree_active(struct vnode **mvp, struct mount *); #define MNT_ITRYLOCK(mp) mtx_trylock(&(mp)->mnt_mtx) #define MNT_IUNLOCK(mp) mtx_unlock(&(mp)->mnt_mtx) #define MNT_MTX(mp) (&(mp)->mnt_mtx) -#define MNT_REF(mp) (mp)->mnt_ref++ +#define MNT_REF(mp) do { \ + mtx_assert(MNT_MTX(mp), MA_OWNED); \ + (mp)->mnt_ref++; \ +} while (0) #define MNT_REL(mp) do { \ + mtx_assert(MNT_MTX(mp), MA_OWNED); \ KASSERT((mp)->mnt_ref > 0, ("negative mnt_ref")); \ (mp)->mnt_ref--; \ if ((mp)->mnt_ref == 0) \