Whamcloud - gitweb
LU-18687 compat: move hash/rhash to lustre_compat 57/58157/18
authorTimothy Day <timday@amazon.com>
Sat, 22 Feb 2025 01:30:05 +0000 (20:30 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 7 May 2025 21:12:27 +0000 (21:12 +0000)
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 <timday@amazon.com>
Change-Id: I73add2b5c2ad8ccc46c252f1066c7f20dc12cc39
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58157
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
20 files changed:
include/lustre_compat/linux/hash.h [new file with mode: 0644]
include/lustre_compat/linux/rhashtable.h [moved from libcfs/include/libcfs/linux/linux-hash.h with 84% similarity]
include/lustre_compat/linux/stringhash.h [new file with mode: 0644]
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/linux/Makefile.am
libcfs/libcfs/Makefile.in
libcfs/libcfs/linux/Makefile.am
libcfs/libcfs/linux/linux-hash.c [deleted file]
libcfs/libcfs/linux/linux-wait.c
lnet/include/lnet/lib-lnet.h
lustre/include/cfs_hash.h
lustre/include/lustre_fid.h
lustre/include/lustre_nrs_crr.h
lustre/ldlm/ldlm_resource.c
lustre/lmv/lmv_obd.c
lustre/lod/lod_pool.c
lustre/lov/lov_pool.c
lustre/obdclass/lu_object.c
lustre/ptlrpc/connection.c
lustre/ptlrpc/gss/gss_svc_upcall.c

diff --git a/include/lustre_compat/linux/hash.h b/include/lustre_compat/linux/hash.h
new file mode 100644 (file)
index 0000000..3be4149
--- /dev/null
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_HASH_LUSTRE_H__
+#define __LINUX_HASH_LUSTRE_H__
+
+#include <linux/types.h>
+#include <linux/hash.h>
+
+#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__ */
similarity index 84%
rename from libcfs/include/libcfs/linux/linux-hash.h
rename to include/lustre_compat/linux/rhashtable.h
index 9d4b1b0..c8d7e6c 100644 (file)
@@ -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 <linux/dcache.h>
 #include <linux/rhashtable.h>
 
-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 (file)
index 0000000..107ffe5
--- /dev/null
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_STRINGHASH_LUSTRE_H
+#define __LINUX_STRINGHASH_LUSTRE_H
+
+#include <linux/dcache.h>
+#include <linux/types.h>
+
+#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 <linux/stringhash.h>
+#endif /* !HAVE_STRINGHASH */
+
+#endif /* !__LINUX_STRINGHASH_LUSTRE_H */
index c593e91..c475c06 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/sched/signal.h>
 #endif
 
-#include <libcfs/linux/linux-hash.h>
 #include <libcfs/linux/linux-misc.h>
 #include <libcfs/linux/linux-mem.h>
 #include <libcfs/linux/linux-time.h>
index f788f9d..1642f27 100644 (file)
@@ -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
index 59d7e56..0984486 100644 (file)
@@ -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))
index 52fddc2..a605d49 100644 (file)
@@ -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 (file)
index 334fcbc..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#define DEBUG_SUBSYSTEM S_LNET
-
-#include <linux/module.h>
-#ifdef HAVE_STRINGHASH
-#include <linux/stringhash.h>
-#else
-#include <linux/dcache.h>
-#endif
-#include <linux/hash.h>
-
-#include <libcfs/linux/linux-hash.h>
-
-/* 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);
index ea066fa..c5763e0 100644 (file)
@@ -4,7 +4,6 @@
  * The implementation of the wait_bit*() and related waiting APIs:
  */
 
-#include <libcfs/linux/linux-hash.h>
 #include <linux/sched.h>
 #ifdef HAVE_SCHED_HEADERS
 #include <linux/sched/signal.h>
index 79697dd..1838c3d 100644 (file)
@@ -20,6 +20,7 @@
 #define CFS_FAIL_DELAY_MSG_FORWARD     0xe002
 
 #include <lustre_compat/linux/generic-radix-tree.h>
+#include <lustre_compat/linux/hash.h>
 #include <linux/netdevice.h>
 
 #include <libcfs/libcfs.h>
index c92a7ae..488e636 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/workqueue.h>
 #include <linux/refcount.h>
 #include <libcfs/libcfs.h>
-#include <libcfs/linux/linux-hash.h>
 
 /* disable debug */
 #define CFS_HASH_DEBUG_NONE    0
index d24fab9..a8efdf7 100644 (file)
  *  Even so, the MDT and OST resources are also in different LDLM namespaces.
  */
 
+#include <lustre_compat/linux/hash.h>
 #include <libcfs/libcfs.h>
 #include <lu_object.h>
 #include <uapi/linux/lustre/lustre_fid.h>
index f370515..a19f2d0 100644 (file)
@@ -21,7 +21,6 @@
  * CRR-N, Client Round Robin over NIDs
  * @{
  */
-#include <libcfs/linux/linux-hash.h>
 
 /**
  * private data structure for CRR-N NRS
index 327f428..5472ce7 100644 (file)
@@ -18,7 +18,6 @@
 #include <lustre_dlm.h>
 #include <lustre_fid.h>
 #include <obd_class.h>
-#include <libcfs/linux/linux-hash.h>
 #include "ldlm_internal.h"
 
 struct kmem_cache *ldlm_resource_slab, *ldlm_lock_slab;
index c438afb..c93ed0f 100644 (file)
@@ -25,6 +25,8 @@
 #include <linux/seq_file.h>
 #include <linux/namei.h>
 
+#include <lustre_compat/linux/stringhash.h>
+
 #include <obd_support.h>
 #include <lustre_lib.h>
 #include <lustre_net.h>
@@ -36,6 +38,7 @@
 #include <uapi/linux/lustre/lustre_ioctl.h>
 #include <lustre_ioctl_old.h>
 #include <lustre_kernelcomm.h>
+
 #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,
index 6f94040..fed6c91 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_LOV
 
+#include <lustre_compat/linux/stringhash.h>
+#include <lustre_compat/linux/rhashtable.h>
+
 #include <libcfs/libcfs.h>
-#include <libcfs/linux/linux-hash.h>
 #include <libcfs/linux/linux-fs.h>
 #include <obd.h>
+
 #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)
index e4e5c6c..d2e8842 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_LOV
 
+#include <lustre_compat/linux/stringhash.h>
+#include <lustre_compat/linux/rhashtable.h>
+
 #include <libcfs/libcfs.h>
-#include <libcfs/linux/linux-hash.h>
 #include <libcfs/linux/linux-fs.h>
-
 #include <obd.h>
+
 #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));
 }
 
 /**
index cd809df..ef88dd0 100644 (file)
 #include <linux/processor.h>
 #include <linux/random.h>
 
+#include <lustre_compat/linux/rhashtable.h>
+
 #include <libcfs/libcfs.h>
 #include <libcfs/linux/linux-mem.h>
-#include <libcfs/linux/linux-hash.h>
 #include <obd_class.h>
 #include <obd_support.h>
 #include <lustre_disk.h>
index 3594d7e..1adb7cb 100644 (file)
@@ -14,7 +14,7 @@
 #define DEBUG_SUBSYSTEM S_RPC
 
 #include <linux/delay.h>
-#include <libcfs/linux/linux-hash.h>
+#include <lustre_compat/linux/rhashtable.h>
 #include <obd_support.h>
 #include <obd_class.h>
 #include <lustre_net.h>
index cd80123..d21ed4e 100644 (file)
@@ -59,6 +59,8 @@
 #include <net/sock.h>
 #include <linux/un.h>
 
+#include <lustre_compat/linux/hash.h>
+
 #include <obd.h>
 #include <obd_class.h>
 #include <obd_support.h>
@@ -66,7 +68,6 @@
 #include <lustre_net.h>
 #include <lustre_nodemap.h>
 #include <lustre_sec.h>
-#include <libcfs/linux/linux-hash.h>
 
 #include "gss_err.h"
 #include "gss_internal.h"