From 7ab7d4f0197fd2c2abc76ad22e90665847ed47cd Mon Sep 17 00:00:00 2001 From: kib Date: Wed, 18 May 2016 11:58:16 +0000 Subject: [PATCH] MFC r299412: Add vfs_hash_ref(9) function, which finds a vnode by the hash value and returns it referenced. git-svn-id: svn://svn.freebsd.org/base/stable/10@300140 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/kern/vfs_hash.c | 30 ++++++++++++++++++++++++++++++ sys/sys/vnode.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/sys/kern/vfs_hash.c b/sys/kern/vfs_hash.c index b7029236d..d2fbbd697 100644 --- a/sys/kern/vfs_hash.c +++ b/sys/kern/vfs_hash.c @@ -102,6 +102,36 @@ vfs_hash_get(const struct mount *mp, u_int hash, int flags, struct thread *td, } } +void +vfs_hash_ref(const struct mount *mp, u_int hash, struct thread *td, + struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg) +{ + struct vnode *vp; + + while (1) { + mtx_lock(&vfs_hash_mtx); + LIST_FOREACH(vp, vfs_hash_bucket(mp, hash), v_hashlist) { + if (vp->v_hash != hash) + continue; + if (vp->v_mount != mp) + continue; + if (fn != NULL && fn(vp, arg)) + continue; + vhold(vp); + mtx_unlock(&vfs_hash_mtx); + vref(vp); + vdrop(vp); + *vpp = vp; + return; + } + if (vp == NULL) { + mtx_unlock(&vfs_hash_mtx); + *vpp = NULL; + return; + } + } +} + void vfs_hash_remove(struct vnode *vp) { diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index ea75d73a0..d3d79aba7 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -849,6 +849,8 @@ int vfs_hash_get(const struct mount *mp, u_int hash, int flags, u_int vfs_hash_index(struct vnode *vp); int vfs_hash_insert(struct vnode *vp, u_int hash, int flags, struct thread *td, struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg); +void vfs_hash_ref(const struct mount *mp, u_int hash, struct thread *td, + struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg); void vfs_hash_rehash(struct vnode *vp, u_int hash); void vfs_hash_remove(struct vnode *vp); -- 2.45.0