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_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) {
kernel_param_lock(THIS_MODULE);
cfs_tracefile_exit();
kernel_param_unlock(THIS_MODULE);
+ debug_started = false;
return 0;
}
int libcfs_setup(void)
{
- int rc = -EINVAL;
+ int rc = 0;
mutex_lock(&libcfs_startup);
if (libcfs_active)
{
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;
}
}
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