35#include <sys/kernel.h>
36#include <sys/malloc.h>
38#include <sys/rwlock.h>
43static LIST_HEAD(vfs_hash_head, vnode) *vfs_hash_tbl;
45static u_long vfs_hash_mask;
46static struct rwlock __exclusive_cache_line vfs_hash_lock;
49vfs_hashinit(
void *
dummy __unused)
53 rw_init(&vfs_hash_lock,
"vfs hash");
54 LIST_INIT(&vfs_hash_side);
58SYSINIT(vfs_hash, SI_SUB_VFS, SI_ORDER_SECOND, vfs_hashinit, NULL);
64 return (vp->v_hash + vp->v_mount->mnt_hashseed);
67static struct vfs_hash_head *
71 return (&vfs_hash_tbl[(hash + mp->mnt_hashseed) & vfs_hash_mask]);
76 struct vnode **vpp, vfs_hash_cmp_t *fn,
void *arg)
83 rw_rlock(&vfs_hash_lock);
85 if (vp->v_hash != hash)
87 if (vp->v_mount != mp)
89 if (fn != NULL && fn(vp, arg))
92 rw_runlock(&vfs_hash_lock);
94 if (error == ENOENT && (
flags & LK_NOWAIT) == 0)
98 if (vp->v_hash != hash ||
99 (fn != NULL && fn(vp, arg))) {
108 rw_runlock(&vfs_hash_lock);
117 struct vnode **vpp, vfs_hash_cmp_t *fn,
void *arg)
122 rw_rlock(&vfs_hash_lock);
124 if (vp->v_hash != hash)
126 if (vp->v_mount != mp)
128 if (fn != NULL && fn(vp, arg))
131 rw_runlock(&vfs_hash_lock);
138 rw_runlock(&vfs_hash_lock);
149 rw_wlock(&vfs_hash_lock);
150 LIST_REMOVE(vp, v_hashlist);
151 rw_wunlock(&vfs_hash_lock);
156 struct vnode **vpp, vfs_hash_cmp_t *fn,
void *arg)
164 rw_wlock(&vfs_hash_lock);
167 if (vp2->v_hash != hash)
169 if (vp2->v_mount != vp->v_mount)
171 if (fn != NULL && fn(vp2, arg))
174 rw_wunlock(&vfs_hash_lock);
176 if (error == ENOENT && (
flags & LK_NOWAIT) == 0)
178 rw_wlock(&vfs_hash_lock);
179 LIST_INSERT_HEAD(&vfs_hash_side, vp, v_hashlist);
180 rw_wunlock(&vfs_hash_lock);
192 rw_wunlock(&vfs_hash_lock);
199 ASSERT_VOP_ELOCKED(vp,
"rehash requires excl lock");
201 rw_wlock(&vfs_hash_lock);
202 LIST_REMOVE(vp, v_hashlist);
205 rw_wunlock(&vfs_hash_lock);
211 struct vfs_hash_head *vfs_hash_newtbl, *vfs_hash_oldtbl;
212 u_long vfs_hash_newmask, vfs_hash_oldmask;
216 vfs_hash_newtbl =
hashinit(newmaxvnodes, M_VFS_HASH,
219 if (vfs_hash_mask == vfs_hash_newmask) {
220 free(vfs_hash_newtbl, M_VFS_HASH);
228 rw_wlock(&vfs_hash_lock);
229 vfs_hash_oldtbl = vfs_hash_tbl;
230 vfs_hash_oldmask = vfs_hash_mask;
231 vfs_hash_tbl = vfs_hash_newtbl;
232 vfs_hash_mask = vfs_hash_newmask;
233 for (i = 0; i <= vfs_hash_oldmask; i++) {
234 while ((vp = LIST_FIRST(&vfs_hash_oldtbl[i])) != NULL) {
235 LIST_REMOVE(vp, v_hashlist);
241 rw_wunlock(&vfs_hash_lock);
242 free(vfs_hash_oldtbl, M_VFS_HASH);
void free(void *addr, struct malloc_type *mtp)
void * hashinit(int elements, struct malloc_type *type, u_long *hashmask)
static LIST_HEAD(vfs_hash_head, vnode)
SYSINIT(vfs_hash, SI_SUB_VFS, SI_ORDER_SECOND, vfs_hashinit, NULL)
void vfs_hash_changesize(u_long newmaxvnodes)
static MALLOC_DEFINE(M_VFS_HASH, "vfs_hash", "VFS hash table")
static struct vfs_hash_head * vfs_hash_bucket(const struct mount *mp, u_int hash)
void vfs_hash_ref(const struct mount *mp, u_int hash, struct thread *td, struct vnode **vpp, vfs_hash_cmp_t *fn, void *arg)
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 vfs_hash_rehash(struct vnode *vp, u_int hash)
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_remove(struct vnode *vp)
u_int vfs_hash_index(struct vnode *vp)
void vhold(struct vnode *vp)
void vref(struct vnode *vp)
int vget_finish(struct vnode *vp, int flags, enum vgetstate vs)
enum vgetstate vget_prep(struct vnode *vp)
void vgone(struct vnode *vp)
void vput(struct vnode *vp)
void vdrop(struct vnode *vp)