28 #include <sys/cdefs.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/mount.h>
36 #include <sys/vnode.h>
38 static MALLOC_DEFINE(M_VFS_HASH,
"vfs_hash",
"VFS hash table");
40 static LIST_HEAD(vfs_hash_head, vnode) *vfs_hash_tbl;
42 static u_long vfs_hash_mask;
43 static struct mtx vfs_hash_mtx;
46 vfs_hashinit(
void *
dummy __unused)
50 mtx_init(&vfs_hash_mtx,
"vfs hash", NULL, MTX_DEF);
51 LIST_INIT(&vfs_hash_side);
55 SYSINIT(vfs_hash, SI_SUB_VFS, SI_ORDER_SECOND, vfs_hashinit, NULL);
61 return (vp->v_hash + vp->v_mount->mnt_hashseed);
64 static struct vfs_hash_head *
68 return (&vfs_hash_tbl[(hash + mp->mnt_hashseed) & vfs_hash_mask]);
72 vfs_hash_get(
const struct mount *mp, u_int hash,
int flags,
struct thread *td,
struct vnode **vpp, vfs_hash_cmp_t *fn,
void *arg)
78 mtx_lock(&vfs_hash_mtx);
80 if (vp->v_hash != hash)
82 if (vp->v_mount != mp)
84 if (fn != NULL && fn(vp, arg))
87 mtx_unlock(&vfs_hash_mtx);
88 error =
vget(vp, flags | LK_INTERLOCK, td);
89 if (error == ENOENT && (flags & LK_NOWAIT) == 0)
97 mtx_unlock(&vfs_hash_mtx);
108 mtx_lock(&vfs_hash_mtx);
109 LIST_REMOVE(vp, v_hashlist);
110 mtx_unlock(&vfs_hash_mtx);
114 vfs_hash_insert(
struct vnode *vp, u_int hash,
int flags,
struct thread *td,
struct vnode **vpp, vfs_hash_cmp_t *fn,
void *arg)
121 mtx_lock(&vfs_hash_mtx);
124 if (vp2->v_hash != hash)
126 if (vp2->v_mount != vp->v_mount)
128 if (fn != NULL && fn(vp2, arg))
131 mtx_unlock(&vfs_hash_mtx);
132 error =
vget(vp2, flags | LK_INTERLOCK, td);
133 if (error == ENOENT && (flags & LK_NOWAIT) == 0)
135 mtx_lock(&vfs_hash_mtx);
136 LIST_INSERT_HEAD(&vfs_hash_side, vp, v_hashlist);
137 mtx_unlock(&vfs_hash_mtx);
149 mtx_unlock(&vfs_hash_mtx);
157 mtx_lock(&vfs_hash_mtx);
158 LIST_REMOVE(vp, v_hashlist);
161 mtx_unlock(&vfs_hash_mtx);
void * hashinit(int elements, struct malloc_type *type, u_long *hashmask)
int vget(struct vnode *vp, int flags, struct thread *td)
static LIST_HEAD(vfs_hash_head, vnode)
void vfs_hash_remove(struct vnode *vp)
static struct vfs_hash_head * vfs_hash_bucket(const struct mount *mp, u_int hash)
int vfs_hash_get(const struct mount *mp, u_int hash, int flags, struct thread *td, struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg)
void vput(struct vnode *vp)
void vfs_hash_rehash(struct vnode *vp, u_int hash)
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 mtx_init(struct mtx *m, const char *name, const char *type, int opts)
static MALLOC_DEFINE(M_VFS_HASH,"vfs_hash","VFS hash table")
SYSINIT(vfs_hash, SI_SUB_VFS, SI_ORDER_SECOND, vfs_hashinit, NULL)