diff options
author | mjg <mjg@FreeBSD.org> | 2016-01-21 01:05:41 +0000 |
---|---|---|
committer | mjg <mjg@FreeBSD.org> | 2016-01-21 01:05:41 +0000 |
commit | a7359714bed100db34d676022a921c639e4829e9 (patch) | |
tree | 1d4b5246cc0ca9a7ae6bb2cca506ec51d6fe5564 /sys | |
parent | 5ca67cac1ebb3eb0efcc941134f08024d73c6cbe (diff) | |
download | FreeBSD-src-a7359714bed100db34d676022a921c639e4829e9.zip FreeBSD-src-a7359714bed100db34d676022a921c639e4829e9.tar.gz |
cache: provide a helper for computing the hash
Reviewed by: kib
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/vfs_cache.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 58a06a7..202f7db 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -310,6 +310,16 @@ static int vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir, static MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries"); +static uint32_t +cache_get_hash(char *name, u_char len, struct vnode *dvp) +{ + uint32_t hash; + + hash = fnv_32_buf(name, len, FNV1_32_INIT); + hash = fnv_32_buf(&dvp, sizeof(dvp), hash); + return (hash); +} + static int sysctl_nchstats(SYSCTL_HANDLER_ARGS) { @@ -554,8 +564,7 @@ retry_wlocked: } } - hash = fnv_32_buf(cnp->cn_nameptr, cnp->cn_namelen, FNV1_32_INIT); - hash = fnv_32_buf(&dvp, sizeof(dvp), hash); + hash = cache_get_hash(cnp->cn_nameptr, cnp->cn_namelen, dvp); LIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) { counter_u64_add(numchecks, 1); if (ncp->nc_dvp == dvp && ncp->nc_nlen == cnp->cn_namelen && @@ -799,9 +808,8 @@ cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, } } len = ncp->nc_nlen = cnp->cn_namelen; - hash = fnv_32_buf(cnp->cn_nameptr, len, FNV1_32_INIT); + hash = cache_get_hash(cnp->cn_nameptr, len, dvp); strlcpy(nc_get_name(ncp), cnp->cn_nameptr, len + 1); - hash = fnv_32_buf(&dvp, sizeof(dvp), hash); CACHE_WLOCK(); /* @@ -980,10 +988,8 @@ cache_changesize(int newmaxvnodes) nchash = new_nchash; for (i = 0; i <= old_nchash; i++) { while ((ncp = LIST_FIRST(&old_nchashtbl[i])) != NULL) { - hash = fnv_32_buf(nc_get_name(ncp), ncp->nc_nlen, - FNV1_32_INIT); - hash = fnv_32_buf(&ncp->nc_dvp, sizeof(ncp->nc_dvp), - hash); + hash = cache_get_hash(nc_get_name(ncp), ncp->nc_nlen, + ncp->nc_dvp); LIST_REMOVE(ncp, nc_hash); LIST_INSERT_HEAD(NCHHASH(hash), ncp, nc_hash); } |