From 145e315b0eefbbfd9ec0ded44560c02aa37877e5 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 3 Feb 2025 12:07:27 -0500 Subject: [PATCH] LU-9859 libcfs: migrate hash table to obdclass 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 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57945 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: Timothy Day Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/Makefile.am | 1 - libcfs/include/libcfs/libcfs.h | 4 +--- libcfs/libcfs/Makefile.in | 2 +- libcfs/libcfs/module.c | 12 ------------ lustre/include/Makefile.am | 1 + .../libcfs_hash.h => lustre/include/cfs_hash.h | 1 + lustre/include/lustre_dlm.h | 1 + lustre/include/lustre_osc.h | 1 + lustre/include/obd_class.h | 4 ++++ lustre/mdt/mdt_hsm_cdt_actions.c | 1 - lustre/mdt/mdt_hsm_cdt_requests.c | 1 - lustre/mdt/mdt_internal.h | 2 +- lustre/obdclass/Makefile.in | 2 +- lustre/obdclass/class_obd.c | 10 ++++++++-- lustre/obdclass/genops.c | 1 + {libcfs/libcfs => lustre/obdclass}/hash.c | 22 +++++++++++++++++++++- lustre/obdclass/jobid.c | 1 + lustre/obdclass/lprocfs_status_server.c | 1 + lustre/obdclass/obd_config.c | 3 +++ lustre/ptlrpc/nodemap_handler.c | 1 + lustre/ptlrpc/nodemap_internal.h | 1 + lustre/ptlrpc/nrs_tbf.c | 1 + lustre/quota/lquota_internal.h | 1 + 23 files changed, 51 insertions(+), 24 deletions(-) rename libcfs/include/libcfs/libcfs_hash.h => lustre/include/cfs_hash.h (99%) rename {libcfs/libcfs => lustre/obdclass}/hash.c (99%) diff --git a/libcfs/include/libcfs/Makefile.am b/libcfs/include/libcfs/Makefile.am index cd38c01..1471122 100644 --- a/libcfs/include/libcfs/Makefile.am +++ b/libcfs/include/libcfs/Makefile.am @@ -15,5 +15,4 @@ EXTRA_DIST = \ libcfs.h \ libcfs_debug.h \ libcfs_fail.h \ - libcfs_hash.h \ libcfs_private.h diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 7b35c9b..c593e91 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -22,6 +22,7 @@ #include #endif +#include #include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #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 diff --git a/libcfs/libcfs/Makefile.in b/libcfs/libcfs/Makefile.in index fcbf367..62cba0b 100644 --- a/libcfs/libcfs/Makefile.in +++ b/libcfs/libcfs/Makefile.in @@ -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) diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index b59e15a..eac235d 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -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", diff --git a/lustre/include/Makefile.am b/lustre/include/Makefile.am index 97a9743..6eb7fcd 100644 --- a/lustre/include/Makefile.am +++ b/lustre/include/Makefile.am @@ -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 \ diff --git a/libcfs/include/libcfs/libcfs_hash.h b/lustre/include/cfs_hash.h similarity index 99% rename from libcfs/include/libcfs/libcfs_hash.h rename to lustre/include/cfs_hash.h index 564629d..c92a7ae 100644 --- a/libcfs/include/libcfs/libcfs_hash.h +++ b/lustre/include/cfs_hash.h @@ -19,6 +19,7 @@ #include #include #include +#include #include /* disable debug */ diff --git a/lustre/include/lustre_dlm.h b/lustre/include/lustre_dlm.h index f6ce885..bcf17a3 100644 --- a/lustre/include/lustre_dlm.h +++ b/lustre/include/lustre_dlm.h @@ -25,6 +25,7 @@ #ifndef _LUSTRE_DLM_H__ #define _LUSTRE_DLM_H__ +#include #include #include #include diff --git a/lustre/include/lustre_osc.h b/lustre/include/lustre_osc.h index bf87865..a6e52f2 100644 --- a/lustre/include/lustre_osc.h +++ b/lustre/include/lustre_osc.h @@ -26,6 +26,7 @@ #include #include +#include #include #include diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index 1b2509a..5fcafbb 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -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); diff --git a/lustre/mdt/mdt_hsm_cdt_actions.c b/lustre/mdt/mdt_hsm_cdt_actions.c index 16ed059..21256d3 100644 --- a/lustre/mdt/mdt_hsm_cdt_actions.c +++ b/lustre/mdt/mdt_hsm_cdt_actions.c @@ -17,7 +17,6 @@ #define DEBUG_SUBSYSTEM S_MDS #include -#include #include #include #include diff --git a/lustre/mdt/mdt_hsm_cdt_requests.c b/lustre/mdt/mdt_hsm_cdt_requests.c index 8c2742d..09662b3 100644 --- a/lustre/mdt/mdt_hsm_cdt_requests.c +++ b/lustre/mdt/mdt_hsm_cdt_requests.c @@ -17,7 +17,6 @@ #define DEBUG_SUBSYSTEM S_MDS #include -#include #include #include #include diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 9fc7bbf..fd51dc9 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -24,7 +24,7 @@ #define _MDT_INTERNAL_H #include -#include +#include #include #include #include diff --git a/lustre/obdclass/Makefile.in b/lustre/obdclass/Makefile.in index de7f25d..464e35f 100644 --- a/lustre/obdclass/Makefile.in +++ b/lustre/obdclass/Makefile.in @@ -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 diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index fb79c30..f505440 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -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(); diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index f7b0d74..93b1fe8 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/libcfs/libcfs/hash.c b/lustre/obdclass/hash.c similarity index 99% rename from libcfs/libcfs/hash.c rename to lustre/obdclass/hash.c index 7aad886..24cc517 100644 --- a/libcfs/libcfs/hash.c +++ b/lustre/obdclass/hash.c @@ -85,8 +85,9 @@ #include #include -#include #include +#include +#include #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) {} diff --git a/lustre/obdclass/jobid.c b/lustre/obdclass/jobid.c index 017da36..38d5fef 100644 --- a/lustre/obdclass/jobid.c +++ b/lustre/obdclass/jobid.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include diff --git a/lustre/obdclass/lprocfs_status_server.c b/lustre/obdclass/lprocfs_status_server.c index 1bf4180..1957013 100644 --- a/lustre/obdclass/lprocfs_status_server.c +++ b/lustre/obdclass/lprocfs_status_server.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index 40aea75..32528d8 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -18,6 +18,9 @@ #include #include +#ifdef HAVE_SERVER_SUPPORT +#include +#endif #include #include #include diff --git a/lustre/ptlrpc/nodemap_handler.c b/lustre/ptlrpc/nodemap_handler.c index 96b1e8d..bb59a81 100644 --- a/lustre/ptlrpc/nodemap_handler.c +++ b/lustre/ptlrpc/nodemap_handler.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/lustre/ptlrpc/nodemap_internal.h b/lustre/ptlrpc/nodemap_internal.h index df846ef..51205f7 100644 --- a/lustre/ptlrpc/nodemap_internal.h +++ b/lustre/ptlrpc/nodemap_internal.h @@ -11,6 +11,7 @@ #ifndef _NODEMAP_INTERNAL_H #define _NODEMAP_INTERNAL_H +#include #include #include #include diff --git a/lustre/ptlrpc/nrs_tbf.c b/lustre/ptlrpc/nrs_tbf.c index 56d7ec3..5b4112f 100644 --- a/lustre/ptlrpc/nrs_tbf.c +++ b/lustre/ptlrpc/nrs_tbf.c @@ -12,6 +12,7 @@ #define DEBUG_SUBSYSTEM S_RPC #include +#include #include #include #include diff --git a/lustre/quota/lquota_internal.h b/lustre/quota/lquota_internal.h index 21e600f..7e2578b 100644 --- a/lustre/quota/lquota_internal.h +++ b/lustre/quota/lquota_internal.h @@ -7,6 +7,7 @@ #include #include +#include #include #ifndef _LQUOTA_INTERNAL_H -- 1.8.3.1