From 2538e44c7b035093d27b8b3e40e6c2ed17f3238f Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Fri, 21 Feb 2025 20:30:05 -0500 Subject: [PATCH] LU-18687 compat: move hash/rhash to lustre_compat Migrate the backported hash and rhashtable code to lustre_compat. The backported linux-hash.c code is only needed for CentOS 7.5, so drop it. Eventually, all of the Lustre/LNet compatability code will live in lustre_compat - maintaining a clear separation from the functional code in Lustre and LNet. Test-Parameters: trivial Signed-off-by: Timothy Day Change-Id: I73add2b5c2ad8ccc46c252f1066c7f20dc12cc39 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58157 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin Reviewed-by: James Simmons Reviewed-by: Andreas Dilger --- include/lustre_compat/linux/hash.h | 46 +++++++++++++++++ .../lustre_compat/linux/rhashtable.h | 57 ++-------------------- include/lustre_compat/linux/stringhash.h | 25 ++++++++++ libcfs/include/libcfs/libcfs.h | 1 - libcfs/include/libcfs/linux/Makefile.am | 2 +- libcfs/libcfs/Makefile.in | 1 - libcfs/libcfs/linux/Makefile.am | 1 - libcfs/libcfs/linux/linux-hash.c | 37 -------------- libcfs/libcfs/linux/linux-wait.c | 1 - lnet/include/lnet/lib-lnet.h | 1 + lustre/include/cfs_hash.h | 1 - lustre/include/lustre_fid.h | 1 + lustre/include/lustre_nrs_crr.h | 1 - lustre/ldlm/ldlm_resource.c | 1 - lustre/lmv/lmv_obd.c | 7 ++- lustre/lod/lod_pool.c | 9 ++-- lustre/lov/lov_pool.c | 10 ++-- lustre/obdclass/lu_object.c | 3 +- lustre/ptlrpc/connection.c | 2 +- lustre/ptlrpc/gss/gss_svc_upcall.c | 3 +- 20 files changed, 99 insertions(+), 111 deletions(-) create mode 100644 include/lustre_compat/linux/hash.h rename libcfs/include/libcfs/linux/linux-hash.h => include/lustre_compat/linux/rhashtable.h (84%) create mode 100644 include/lustre_compat/linux/stringhash.h delete mode 100644 libcfs/libcfs/linux/linux-hash.c diff --git a/include/lustre_compat/linux/hash.h b/include/lustre_compat/linux/hash.h new file mode 100644 index 0000000..3be4149 --- /dev/null +++ b/include/lustre_compat/linux/hash.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LINUX_HASH_LUSTRE_H__ +#define __LINUX_HASH_LUSTRE_H__ + +#include +#include + +#ifdef HAVE_BROKEN_HASH_64 + +#define GOLDEN_RATIO_32 0x61C88647 +#define GOLDEN_RATIO_64 0x61C8864680B583EBull + +static inline u32 cfs_hash_32(u32 val, unsigned int bits) +{ + /* High bits are more random, so use them. */ + return (val * GOLDEN_RATIO_32) >> (32 - bits); +} + +static __always_inline u32 cfs_hash_64(u64 val, unsigned int bits) +{ +#if BITS_PER_LONG == 64 + /* 64x64-bit multiply is efficient on all 64-bit processors */ + return val * GOLDEN_RATIO_64 >> (64 - bits); +#else + /* Hash 64 bits using only 32x32-bit multiply. */ + return cfs_hash_32(((u32)val ^ ((val >> 32) * GOLDEN_RATIO_32)), bits); +#endif +} + +#if BITS_PER_LONG == 32 +#define cfs_hash_long(val, bits) cfs_hash_32(val, bits) +#elif BITS_PER_LONG == 64 +#define cfs_hash_long(val, bits) cfs_hash_64(val, bits) +#else +#error Wordsize not 32 or 64 +#endif + +#else + +#define cfs_hash_32 hash_32 +#define cfs_hash_64 hash_64 +#define cfs_hash_long hash_long + +#endif /* HAVE_BROKEN_HASH_64 */ +#endif /* __LINUX_HASH_LUSTRE_H__ */ diff --git a/libcfs/include/libcfs/linux/linux-hash.h b/include/lustre_compat/linux/rhashtable.h similarity index 84% rename from libcfs/include/libcfs/linux/linux-hash.h rename to include/lustre_compat/linux/rhashtable.h index 9d4b1b0..c8d7e6c 100644 --- a/libcfs/include/libcfs/linux/linux-hash.h +++ b/include/lustre_compat/linux/rhashtable.h @@ -1,61 +1,10 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __LIBCFS_LINUX_HASH_H__ -#define __LIBCFS_LINUX_HASH_H__ +#ifndef _LINUX_RHASHTABLE_LUSTRE_H +#define _LINUX_RHASHTABLE_LUSTRE_H -#include #include -u64 cfs_hashlen_string(const void *salt, const char *name); - -#ifndef hashlen_hash -#define hashlen_hash(hashlen) ((u32)(hashlen)) -#endif - -#ifndef HAVE_STRINGHASH -#ifndef hashlen_create -#define hashlen_create(hash, len) ((u64)(len)<<32 | (u32)(hash)) -#endif -#endif /* !HAVE_STRINGHASH */ - -#ifdef HAVE_BROKEN_HASH_64 - -#define GOLDEN_RATIO_32 0x61C88647 -#define GOLDEN_RATIO_64 0x61C8864680B583EBull - -static inline u32 cfs_hash_32(u32 val, unsigned int bits) -{ - /* High bits are more random, so use them. */ - return (val * GOLDEN_RATIO_32) >> (32 - bits); -} - -static __always_inline u32 cfs_hash_64(u64 val, unsigned int bits) -{ -#if BITS_PER_LONG == 64 - /* 64x64-bit multiply is efficient on all 64-bit processors */ - return val * GOLDEN_RATIO_64 >> (64 - bits); -#else - /* Hash 64 bits using only 32x32-bit multiply. */ - return cfs_hash_32(((u32)val ^ ((val >> 32) * GOLDEN_RATIO_32)), bits); -#endif -} - -#if BITS_PER_LONG == 32 -#define cfs_hash_long(val, bits) cfs_hash_32(val, bits) -#elif BITS_PER_LONG == 64 -#define cfs_hash_long(val, bits) cfs_hash_64(val, bits) -#else -#error Wordsize not 32 or 64 -#endif - -#else - -#define cfs_hash_32 hash_32 -#define cfs_hash_64 hash_64 -#define cfs_hash_long hash_long - -#endif /* HAVE_BROKEN_HASH_64 */ - #ifndef HAVE_RHASHTABLE_WALK_ENTER static int rhashtable_walk_enter(struct rhashtable *ht, struct rhashtable_iter *iter) @@ -332,4 +281,4 @@ static inline int rhashtable_replace_fast( } #endif /* HAVE_RHASHTABLE_REPLACE */ -#endif /* __LIBCFS_LINUX_HASH_H__ */ +#endif /* _LINUX_RHASHTABLE_LUSTRE_H */ diff --git a/include/lustre_compat/linux/stringhash.h b/include/lustre_compat/linux/stringhash.h new file mode 100644 index 0000000..107ffe5 --- /dev/null +++ b/include/lustre_compat/linux/stringhash.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LINUX_STRINGHASH_LUSTRE_H +#define __LINUX_STRINGHASH_LUSTRE_H + +#include +#include + +#ifndef HAVE_STRINGHASH + +u64 hashlen_string(const void *salt, const char *name); + +#ifndef hashlen_hash +#define hashlen_hash(hashlen) ((u32)(hashlen)) +#endif + +#ifndef hashlen_create +#define hashlen_create(hash, len) ((u64)(len)<<32 | (u32)(hash)) +#endif + +#else +#include +#endif /* !HAVE_STRINGHASH */ + +#endif /* !__LINUX_STRINGHASH_LUSTRE_H */ diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index c593e91..c475c06 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -22,7 +22,6 @@ #include #endif -#include #include #include #include diff --git a/libcfs/include/libcfs/linux/Makefile.am b/libcfs/include/libcfs/linux/Makefile.am index f788f9d..1642f27 100644 --- a/libcfs/include/libcfs/linux/Makefile.am +++ b/libcfs/include/libcfs/linux/Makefile.am @@ -5,5 +5,5 @@ # EXTRA_DIST = linux-misc.h linux-fs.h linux-mem.h linux-time.h linux-cpu.h \ - linux-list.h linux-hash.h linux-wait.h linux-net.h \ + linux-list.h linux-wait.h linux-net.h \ refcount.h processor.h linux-fortify-string.h diff --git a/libcfs/libcfs/Makefile.in b/libcfs/libcfs/Makefile.in index 59d7e56..0984486 100644 --- a/libcfs/libcfs/Makefile.in +++ b/libcfs/libcfs/Makefile.in @@ -12,7 +12,6 @@ libcfs_dir := $(dir $(lastword $(MAKEFILE_LIST))) include $(libcfs_dir)/../../lustre_compat/lib/Makefile libcfs-linux-objs := linux-prim.o -libcfs-linux-objs += linux-hash.o libcfs-linux-objs += linux-wait.o libcfs-compat-objs += $(patsubst %,$(COMPAT)%,$(compat_objs)) diff --git a/libcfs/libcfs/linux/Makefile.am b/libcfs/libcfs/linux/Makefile.am index 52fddc2..a605d49 100644 --- a/libcfs/libcfs/linux/Makefile.am +++ b/libcfs/libcfs/linux/Makefile.am @@ -5,5 +5,4 @@ # EXTRA_DIST = linux-prim.c \ - linux-hash.c \ linux-wait.c diff --git a/libcfs/libcfs/linux/linux-hash.c b/libcfs/libcfs/linux/linux-hash.c deleted file mode 100644 index 334fcbc..0000000 --- a/libcfs/libcfs/linux/linux-hash.c +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#define DEBUG_SUBSYSTEM S_LNET - -#include -#ifdef HAVE_STRINGHASH -#include -#else -#include -#endif -#include - -#include - -/* Return the "hash_len" (hash and length) of a null-terminated string */ -/* The kernel equivalent is in fs/namei.c but for some strange reason - * RHEL7.5 stuck it in dax/super.c instead. This placement never existed - * upstream so to make life easier we just have the equavilent - */ -u64 cfs_hashlen_string(const void *salt, const char *name) -{ -#ifdef HAVE_FULL_NAME_HASH_3ARGS - unsigned long hash = init_name_hash(salt); -#else - unsigned long hash = init_name_hash(); -#endif - unsigned long len = 0, c; - - c = (unsigned char)*name; - while (c) { - len++; - hash = partial_name_hash(c, hash); - c = (unsigned char)name[len]; - } - return hashlen_create(end_name_hash(hash), len); -} -EXPORT_SYMBOL(cfs_hashlen_string); diff --git a/libcfs/libcfs/linux/linux-wait.c b/libcfs/libcfs/linux/linux-wait.c index ea066fa..c5763e0 100644 --- a/libcfs/libcfs/linux/linux-wait.c +++ b/libcfs/libcfs/linux/linux-wait.c @@ -4,7 +4,6 @@ * The implementation of the wait_bit*() and related waiting APIs: */ -#include #include #ifdef HAVE_SCHED_HEADERS #include diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index 79697dd..1838c3d 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -20,6 +20,7 @@ #define CFS_FAIL_DELAY_MSG_FORWARD 0xe002 #include +#include #include #include diff --git a/lustre/include/cfs_hash.h b/lustre/include/cfs_hash.h index c92a7ae..488e636 100644 --- a/lustre/include/cfs_hash.h +++ b/lustre/include/cfs_hash.h @@ -20,7 +20,6 @@ #include #include #include -#include /* disable debug */ #define CFS_HASH_DEBUG_NONE 0 diff --git a/lustre/include/lustre_fid.h b/lustre/include/lustre_fid.h index d24fab9..a8efdf7 100644 --- a/lustre/include/lustre_fid.h +++ b/lustre/include/lustre_fid.h @@ -127,6 +127,7 @@ * Even so, the MDT and OST resources are also in different LDLM namespaces. */ +#include #include #include #include diff --git a/lustre/include/lustre_nrs_crr.h b/lustre/include/lustre_nrs_crr.h index f370515..a19f2d0 100644 --- a/lustre/include/lustre_nrs_crr.h +++ b/lustre/include/lustre_nrs_crr.h @@ -21,7 +21,6 @@ * CRR-N, Client Round Robin over NIDs * @{ */ -#include /** * private data structure for CRR-N NRS diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 327f428..5472ce7 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -18,7 +18,6 @@ #include #include #include -#include #include "ldlm_internal.h" struct kmem_cache *ldlm_resource_slab, *ldlm_lock_slab; diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index c438afb..c93ed0f 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -36,6 +38,7 @@ #include #include #include + #include "lmv_internal.h" static int lmv_check_connect(struct obd_device *obd); @@ -1200,8 +1203,8 @@ static u32 qos_exclude_hashfh(const void *data, u32 len, u32 seed) { const char *name = data; - return hashlen_hash(cfs_hashlen_string((void *)(unsigned long)seed, - name)); + return hashlen_hash(hashlen_string((void *)(unsigned long)seed, + name)); } static int qos_exclude_cmpfn(struct rhashtable_compare_arg *arg, diff --git a/lustre/lod/lod_pool.c b/lustre/lod/lod_pool.c index 6f94040..fed6c91 100644 --- a/lustre/lod/lod_pool.c +++ b/lustre/lod/lod_pool.c @@ -35,10 +35,13 @@ #define DEBUG_SUBSYSTEM S_LOV +#include +#include + #include -#include #include #include + #include "lod_internal.h" #define pool_tgt(_p, _i) OST_TGT(lu2lod_dev((_p)->pool_lobd->obd_lu_dev), \ @@ -94,8 +97,8 @@ static u32 pool_hashfh(const void *data, u32 len, u32 seed) { const char *pool_name = data; - return hashlen_hash(cfs_hashlen_string((void *)(unsigned long)seed, - pool_name)); + return hashlen_hash(hashlen_string((void *)(unsigned long)seed, + pool_name)); } static int pool_cmpfn(struct rhashtable_compare_arg *arg, const void *obj) diff --git a/lustre/lov/lov_pool.c b/lustre/lov/lov_pool.c index e4e5c6c..d2e8842 100644 --- a/lustre/lov/lov_pool.c +++ b/lustre/lov/lov_pool.c @@ -19,11 +19,13 @@ #define DEBUG_SUBSYSTEM S_LOV +#include +#include + #include -#include #include - #include + #include "lov_internal.h" #define pool_tgt(_p, _i) \ @@ -42,8 +44,8 @@ static u32 pool_hashfh(const void *data, u32 len, u32 seed) { const char *pool_name = data; - return hashlen_hash(cfs_hashlen_string((void *)(unsigned long)seed, - pool_name)); + return hashlen_hash(hashlen_string((void *)(unsigned long)seed, + pool_name)); } /** diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index cd809df..ef88dd0 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -25,9 +25,10 @@ #include #include +#include + #include #include -#include #include #include #include diff --git a/lustre/ptlrpc/connection.c b/lustre/ptlrpc/connection.c index 3594d7e..1adb7cb 100644 --- a/lustre/ptlrpc/connection.c +++ b/lustre/ptlrpc/connection.c @@ -14,7 +14,7 @@ #define DEBUG_SUBSYSTEM S_RPC #include -#include +#include #include #include #include diff --git a/lustre/ptlrpc/gss/gss_svc_upcall.c b/lustre/ptlrpc/gss/gss_svc_upcall.c index cd80123..d21ed4e 100644 --- a/lustre/ptlrpc/gss/gss_svc_upcall.c +++ b/lustre/ptlrpc/gss/gss_svc_upcall.c @@ -59,6 +59,8 @@ #include #include +#include + #include #include #include @@ -66,7 +68,6 @@ #include #include #include -#include #include "gss_err.h" #include "gss_internal.h" -- 1.8.3.1