Use now preferred SipHash24 functions. This also means we shouldn't need to hash in the value of the dirhash pointer itself, which confuses me every time I look at it.
Index: ufs/ufs_dirhash.c =================================================================== RCS file: /cvs/src/sys/ufs/ufs/ufs_dirhash.c,v retrieving revision 1.30 diff -u -p -r1.30 ufs_dirhash.c --- ufs/ufs_dirhash.c 14 Sep 2014 14:17:27 -0000 1.30 +++ ufs/ufs_dirhash.c 3 Dec 2014 03:47:22 -0000 @@ -42,9 +42,10 @@ __FBSDID("$FreeBSD: src/sys/ufs/ufs/ufs_ #include <sys/vnode.h> #include <sys/mount.h> #include <sys/sysctl.h> -#include <sys/hash.h> #include <sys/mutex.h> +#include <crypto/siphash.h> + #include <ufs/ufs/quota.h> #include <ufs/ufs/inode.h> #include <ufs/ufs/dir.h> @@ -62,6 +63,7 @@ int ufs_dirhashmaxmem; int ufs_dirhashmem; int ufs_dirhashcheck; +SIPHASH_KEY ufsdirhash_key; int ufsdirhash_hash(struct dirhash *dh, char *name, int namelen); void ufsdirhash_adjfree(struct dirhash *dh, doff_t offset, int diff); @@ -857,17 +859,7 @@ ufsdirhash_checkblock(struct inode *ip, int ufsdirhash_hash(struct dirhash *dh, char *name, int namelen) { - u_int32_t hash; - - /* - * We hash the name and then some other bit of data that is - * invariant over the dirhash's lifetime. Otherwise names - * differing only in the last byte are placed close to one - * another in the table, which is bad for linear probing. - */ - hash = hash32_buf(name, namelen, HASHINIT); - hash = hash32_buf(&dh, sizeof(dh), hash); - return (hash % dh->dh_hlen); + return SipHash24(&ufsdirhash_key, name, namelen) % dh->dh_hlen; } /* @@ -1059,6 +1051,7 @@ ufsdirhash_init(void) pool_init(&ufsdirhash_pool, DH_NBLKOFF * sizeof(doff_t), 0, 0, 0, "dirhash", &pool_allocator_nointr); mtx_init(&ufsdirhash_mtx, IPL_NONE); + arc4random_buf(&ufsdirhash_key, sizeof(ufsdirhash_key)); TAILQ_INIT(&ufsdirhash_list); #if defined (__sparc__) && !defined (__sparc64__) if (!CPU_ISSUN4OR4C)