1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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>
42 # define EXPORT_SYMTAB
45 #ifndef AUTOCONF_INCLUDED
46 #include <linux/config.h>
48 #include <linux/module.h>
49 #include <linux/kmod.h>
50 #include <linux/notifier.h>
51 #include <linux/kernel.h>
53 #include <linux/string.h>
54 #include <linux/stat.h>
55 #include <linux/errno.h>
56 #include <linux/smp_lock.h>
57 #include <linux/unistd.h>
58 #include <linux/interrupt.h>
59 #include <asm/system.h>
60 #include <asm/uaccess.h>
61 #include <linux/completion.h>
64 #include <linux/stat.h>
65 #include <asm/uaccess.h>
66 #include <linux/miscdevice.h>
67 #include <linux/version.h>
69 # define DEBUG_SUBSYSTEM S_LNET
71 #include <libcfs/libcfs.h>
72 #include <libcfs/linux/portals_compat25.h>
74 #include "tracefile.h"
76 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
77 #include <linux/kallsyms.h>
80 char lnet_upcall[1024] = "/usr/lib/lustre/lnet_upcall";
82 void libcfs_run_upcall(char **argv)
88 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
92 argv[0] = lnet_upcall;
94 while (argv[argc] != NULL)
99 rc = USERMODEHELPER(argv[0], argv, envp);
100 if (rc < 0 && rc != -ENOENT) {
101 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; "
102 "check /proc/sys/lnet/upcall\n",
103 rc, argv[0], argv[1],
104 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
105 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
106 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
107 argc < 6 ? "" : ",...");
109 CDEBUG(D_HA, "Invoked LNET upcall %s %s%s%s%s%s%s%s%s\n",
111 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
112 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
113 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
114 argc < 6 ? "" : ",...");
118 void libcfs_run_lbug_upcall(char *file, const char *fn, const int line)
124 snprintf (buf, sizeof buf, "%d", line);
128 argv[3] = (char *)fn;
132 libcfs_run_upcall (argv);
136 void lbug_with_loc(char *file, const char *func, const int line)
138 libcfs_catastrophe = 1;
139 libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line,
140 "LBUG - trying to dump log to %s\n", debug_file_path);
141 libcfs_debug_dumplog();
142 libcfs_run_lbug_upcall(file, func, line);
147 /* coverity[+kill] */
148 void lbug_with_loc(char *file, const char *func, const int line)
150 libcfs_catastrophe = 1;
151 libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line, "LBUG\n");
153 if (in_interrupt()) {
154 panic("LBUG in interrupt.\n");
158 libcfs_debug_dumpstack(NULL);
159 libcfs_debug_dumplog();
160 libcfs_run_lbug_upcall(file, func, line);
161 if (libcfs_panic_on_lbug)
163 set_task_state(current, TASK_UNINTERRUPTIBLE);
167 #endif /* __arch_um__ */
171 void libcfs_debug_dumpstack(struct task_struct *tsk)
173 #if defined(__arch_um__)
175 CWARN("stack dump for pid %d (%d) requested; wake up gdb.\n",
176 tsk->pid, UML_PID(tsk));
178 #elif defined(HAVE_SHOW_TASK)
179 /* this is exported by lustre kernel version 42 */
180 extern void show_task(struct task_struct *);
184 CWARN("showing stack for process %d\n", tsk->pid);
187 if ((tsk == NULL) || (tsk == current))
190 CWARN("can't show stack: kernel doesn't export show_task\n");
194 cfs_task_t *libcfs_current(void)
196 CWARN("current task struct is %p\n", current);
200 static int panic_notifier(struct notifier_block *self, unsigned long unused1,
203 if (libcfs_panic_in_progress)
206 libcfs_panic_in_progress = 1;
209 #ifdef LNET_DUMP_ON_PANIC
210 /* This is currently disabled because it spews far too much to the
211 * console on the rare cases it is ever triggered. */
213 if (in_interrupt()) {
216 while (current->lock_depth >= 0)
219 libcfs_debug_dumplog_internal((void *)(long)cfs_curproc_pid());
225 static struct notifier_block libcfs_panic_notifier = {
226 notifier_call : panic_notifier,
231 void libcfs_register_panic_notifier(void)
233 #ifdef HAVE_ATOMIC_PANIC_NOTIFIER
234 atomic_notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
236 notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
240 void libcfs_unregister_panic_notifier(void)
242 #ifdef HAVE_ATOMIC_PANIC_NOTIFIER
243 atomic_notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
245 notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
249 EXPORT_SYMBOL(libcfs_debug_dumpstack);
250 EXPORT_SYMBOL(libcfs_current);
252 #endif /* __KERNEL__ */
254 EXPORT_SYMBOL(libcfs_run_upcall);
255 EXPORT_SYMBOL(libcfs_run_lbug_upcall);
256 EXPORT_SYMBOL(lbug_with_loc);