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>
48 #include <asm/segment.h>
49 #include <linux/miscdevice.h>
50 #include <linux/version.h>
52 # define DEBUG_SUBSYSTEM S_LNET
54 #include <libcfs/kp30.h>
55 #include <libcfs/linux/portals_compat25.h>
56 #include <libcfs/libcfs.h>
58 #include "tracefile.h"
60 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
61 #include <linux/kallsyms.h>
64 char lnet_upcall[1024] = "/usr/lib/lustre/lnet_upcall";
66 void libcfs_run_upcall(char **argv)
72 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
76 argv[0] = lnet_upcall;
78 while (argv[argc] != NULL)
83 rc = USERMODEHELPER(argv[0], argv, envp);
84 if (rc < 0 && rc != -ENOENT) {
85 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; "
86 "check /proc/sys/lnet/upcall\n",
88 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
89 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
90 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
91 argc < 6 ? "" : ",...");
93 CDEBUG(D_HA, "Invoked LNET upcall %s %s%s%s%s%s%s%s%s\n",
95 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
96 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
97 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
98 argc < 6 ? "" : ",...");
102 void libcfs_run_lbug_upcall(char *file, const char *fn, const int line)
108 snprintf (buf, sizeof buf, "%d", line);
112 argv[3] = (char *)fn;
116 libcfs_run_upcall (argv);
120 void lbug_with_loc(char *file, const char *func, const int line)
122 libcfs_catastrophe = 1;
123 libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line,
124 "LBUG - trying to dump log to %s\n", debug_file_path);
125 libcfs_debug_dumplog();
126 libcfs_run_lbug_upcall(file, func, line);
131 /* coverity[+kill] */
132 void lbug_with_loc(char *file, const char *func, const int line)
134 libcfs_catastrophe = 1;
135 libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line, "LBUG\n");
137 if (in_interrupt()) {
138 panic("LBUG in interrupt.\n");
142 libcfs_debug_dumpstack(NULL);
143 libcfs_debug_dumplog();
144 libcfs_run_lbug_upcall(file, func, line);
145 if (libcfs_panic_on_lbug)
147 set_task_state(current, TASK_UNINTERRUPTIBLE);
151 #endif /* __arch_um__ */
155 void libcfs_debug_dumpstack(struct task_struct *tsk)
157 #if defined(__arch_um__)
159 CWARN("stack dump for pid %d (%d) requested; wake up gdb.\n",
160 tsk->pid, UML_PID(tsk));
162 #elif defined(HAVE_SHOW_TASK)
163 /* this is exported by lustre kernel version 42 */
164 extern void show_task(struct task_struct *);
168 CWARN("showing stack for process %d\n", tsk->pid);
171 if ((tsk == NULL) || (tsk == current))
174 CWARN("can't show stack: kernel doesn't export show_task\n");
178 cfs_task_t *libcfs_current(void)
180 CWARN("current task struct is %p\n", current);
184 static int panic_notifier(struct notifier_block *self, unsigned long unused1,
187 if (libcfs_panic_in_progress)
190 libcfs_panic_in_progress = 1;
193 #ifdef LNET_DUMP_ON_PANIC
194 /* This is currently disabled because it spews far too much to the
195 * console on the rare cases it is ever triggered. */
197 if (in_interrupt()) {
200 while (current->lock_depth >= 0)
203 libcfs_debug_dumplog_internal((void *)(long)cfs_curproc_pid());
209 static struct notifier_block libcfs_panic_notifier = {
210 notifier_call : panic_notifier,
215 void libcfs_register_panic_notifier(void)
217 #ifdef HAVE_ATOMIC_PANIC_NOTIFIER
218 atomic_notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
220 notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
224 void libcfs_unregister_panic_notifier(void)
226 #ifdef HAVE_ATOMIC_PANIC_NOTIFIER
227 atomic_notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
229 notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
233 EXPORT_SYMBOL(libcfs_debug_dumpstack);
234 EXPORT_SYMBOL(libcfs_current);
236 #endif /* __KERNEL__ */
238 EXPORT_SYMBOL(libcfs_run_upcall);
239 EXPORT_SYMBOL(libcfs_run_lbug_upcall);
240 EXPORT_SYMBOL(lbug_with_loc);