From: James Simmons Date: Wed, 21 Aug 2019 15:52:03 +0000 (-0400) Subject: LU-9859 libcfs: fix cfs_print_to_console() X-Git-Tag: 2.12.58~49 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=08ec9c8b6f5a1334fa7de822a50fd480b844884c LU-9859 libcfs: fix cfs_print_to_console() The original code for cfs_print_to_console() used printk() and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly to pr_info which is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold both dbghdr_to_err_string() and the function dbghdr_to_info_string() into cfs_print_to_console(). Linux-commit: f030d88558e77bbf07fab388c341af1cf86135c9 Fixes: 003096c7e3e ("LU-6142 libcfs: Fix style issues for linux-tracefile.c") Change-Id: I44646b1ff41505faa05eeea7bfcb6911e893fb73 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/35847 Reviewed-by: Shaun Tancheff Reviewed-by: Arshad Hussain Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/libcfs/libcfs/linux/linux-tracefile.c b/libcfs/libcfs/linux/linux-tracefile.c index b0a8a9b..0cc9c39 100644 --- a/libcfs/libcfs/linux/linux-tracefile.c +++ b/libcfs/libcfs/linux/linux-tracefile.c @@ -208,30 +208,6 @@ cfs_set_ptldebug_header(struct ptldebug_header *header, header->ph_extern_pid = 0; } -static char * -dbghdr_to_err_string(struct ptldebug_header *hdr) -{ - switch (hdr->ph_subsys) { - case S_LND: - case S_LNET: - return "LNetError"; - default: - return "LustreError"; - } -} - -static char * -dbghdr_to_info_string(struct ptldebug_header *hdr) -{ - switch (hdr->ph_subsys) { - case S_LND: - case S_LNET: - return "LNet"; - default: - return "Lustre"; - } -} - /** * tty_write_msg - write a message to a certain tty, not just the console. * @tty: the destination tty_struct @@ -251,7 +227,7 @@ static void tty_write_msg(struct tty_struct *tty, const char *msg) wake_up_interruptible_poll(&tty->write_wait, POLLOUT); } -static void cfs_tty_write_message(const char *prefix, const char *msg) +static void cfs_tty_write_message(const char *prefix, int mask, const char *msg) { struct tty_struct *tty; @@ -260,6 +236,8 @@ static void cfs_tty_write_message(const char *prefix, const char *msg) return; tty_write_msg(tty, prefix); + if ((mask & D_EMERG) || (mask & D_ERROR)) + tty_write_msg(tty, "Error"); tty_write_msg(tty, ": "); tty_write_msg(tty, msg); tty_kref_put(tty); @@ -269,32 +247,39 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, const char *buf, int len, const char *file, const char *fn) { - char *prefix = "Lustre", *ptype = NULL; - - if (mask & D_EMERG) { - prefix = dbghdr_to_err_string(hdr); - ptype = KERN_EMERG; - } else if (mask & D_ERROR) { - prefix = dbghdr_to_err_string(hdr); - ptype = KERN_ERR; - } else if (mask & D_WARNING) { - prefix = dbghdr_to_info_string(hdr); - ptype = KERN_WARNING; - } else if (mask & (D_CONSOLE | libcfs_printk)) { - prefix = dbghdr_to_info_string(hdr); - ptype = KERN_INFO; - } + char *prefix = "Lustre"; - if (mask & D_TTY) - cfs_tty_write_message(prefix, buf); + if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET) + prefix = "LNet"; if (mask & D_CONSOLE) { - pr_info("%s%s: %.*s", ptype, prefix, len, buf); + if (mask & D_EMERG) + pr_emerg("%sError: %.*s", prefix, len, buf); + else if (mask & D_ERROR) + pr_err("%sError: %.*s", prefix, len, buf); + else if (mask & D_WARNING) + pr_warn("%s: %.*s", prefix, len, buf); + else if (mask & libcfs_printk) + pr_info("%s: %.*s", prefix, len, buf); } else { - pr_info("%s%s: %d:%d:(%s:%d:%s()) %.*s", ptype, prefix, - hdr->ph_pid, hdr->ph_extern_pid, file, - hdr->ph_line_num, fn, len, buf); + if (mask & D_EMERG) + pr_emerg("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); + else if (mask & D_ERROR) + pr_err("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); + else if (mask & D_WARNING) + pr_warn("%s: %d:%d:(%s:%d:%s()) %.*s", prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); + else if (mask & (D_CONSOLE | libcfs_printk)) + pr_info("%s: %.*s", prefix, len, buf); } + + if (mask & D_TTY) + cfs_tty_write_message(prefix, mask, buf); } int cfs_trace_max_debug_mb(void)