4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/libcfs/linux/linux-debug.c
38 * Author: Phil Schwan <phil@clusterfs.com>
41 #include <linux/module.h>
42 #include <linux/kmod.h>
43 #include <linux/notifier.h>
44 #include <linux/kernel.h>
46 #include <linux/string.h>
47 #include <linux/stat.h>
48 #include <linux/errno.h>
49 #ifdef HAVE_KERNEL_LOCKED
50 #include <linux/smp_lock.h>
52 #include <linux/unistd.h>
53 #include <linux/interrupt.h>
54 #include <asm/uaccess.h>
55 #include <linux/completion.h>
58 #include <linux/stat.h>
59 #include <asm/uaccess.h>
60 #include <linux/miscdevice.h>
61 #include <linux/version.h>
63 # define DEBUG_SUBSYSTEM S_LNET
65 #include <libcfs/libcfs.h>
66 #include <libcfs/linux/portals_compat25.h>
68 #include "tracefile.h"
70 #include <linux/kallsyms.h>
72 char lnet_upcall[1024] = "/usr/lib/lustre/lnet_upcall";
73 char lnet_debug_log_upcall[1024] = "/usr/lib/lustre/lnet_debug_log_upcall";
76 * Upcall function once a Lustre log has been dumped.
78 * \param file path of the dumped log
80 void libcfs_run_debug_log_upcall(char *file)
86 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
90 argv[0] = lnet_debug_log_upcall;
92 LASSERTF(file != NULL, "called on a null filename\n");
93 argv[1] = file; //only need to pass the path of the file
97 rc = call_usermodehelper(argv[0], argv, envp, 1);
98 if (rc < 0 && rc != -ENOENT) {
99 CERROR("Error %d invoking LNET debug log upcall %s %s; "
100 "check /proc/sys/lnet/debug_log_upcall\n",
101 rc, argv[0], argv[1]);
103 CDEBUG(D_HA, "Invoked LNET debug log upcall %s %s\n",
110 void libcfs_run_upcall(char **argv)
116 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
120 argv[0] = lnet_upcall;
122 while (argv[argc] != NULL)
127 rc = call_usermodehelper(argv[0], argv, envp, 1);
128 if (rc < 0 && rc != -ENOENT) {
129 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; "
130 "check /proc/sys/lnet/upcall\n",
131 rc, argv[0], argv[1],
132 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
133 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
134 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
135 argc < 6 ? "" : ",...");
137 CDEBUG(D_HA, "Invoked LNET upcall %s %s%s%s%s%s%s%s%s\n",
139 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
140 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
141 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
142 argc < 6 ? "" : ",...");
146 void libcfs_run_lbug_upcall(struct libcfs_debug_msg_data *msgdata)
152 snprintf (buf, sizeof buf, "%d", msgdata->msg_line);
155 argv[2] = (char *)msgdata->msg_file;
156 argv[3] = (char *)msgdata->msg_fn;
160 libcfs_run_upcall (argv);
163 /* coverity[+kill] */
164 void lbug_with_loc(struct libcfs_debug_msg_data *msgdata)
166 libcfs_catastrophe = 1;
167 libcfs_debug_msg(msgdata, "LBUG\n");
169 if (in_interrupt()) {
170 panic("LBUG in interrupt.\n");
174 libcfs_debug_dumpstack(NULL);
175 if (!libcfs_panic_on_lbug)
176 libcfs_debug_dumplog();
177 libcfs_run_lbug_upcall(msgdata);
178 if (libcfs_panic_on_lbug)
180 set_task_state(current, TASK_UNINTERRUPTIBLE);
187 #include <linux/nmi.h>
188 #include <asm/stacktrace.h>
190 #ifdef HAVE_STACKTRACE_WARNING
192 print_trace_warning_symbol(void *data, char *msg, unsigned long symbol)
194 printk("%s", (char *)data);
195 print_symbol(msg, symbol);
199 static void print_trace_warning(void *data, char *msg)
201 printk("%s%s\n", (char *)data, msg);
205 static int print_trace_stack(void *data, char *name)
207 printk(" <%s> ", name);
211 static void print_trace_address(void *data, unsigned long addr, int reliable)
215 touch_nmi_watchdog();
216 sprintf(fmt, " [<%016lx>] %s%%s\n", addr, reliable ? "": "? ");
217 __print_symbol(fmt, addr);
220 static const struct stacktrace_ops print_trace_ops = {
221 #ifdef HAVE_STACKTRACE_WARNING
222 .warning = print_trace_warning,
223 .warning_symbol = print_trace_warning_symbol,
225 .stack = print_trace_stack,
226 .address = print_trace_address,
227 #ifdef STACKTRACE_OPS_HAVE_WALK_STACK
228 .walk_stack = print_context_stack,
232 void libcfs_debug_dumpstack(struct task_struct *tsk)
238 printk("Pid: %d, comm: %.20s\n", tsk->pid, tsk->comm);
239 /* show_trace_log_lvl() */
240 printk("\nCall Trace:\n");
241 dump_trace(tsk, NULL, NULL,
242 #ifdef HAVE_DUMP_TRACE_ADDRESS
244 #endif /* HAVE_DUMP_TRACE_ADDRESS */
245 &print_trace_ops, NULL);
249 struct task_struct *libcfs_current(void)
251 CWARN("current task struct is %p\n", current);
255 static int panic_notifier(struct notifier_block *self, unsigned long unused1,
258 if (libcfs_panic_in_progress)
261 libcfs_panic_in_progress = 1;
264 #ifdef LNET_DUMP_ON_PANIC
265 /* This is currently disabled because it spews far too much to the
266 * console on the rare cases it is ever triggered. */
268 if (in_interrupt()) {
269 cfs_trace_debug_print();
271 # ifdef HAVE_KERNEL_LOCKED
272 while (kernel_locked())
275 libcfs_debug_dumplog_internal((void *)(long)current_pid());
281 static struct notifier_block libcfs_panic_notifier = {
282 notifier_call : panic_notifier,
287 void libcfs_register_panic_notifier(void)
289 atomic_notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
292 void libcfs_unregister_panic_notifier(void)
294 atomic_notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
297 EXPORT_SYMBOL(libcfs_debug_dumpstack);
298 EXPORT_SYMBOL(libcfs_current);
300 #endif /* __KERNEL__ */
302 EXPORT_SYMBOL(libcfs_run_upcall);
303 EXPORT_SYMBOL(libcfs_run_lbug_upcall);
304 EXPORT_SYMBOL(lbug_with_loc);