git: d653aaec7a31 - main - cache: add cache_assert_no_entries

From: Mateusz Guzik <mjg_at_FreeBSD.org>
Date: Mon, 24 Oct 2022 15:40:26 UTC
The branch main has been updated by mjg:

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

commit d653aaec7a311a7d1455e9721904b2a341b32a65
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2022-10-24 15:34:57 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2022-10-24 15:37:43 +0000

    cache: add cache_assert_no_entries
---
 sys/kern/vfs_cache.c | 9 +++++++++
 sys/sys/vnode.h      | 6 ++++++
 2 files changed, 15 insertions(+)

diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 5f72506549bd..e58d3f338085 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -2998,6 +2998,15 @@ cache_validate(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
 	}
 	mtx_unlock(blp);
 }
+
+void
+cache_assert_no_entries(struct vnode *vp)
+{
+
+	VNPASS(TAILQ_EMPTY(&vp->v_cache_dst), vp);
+	VNPASS(LIST_EMPTY(&vp->v_cache_src), vp);
+	VNPASS(vp->v_cache_dd == NULL, vp);
+}
 #endif
 
 /*
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 63b3c23bd072..167f1904b70d 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -676,11 +676,17 @@ void	cache_vop_rmdir(struct vnode *dvp, struct vnode *vp);
 #ifdef INVARIANTS
 void	cache_validate(struct vnode *dvp, struct vnode *vp,
 	    struct componentname *cnp);
+void	cache_assert_no_entries(struct vnode *vp);
 #else
 static inline void
 cache_validate(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
 {
 }
+
+static inline void
+cache_assert_no_entries(struct vnode *vp)
+{
+}
 #endif
 void	cache_fast_lookup_enabled_recalc(void);
 int	change_dir(struct vnode *vp, struct thread *td);