Whamcloud - gitweb
LU-17418 libcfs: support debug setup for libcfs modules 25/53825/7
authorJames Simmons <jsimmons@infradead.org>
Mon, 5 Feb 2024 02:53:44 +0000 (21:53 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Feb 2024 06:59:18 +0000 (06:59 +0000)
Work was landed to make Lustre ensure key libcfs components
were initialized for both a module build and a build directly
into the kernel. This change resulted in an defect that allows
you to crash a node when you only load libcfs.ko and run a
user land tool to set a debugfs setting of libcfs. The debug
handling is critical to load before anything. Update Lustre
to handle both a module and builtin setup for Lustre. When
lustre is built into the kernel we can't control if libcfs_init()
is called first so have libcfs_setup() handle setting up the
debug handling. When built as a module have libcfs_init()
setup the debug handling instead. For both cases
libcfs_debug_init() is always called so make sure we only
initialize it only once. Add a test to validate this fix.

Fixes: f3494a6e9 ("LU-9859 libcfs: refactor libcfs initialization.")
Test-Parameters: trivial testlist=conf-sanity env=ONLY="5j"
Change-Id: If4a229e43b9e06a723546c03eb2b787ba0b16f5a
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53825
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/libcfs/debug.c
libcfs/libcfs/module.c
lustre/tests/conf-sanity.sh [changed mode: 0644->0755]

index cb67d26..9cc4c6a 100644 (file)
@@ -642,11 +642,17 @@ static void libcfs_unregister_panic_notifier(void)
                                         &libcfs_panic_notifier);
 }
 
+static bool debug_started;
+
 int libcfs_debug_init(unsigned long bufsize)
 {
        unsigned int max = libcfs_debug_mb;
        int rc = 0;
 
+       if (debug_started)
+               return 0;
+
+       debug_started = true;
        if (libcfs_console_max_delay <= 0 || /* not set by user or */
            libcfs_console_min_delay <= 0 || /* set to invalid values */
            libcfs_console_min_delay >= libcfs_console_max_delay) {
@@ -679,6 +685,7 @@ int libcfs_debug_cleanup(void)
        kernel_param_lock(THIS_MODULE);
        cfs_tracefile_exit();
        kernel_param_unlock(THIS_MODULE);
+       debug_started = false;
        return 0;
 }
 
index fb7e861..d21cbb2 100644 (file)
@@ -667,7 +667,7 @@ static void *debugfs_state;
 
 int libcfs_setup(void)
 {
-       int rc = -EINVAL;
+       int rc = 0;
 
        mutex_lock(&libcfs_startup);
        if (libcfs_active)
@@ -720,9 +720,18 @@ static int __init libcfs_init(void)
 {
        int rc;
 
+       mutex_lock(&libcfs_startup);
+       rc = libcfs_debug_init(5 * 1024 * 1024);
+       mutex_unlock(&libcfs_startup);
+       if (rc < 0) {
+               pr_err("LustreError: libcfs_debug_init: rc = %d\n", rc);
+               return rc;
+       }
+
        rc = cfs_arch_init();
        if (rc < 0) {
                CERROR("cfs_arch_init: error %d\n", rc);
+               libcfs_debug_cleanup();
                return rc;
        }
 
old mode 100644 (file)
new mode 100755 (executable)
index af68d16..e154feb
@@ -548,6 +548,15 @@ test_5i() {
 }
 run_test 5i "start mdt failure at mdt_quota_init()"
 
+test_5j() {
+       unload_modules
+       load_module ../libcfs/libcfs/libcfs ||
+               error "Failed to load modules libcfs rc = $?"
+       $LCTL set_param debug=all
+       rmmod -v libcfs
+}
+run_test 5j "verify libcfs doesn't crash when setting debug flags"
+
 test_6() {
        setup
        manual_umount_client