Add vfs_hash_ref(9) function, which finds a vnode by the hash value
and returns it referenced. The function is similar to vfs_hash_get(9), but unlike the later, returned vnode is not locked. This operation cannot be requested with the vget(9) flags. Reviewed and tested by: rmacklem Sponsored by: The FreeBSD Foundation MFC after: 1 week
This commit is contained in:
parent
8b94864213
commit
54a33d2f97
@ -103,6 +103,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) {
|
||||
rw_rlock(&vfs_hash_lock);
|
||||
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);
|
||||
rw_runlock(&vfs_hash_lock);
|
||||
vref(vp);
|
||||
vdrop(vp);
|
||||
*vpp = vp;
|
||||
return;
|
||||
}
|
||||
if (vp == NULL) {
|
||||
rw_runlock(&vfs_hash_lock);
|
||||
*vpp = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
vfs_hash_remove(struct vnode *vp)
|
||||
{
|
||||
|
@ -859,6 +859,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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user