Whamcloud - gitweb
LU-11062 libcfs: use save_stack_trace for stack dump 52/32952/3
authorYang Sheng <ys@whamcloud.com>
Tue, 7 Aug 2018 16:24:19 +0000 (00:24 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 13 Aug 2018 01:13:41 +0000 (01:13 +0000)
The stacktrace_ops has been removed recently. So we
have to use save_stack_trace_tsk for stack trace
dump.

Signed-off-by: Yang Sheng <ys@whamcloud.com>
Change-Id: Icb3d0dbd62c35fdd9b8de925aec9358a2208814f
Reviewed-on: https://review.whamcloud.com/32952
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Jenkins
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/libcfs/linux/linux-debug.c

index 2778c62..46fbc29 100644 (file)
@@ -45,6 +45,8 @@
 #endif
 #include <linux/string.h>
 #include <linux/unistd.h>
 #endif
 #include <linux/string.h>
 #include <linux/unistd.h>
+#include <linux/stacktrace.h>
+#include <linux/utsname.h>
 
 # define DEBUG_SUBSYSTEM S_LNET
 
 
 # define DEBUG_SUBSYSTEM S_LNET
 
@@ -92,25 +94,51 @@ void libcfs_run_debug_log_upcall(char *file)
 /* coverity[+kill] */
 void lbug_with_loc(struct libcfs_debug_msg_data *msgdata)
 {
 /* coverity[+kill] */
 void lbug_with_loc(struct libcfs_debug_msg_data *msgdata)
 {
-        libcfs_catastrophe = 1;
-        libcfs_debug_msg(msgdata, "LBUG\n");
+       libcfs_catastrophe = 1;
+       libcfs_debug_msg(msgdata, "LBUG\n");
 
 
-        if (in_interrupt()) {
-                panic("LBUG in interrupt.\n");
-                /* not reached */
-        }
+       if (in_interrupt()) {
+               panic("LBUG in interrupt.\n");
+               /* not reached */
+       }
 
 
-        libcfs_debug_dumpstack(NULL);
-        if (!libcfs_panic_on_lbug)
-                libcfs_debug_dumplog();
-        if (libcfs_panic_on_lbug)
-                panic("LBUG");
+       libcfs_debug_dumpstack(NULL);
+       if (libcfs_panic_on_lbug)
+               panic("LBUG");
+       else
+               libcfs_debug_dumplog();
        set_current_state(TASK_UNINTERRUPTIBLE);
        set_current_state(TASK_UNINTERRUPTIBLE);
-        while (1)
-                schedule();
+       while (1)
+               schedule();
 }
 EXPORT_SYMBOL(lbug_with_loc);
 
 }
 EXPORT_SYMBOL(lbug_with_loc);
 
+#ifdef CONFIG_STACKTRACE
+
+#define MAX_ST_ENTRIES 100
+static DEFINE_SPINLOCK(st_lock);
+
+static void libcfs_call_trace(struct task_struct *tsk)
+{
+       struct stack_trace trace;
+       static unsigned long entries[MAX_ST_ENTRIES];
+
+       trace.nr_entries = 0;
+       trace.max_entries = MAX_ST_ENTRIES;
+       trace.entries = entries;
+       trace.skip = 0;
+
+       spin_lock(&st_lock);
+       pr_info("Pid: %d, comm: %.20s %s %s\n", tsk->pid, tsk->comm,
+              init_utsname()->release, init_utsname()->version);
+       pr_info("Call Trace:\n");
+       save_stack_trace_tsk(tsk, &trace);
+       print_stack_trace(&trace, 0);
+       spin_unlock(&st_lock);
+}
+
+#else /* !CONFIG_STACKTRACE */
+
 #ifdef CONFIG_X86
 #include <linux/nmi.h>
 #include <asm/stacktrace.h>
 #ifdef CONFIG_X86
 #include <linux/nmi.h>
 #include <asm/stacktrace.h>
@@ -198,6 +226,8 @@ static void libcfs_call_trace(struct task_struct *tsk)
 
 #endif /* CONFIG_X86 */
 
 
 #endif /* CONFIG_X86 */
 
+#endif /* CONFIG_STACKTRACE */
+
 void libcfs_debug_dumpstack(struct task_struct *tsk)
 {
        libcfs_call_trace(tsk ?: current);
 void libcfs_debug_dumpstack(struct task_struct *tsk)
 {
        libcfs_call_trace(tsk ?: current);