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 <linux/miscdevice.h>
49 #include <linux/version.h>
51 # define DEBUG_SUBSYSTEM S_LNET
53 #include <libcfs/kp30.h>
54 #include <libcfs/linux/portals_compat25.h>
55 #include <libcfs/libcfs.h>
57 #include "tracefile.h"
59 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
60 #include <linux/kallsyms.h>
63 char lnet_upcall[1024] = "/usr/lib/lustre/lnet_upcall";
65 void libcfs_run_upcall(char **argv)
71 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
75 argv[0] = lnet_upcall;
77 while (argv[argc] != NULL)
82 rc = USERMODEHELPER(argv[0], argv, envp);
83 if (rc < 0 && rc != -ENOENT) {
84 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; "
85 "check /proc/sys/lnet/upcall\n",
87 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
88 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
89 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
90 argc < 6 ? "" : ",...");
92 CDEBUG(D_HA, "Invoked LNET upcall %s %s%s%s%s%s%s%s%s\n",
94 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
95 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
96 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
97 argc < 6 ? "" : ",...");
101 void libcfs_run_lbug_upcall(char *file, const char *fn, const int line)
107 snprintf (buf, sizeof buf, "%d", line);
111 argv[3] = (char *)fn;
115 libcfs_run_upcall (argv);
119 void lbug_with_loc(char *file, const char *func, const int line)
121 libcfs_catastrophe = 1;
122 libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line,
123 "LBUG - trying to dump log to %s\n", debug_file_path);
124 libcfs_debug_dumplog();
125 libcfs_run_lbug_upcall(file, func, line);
130 /* coverity[+kill] */
131 void lbug_with_loc(char *file, const char *func, const int line)
133 libcfs_catastrophe = 1;
134 libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line, "LBUG\n");
136 if (in_interrupt()) {
137 panic("LBUG in interrupt.\n");
141 libcfs_debug_dumpstack(NULL);
142 libcfs_debug_dumplog();
143 libcfs_run_lbug_upcall(file, func, line);
144 if (libcfs_panic_on_lbug)
146 set_task_state(current, TASK_UNINTERRUPTIBLE);
150 #endif /* __arch_um__ */
154 void libcfs_debug_dumpstack(struct task_struct *tsk)
156 #if defined(__arch_um__)
158 CWARN("stack dump for pid %d (%d) requested; wake up gdb.\n",
159 tsk->pid, UML_PID(tsk));
161 #elif defined(HAVE_SHOW_TASK)
162 /* this is exported by lustre kernel version 42 */
163 extern void show_task(struct task_struct *);
167 CWARN("showing stack for process %d\n", tsk->pid);
170 if ((tsk == NULL) || (tsk == current))
173 CWARN("can't show stack: kernel doesn't export show_task\n");
177 cfs_task_t *libcfs_current(void)
179 CWARN("current task struct is %p\n", current);
183 static int panic_notifier(struct notifier_block *self, unsigned long unused1,
186 if (libcfs_panic_in_progress)
189 libcfs_panic_in_progress = 1;
192 #ifdef LNET_DUMP_ON_PANIC
193 /* This is currently disabled because it spews far too much to the
194 * console on the rare cases it is ever triggered. */
196 if (in_interrupt()) {
199 while (current->lock_depth >= 0)
202 libcfs_debug_dumplog_internal((void *)(long)cfs_curproc_pid());
208 static struct notifier_block libcfs_panic_notifier = {
209 notifier_call : panic_notifier,
214 void libcfs_register_panic_notifier(void)
216 #ifdef HAVE_ATOMIC_PANIC_NOTIFIER
217 atomic_notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
219 notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier);
223 void libcfs_unregister_panic_notifier(void)
225 #ifdef HAVE_ATOMIC_PANIC_NOTIFIER
226 atomic_notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
228 notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier);
232 EXPORT_SYMBOL(libcfs_debug_dumpstack);
233 EXPORT_SYMBOL(libcfs_current);
235 #endif /* __KERNEL__ */
237 EXPORT_SYMBOL(libcfs_run_upcall);
238 EXPORT_SYMBOL(libcfs_run_lbug_upcall);
239 EXPORT_SYMBOL(lbug_with_loc);