MFC r299412:

Add vfs_hash_ref(9) function, which finds a vnode by the hash value
and returns it referenced.
This commit is contained in:
kib 2016-05-18 11:58:16 +00:00
parent 474c064c24
commit 9f55837918
2 changed files with 32 additions and 0 deletions

View File

@ -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)
{

View File

@ -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);