1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
5 * Author: Phil Schwan <phil@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 # define EXPORT_SYMTAB
27 #ifndef AUTOCONF_INCLUDED
28 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/kmod.h>
32 #include <linux/notifier.h>
33 #include <linux/kernel.h>
35 #include <linux/string.h>
36 #include <linux/stat.h>
37 #include <linux/errno.h>
38 #include <linux/smp_lock.h>
39 #include <linux/unistd.h>
40 #include <linux/interrupt.h>
41 #include <asm/system.h>
42 #include <asm/uaccess.h>
43 #include <linux/completion.h>
46 #include <linux/stat.h>
47 #include <asm/uaccess.h>
49 # include <asm/segment.h>
51 #include <linux/miscdevice.h>
52 #include <linux/version.h>
54 # define DEBUG_SUBSYSTEM S_LNET
56 #include <libcfs/kp30.h>
57 #include <libcfs/linux/portals_compat25.h>
58 #include <libcfs/libcfs.h>
60 #include "tracefile.h"
62 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
63 #include <linux/kallsyms.h>
66 char lnet_upcall[1024] = "/usr/lib/lustre/lnet_upcall";
68 void libcfs_run_upcall(char **argv)
74 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
78 argv[0] = lnet_upcall;
80 while (argv[argc] != NULL)
85 rc = USERMODEHELPER(argv[0], argv, envp);
86 if (rc < 0 && rc != -ENOENT) {
87 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; "
88 "check /proc/sys/lnet/upcall\n",
90 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
91 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
92 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
93 argc < 6 ? "" : ",...");
95 CDEBUG(D_HA, "Invoked LNET upcall %s %s%s%s%s%s%s%s%s\n",
97 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
98 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
99 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
100 argc < 6 ? "" : ",...");
104 void libcfs_run_lbug_upcall(char *file, const char *fn, const int line)
110 snprintf (buf, sizeof buf, "%d", line);
114 argv[3] = (char *)fn;
118 libcfs_run_upcall (argv);
122 void lbug_with_loc(char *file, const char *func, const int line)
124 libcfs_catastrophe = 1;
125 libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line,
126 "LBUG - trying to dump log to %s\n", debug_file_path);
127 libcfs_debug_dumplog();
128 libcfs_run_lbug_upcall(file, func, line);
133 /* coverity[+kill] */
134 void lbug_with_loc(char *file, const char *func, const int line)
136 libcfs_catastrophe = 1;
137 libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line, "LBUG\n");
139 if (in_interrupt()) {
140 panic("LBUG in interrupt.\n");
144 libcfs_debug_dumpstack(NULL);
145 libcfs_debug_dumplog();
146 libcfs_run_lbug_upcall(file, func, line);
147 if (libcfs_panic_on_lbug)
149 set_task_state(current, TASK_UNINTERRUPTIBLE);
153 #endif /* __arch_um__ */
157 void libcfs_debug_dumpstack(struct task_struct *tsk)
159 #if defined(__arch_um__)
161 CWARN("stack dump for pid %d (%d) requested; wake up gdb.\n",
162 tsk->pid, UML_PID(tsk));
164 #elif defined(HAVE_SHOW_TASK)
165 /* this is exported by lustre kernel version 42 */
166 extern void show_task(struct task_struct *);
170 CWARN("showing stack for process %d\n", tsk->pid);
173 if ((tsk == NULL) || (tsk == current))
176 CWARN("can't show stack: kernel doesn't export show_task\n");
180 cfs_task_t *libcfs_current(void)
182 CWARN("current task struct is %p\n", current);
186 static int panic_notifier(struct notifier_block *self, unsigned long unused1,
189 if (libcfs_panic_in_progress)
192 libcfs_panic_in_progress = 1;
195 #ifdef LNET_DUMP_ON_PANIC
196 /* This is currently disabled because it spews far too much to the
197 * console on the rare cases it is ever triggered. */
199 if (in_interrupt()) {
202 while (current->lock_depth >= 0)
205 libcfs_debug_dumplog_internal((void *)(long)cfs_curproc_pid());
211 static struct notifier_block libcfs_panic_notifier = {
212 notifier_call : panic_notifier,
217 void libcfs_register_panic_notifier(void)
219 #ifdef HAVE_ATOMIC_PANIC_NOTIFIER
220 atomic_notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
222 notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
226 void libcfs_unregister_panic_notifier(void)
228 #ifdef HAVE_ATOMIC_PANIC_NOTIFIER
229 atomic_notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
231 notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
235 EXPORT_SYMBOL(libcfs_debug_dumpstack);
236 EXPORT_SYMBOL(libcfs_current);
238 #endif /* __KERNEL__ */
240 EXPORT_SYMBOL(libcfs_run_upcall);
241 EXPORT_SYMBOL(libcfs_run_lbug_upcall);
242 EXPORT_SYMBOL(lbug_with_loc);