From: Timothy Day Date: Sun, 8 Dec 2024 06:46:41 +0000 (-0500) Subject: LU-17995 libcfs: implement libcfs_subsystem_debug X-Git-Tag: 2.16.52~79 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F57336%2F3;p=fs%2Flustre-release.git LU-17995 libcfs: implement libcfs_subsystem_debug Allow printk to be enabled based on subsystem. This mirrors the existing infrastructure for printing debug messages to console. Also, include file and function names in debug messages printed to the console. These changes remove the need for the custom debugging in the in-memory OSD. Test-Parameters: trivial Signed-off-by: Timothy Day Change-Id: Ifaca7f6d4f1b7b5fb42e7147b5a9dff0b34f643a Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57336 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/libcfs_debug.h b/libcfs/include/libcfs/libcfs_debug.h index 5c4be6e..1375dda 100644 --- a/libcfs/include/libcfs/libcfs_debug.h +++ b/libcfs/include/libcfs/libcfs_debug.h @@ -25,6 +25,7 @@ */ extern unsigned int libcfs_subsystem_debug; extern unsigned int libcfs_debug; +extern unsigned int libcfs_subsystem_printk; extern unsigned int libcfs_printk; extern unsigned int libcfs_watchdog_ratelimit; extern unsigned int libcfs_console_ratelimit; diff --git a/libcfs/libcfs/debug.c b/libcfs/libcfs/debug.c index 868cbf1..7ed63d0 100644 --- a/libcfs/libcfs/debug.c +++ b/libcfs/libcfs/debug.c @@ -103,6 +103,10 @@ module_param_call(libcfs_debug_mb, libcfs_param_debug_mb_set, param_get_uint, #endif MODULE_PARM_DESC(libcfs_debug_mb, "Total debug buffer size."); +unsigned int libcfs_subsystem_printk; +module_param(libcfs_subsystem_printk, uint, 0644); +MODULE_PARM_DESC(libcfs_subsystem_printk, "Lustre kernel debug subsystem console mask"); + unsigned int libcfs_printk = D_CANTMASK; module_param(libcfs_printk, uint, 0644); MODULE_PARM_DESC(libcfs_printk, "Lustre kernel debug console mask"); diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 68e81a7..e685778 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -104,14 +104,15 @@ static int proc_dobitmasks(const struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - const int tmpstrlen = 512; - char *tmpstr = NULL; - int rc; + unsigned int *mask = table->data; + int is_subsys = (mask == &libcfs_subsystem_debug || + mask == &libcfs_subsystem_printk) ? 1 : 0; + int is_printk = (mask == &libcfs_printk) ? 1 : 0; + const int tmpstrlen = 512; + char *tmpstr = NULL; size_t nob = *lenp; loff_t pos = *ppos; - unsigned int *mask = table->data; - int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0; - int is_printk = (mask == &libcfs_printk) ? 1 : 0; + int rc; if (!write) { tmpstr = kmalloc(tmpstrlen, GFP_KERNEL | __GFP_ZERO); @@ -391,6 +392,13 @@ static struct ctl_table lnet_table[] = { .proc_handler = cfs_proc_handler(&proc_dobitmasks), }, { + .procname = "subsystem_printk", + .data = &libcfs_subsystem_printk, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = cfs_proc_handler(&proc_dobitmasks), + }, + { .procname = "debug_log_upcall", .data = lnet_debug_log_upcall, .maxlen = sizeof(lnet_debug_log_upcall), diff --git a/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index 583e540..7fd7b70 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -329,10 +329,11 @@ static void cfs_vprint_to_console(struct ptldebug_header *hdr, struct va_format *vaf, const char *file, const char *fn) { - char *prefix = "Lustre"; + int subsys = hdr->ph_subsys; int mask = hdr->ph_mask; + char *prefix = "Lustre"; - if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET) + if (subsys == S_LND || subsys == S_LNET) prefix = "LNet"; if (mask & D_CONSOLE) { @@ -342,7 +343,8 @@ static void cfs_vprint_to_console(struct ptldebug_header *hdr, pr_err("%sError: %pV", prefix, vaf); else if (mask & D_WARNING) pr_warn("%s: %pV", prefix, vaf); - else if (mask & libcfs_printk) + else if (mask & libcfs_printk || + subsys & libcfs_subsystem_printk) pr_info("%s: %pV", prefix, vaf); } else { if (mask & D_EMERG) @@ -357,8 +359,11 @@ static void cfs_vprint_to_console(struct ptldebug_header *hdr, pr_warn("%s: %d:%d:(%s:%d:%s()) %pV", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, vaf); - else if (mask & (D_CONSOLE | libcfs_printk)) - pr_info("%s: %pV", prefix, vaf); + else if (mask & libcfs_printk || + subsys & libcfs_subsystem_printk) + pr_info("%s: %d:%d:(%s:%d:%s()) %pV", prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, vaf); } } @@ -676,7 +681,8 @@ void libcfs_debug_msg(struct libcfs_debug_msg_data *msgdata, __LASSERT(tage->used <= PAGE_SIZE); console: - if ((header.ph_mask & libcfs_printk) == 0) { + if ((header.ph_mask & libcfs_printk) == 0 && + (header.ph_subsys & libcfs_subsystem_printk) == 0) { /* no console output requested */ if (tcd != NULL) cfs_trace_put_tcd(tcd);