Whamcloud - gitweb
LU-9859 libcfs: migrate hash table to obdclass 45/57945/5
authorJames Simmons <jsimmons@infradead.org>
Mon, 3 Feb 2025 17:07:27 +0000 (12:07 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 28 Feb 2025 08:14:37 +0000 (08:14 +0000)
The lustre specific hash is only used by the Lustre layer so it
doesn't make sense to keep it in libcfs. Move the hash code to
obdclass. Once ldlm resource hashtable moves to rhashtabble this
be server only code.

Test-Parameters: trivial
Change-Id: I676f6a3decf17e0e90cd747ad4bb4c4d16a52a30
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57945
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
23 files changed:
libcfs/include/libcfs/Makefile.am
libcfs/include/libcfs/libcfs.h
libcfs/libcfs/Makefile.in
libcfs/libcfs/module.c
lustre/include/Makefile.am
lustre/include/cfs_hash.h [moved from libcfs/include/libcfs/libcfs_hash.h with 99% similarity]
lustre/include/lustre_dlm.h
lustre/include/lustre_osc.h
lustre/include/obd_class.h
lustre/mdt/mdt_hsm_cdt_actions.c
lustre/mdt/mdt_hsm_cdt_requests.c
lustre/mdt/mdt_internal.h
lustre/obdclass/Makefile.in
lustre/obdclass/class_obd.c
lustre/obdclass/genops.c
lustre/obdclass/hash.c [moved from libcfs/libcfs/hash.c with 99% similarity]
lustre/obdclass/jobid.c
lustre/obdclass/lprocfs_status_server.c
lustre/obdclass/obd_config.c
lustre/ptlrpc/nodemap_handler.c
lustre/ptlrpc/nodemap_internal.h
lustre/ptlrpc/nrs_tbf.c
lustre/quota/lquota_internal.h

index cd38c01..1471122 100644 (file)
@@ -15,5 +15,4 @@ EXTRA_DIST = \
        libcfs.h \
        libcfs_debug.h \
        libcfs_fail.h \
-       libcfs_hash.h \
        libcfs_private.h
index 7b35c9b..c593e91 100644 (file)
@@ -22,6 +22,7 @@
 #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>
@@ -31,7 +32,6 @@
 #include <uapi/linux/lnet/libcfs_ioctl.h>
 #include <libcfs/libcfs_debug.h>
 #include <libcfs/libcfs_private.h>
-#include <libcfs/libcfs_hash.h>
 #include <libcfs/libcfs_fail.h>
 
 #define LIBCFS_VERSION "0.7.1"
@@ -50,8 +50,6 @@ typedef s32 timeout_t;
 int libcfs_setup(void);
 int libcfs_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data);
 
-extern struct workqueue_struct *cfs_rehash_wq;
-
 #ifdef HAVE_CONST_CTR_TABLE
 #define DEFINE_CTL_TABLE_INIT(__name, init)\
        const struct ctl_table *__name = init
index fcbf367..62cba0b 100644 (file)
@@ -21,7 +21,7 @@ default: all
 libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
 libcfs-crypto-objs := $(addprefix crypto/,$(libcfs-crypto-objs))
 
-libcfs-all-objs := debug.o fail.o module.o tracefile.o hash.o
+libcfs-all-objs := debug.o fail.o module.o tracefile.o
 
 libcfs-objs := $(libcfs-linux-objs) $(libcfs-all-objs)
 @LLCRYPT_TRUE@libcfs-objs += $(libcfs-crypto-objs)
index b59e15a..eac235d 100644 (file)
@@ -639,15 +639,6 @@ int libcfs_setup(void)
                goto cleanup_lock;
        }
 
-       cfs_rehash_wq = alloc_workqueue("cfs_rh", WQ_SYSFS, 4);
-       if (!cfs_rehash_wq) {
-               rc = -ENOMEM;
-               CERROR("libcfs: failed to start rehash workqueue: rc = %d\n",
-                      rc);
-               libcfs_debug_cleanup();
-               goto cleanup_lock;
-       }
-
        CDEBUG(D_OTHER, "libcfs setup OK\n");
        libcfs_active = 1;
 cleanup_lock:
@@ -695,9 +686,6 @@ static void __exit libcfs_exit(void)
        CDEBUG(D_MALLOC, "before Portals cleanup: kmem %lld\n",
               libcfs_kmem_read());
 
-       if (cfs_rehash_wq)
-               destroy_workqueue(cfs_rehash_wq);
-
        /* the below message is checked in test-framework.sh check_mem_leak() */
        if (libcfs_kmem_read() != 0)
                CERROR("Portals memory leaked: %lld bytes\n",
index 97a9743..6eb7fcd 100644 (file)
@@ -16,6 +16,7 @@ SUBDIRS = lustre uapi/linux/lustre
 DIST_SUBDIRS = lustre uapi/linux/lustre
 
 EXTRA_DIST = \
+       cfs_hash.h \
        cl_object.h \
        dt_object.h \
        erasure_code.h \
similarity index 99%
rename from libcfs/include/libcfs/libcfs_hash.h
rename to lustre/include/cfs_hash.h
index 564629d..c92a7ae 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
 #include <linux/refcount.h>
+#include <libcfs/libcfs.h>
 #include <libcfs/linux/linux-hash.h>
 
 /* disable debug */
index f6ce885..bcf17a3 100644 (file)
@@ -25,6 +25,7 @@
 #ifndef _LUSTRE_DLM_H__
 #define _LUSTRE_DLM_H__
 
+#include <cfs_hash.h>
 #include <lustre_lib.h>
 #include <lustre_net.h>
 #include <lustre_import.h>
index bf87865..a6e52f2 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <libcfs/libcfs.h>
 #include <obd.h>
+#include <cfs_hash.h>
 #include <cl_object.h>
 #include <lustre_crypto.h>
 
index 1b2509a..5fcafbb 100644 (file)
@@ -164,6 +164,10 @@ void obd_pool_put_objects(void *buf, unsigned int order);
 int obd_pool_get_free_objects(unsigned int order);
 int pool_is_at_full_capacity(int order);
 
+/* cfs_hash.c */
+int cfs_hash_init(void);
+void cfs_hash_fini(void);
+
 int encrypt_page_pools_seq_show(struct seq_file *m, void *v);
 int page_pools_seq_show(struct seq_file *m, void *v);
 
index 16ed059..21256d3 100644 (file)
@@ -17,7 +17,6 @@
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <libcfs/libcfs.h>
-#include <libcfs/libcfs_hash.h>
 #include <obd_support.h>
 #include <lustre_export.h>
 #include <obd.h>
index 8c2742d..09662b3 100644 (file)
@@ -17,7 +17,6 @@
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <libcfs/libcfs.h>
-#include <libcfs/libcfs_hash.h>
 #include <obd_support.h>
 #include <lprocfs_status.h>
 #include <linux/interval_tree_generic.h>
index 9fc7bbf..fd51dc9 100644 (file)
@@ -24,7 +24,7 @@
 #define _MDT_INTERNAL_H
 
 #include <libcfs/libcfs.h>
-#include <libcfs/libcfs_hash.h>
+#include <cfs_hash.h>
 #include <upcall_cache.h>
 #include <obd_class.h>
 #include <lustre_disk.h>
index de7f25d..464e35f 100644 (file)
@@ -13,7 +13,7 @@ MODULES := obdclass
 default: all
 
 obdclass-all-objs := llog.o llog_cat.o llog_obd.o llog_swab.o
-obdclass-all-objs += class_obd.o genops.o
+obdclass-all-objs += class_obd.o genops.o hash.o
 obdclass-all-objs += lprocfs_status.o lprocfs_counters.o
 obdclass-all-objs += lustre_handles.o lustre_peer.o
 obdclass-all-objs += statfs_pack.o obdo.o obd_config.o obd_mount.o obd_sysfs.o
index fb79c30..f505440 100644 (file)
@@ -850,10 +850,13 @@ static int __init obdclass_init(void)
        if (err)
                goto cleanup_llog_info;
 
+       err = cfs_hash_init();
+       if (err)
+               goto cleanup_obd_pool;
 #ifdef HAVE_SERVER_SUPPORT
        err = dt_global_init();
        if (err != 0)
-               goto cleanup_obd_pool;
+               goto cleanup_cfs_hash;
 
        err = lu_ucred_global_init();
        if (err != 0)
@@ -877,8 +880,10 @@ cleanup_all:
 cleanup_dt_global:
        dt_global_fini();
 
-cleanup_obd_pool:
+cleanup_cfs_hash:
 #endif /* HAVE_SERVER_SUPPORT */
+       cfs_hash_fini();
+cleanup_obd_pool:
        obd_pool_fini();
 
 cleanup_llog_info:
@@ -952,6 +957,7 @@ static void __exit obdclass_exit(void)
        lu_ucred_global_fini();
        dt_global_fini();
 #endif /* HAVE_SERVER_SUPPORT */
+       cfs_hash_fini();
        obd_pool_fini();
        llog_info_fini();
        cl_global_fini();
index f7b0d74..93b1fe8 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/workqueue.h>
 #include <lustre_compat.h>
+#include <cfs_hash.h>
 #include <obd_class.h>
 #include <lustre_log.h>
 #include <lprocfs_status.h>
similarity index 99%
rename from libcfs/libcfs/hash.c
rename to lustre/obdclass/hash.c
index 7aad886..24cc517 100644 (file)
@@ -85,8 +85,9 @@
 #include <linux/seq_file.h>
 #include <linux/log2.h>
 
-#include <libcfs/linux/linux-list.h>
 #include <libcfs/libcfs.h>
+#include <cfs_hash.h>
+#include <obd_class.h>
 
 #if CFS_HASH_DEBUG_LEVEL >= CFS_HASH_DEBUG_1
 static unsigned int warn_on_depth = 8;
@@ -96,6 +97,25 @@ MODULE_PARM_DESC(warn_on_depth, "warning when hash depth is high.");
 
 struct workqueue_struct *cfs_rehash_wq;
 
+int cfs_hash_init(void)
+{
+       int rc = 0;
+
+       cfs_rehash_wq = alloc_workqueue("cfs_rh", WQ_SYSFS, 4);
+       if (!cfs_rehash_wq) {
+               rc = -ENOMEM;
+               CERROR("obdclass: failed to start rehash workqueue: rc = %d\n",
+                      rc);
+       }
+       return rc;
+}
+
+void cfs_hash_fini(void)
+{
+       if (cfs_rehash_wq)
+               destroy_workqueue(cfs_rehash_wq);
+}
+
 static inline void
 cfs_hash_nl_lock(union cfs_hash_lock *lock, int exclusive) {}
 
index 017da36..38d5fef 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/utsname.h>
 
 #include <libcfs/libcfs.h>
+#include <cfs_hash.h>
 #include <obd_support.h>
 #include <obd_class.h>
 #include <lustre_net.h>
index 1bf4180..1957013 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/kobject.h>
 #include <linux/sysfs.h>
 
+#include <cfs_hash.h>
 #include <obd_class.h>
 #include <lprocfs_status.h>
 #include <lustre_nodemap.h>
index 40aea75..32528d8 100644 (file)
@@ -18,6 +18,9 @@
 #include <linux/kobject.h>
 #include <linux/string.h>
 
+#ifdef HAVE_SERVER_SUPPORT
+#include <cfs_hash.h>
+#endif
 #include <llog_swab.h>
 #include <lprocfs_status.h>
 #include <lustre_disk.h>
index 96b1e8d..bb59a81 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/sort.h>
 #include <uapi/linux/lnet/nidstr.h>
+#include <cfs_hash.h>
 #include <lustre_net.h>
 #include <lustre_acl.h>
 #include <obd_class.h>
index df846ef..51205f7 100644 (file)
@@ -11,6 +11,7 @@
 #ifndef _NODEMAP_INTERNAL_H
 #define _NODEMAP_INTERNAL_H
 
+#include <cfs_hash.h>
 #include <lustre_nodemap.h>
 #include <lustre_disk.h>
 #include <linux/rbtree.h>
index 56d7ec3..5b4112f 100644 (file)
@@ -12,6 +12,7 @@
 
 #define DEBUG_SUBSYSTEM S_RPC
 #include <linux/delay.h>
+#include <cfs_hash.h>
 #include <obd_support.h>
 #include <obd_class.h>
 #include <libcfs/libcfs.h>
index 21e600f..7e2578b 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <obd.h>
 #include <dt_object.h>
+#include <cfs_hash.h>
 #include <lustre_quota.h>
 
 #ifndef _LQUOTA_INTERNAL_H