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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * libcfs/libcfs/linux/linux-debug.c
34 * Author: Phil Schwan <phil@clusterfs.com>
37 #include <linux/module.h>
38 #include <linux/kmod.h>
39 #include <linux/notifier.h>
40 #include <linux/kernel.h>
42 #include <linux/string.h>
43 #include <linux/stat.h>
44 #include <linux/errno.h>
45 #include <linux/unistd.h>
46 #include <linux/interrupt.h>
47 #include <linux/completion.h>
49 #include <linux/uaccess.h>
50 #include <linux/miscdevice.h>
52 # define DEBUG_SUBSYSTEM S_LNET
54 #include "../../../include/linux/libcfs/libcfs.h"
56 #include "../tracefile.h"
58 #include <linux/kallsyms.h>
60 char lnet_upcall[1024] = "/usr/lib/lustre/lnet_upcall";
61 char lnet_debug_log_upcall[1024] = "/usr/lib/lustre/lnet_debug_log_upcall";
64 * Upcall function once a Lustre log has been dumped.
66 * \param file path of the dumped log
68 void libcfs_run_debug_log_upcall(char *file)
74 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
77 argv[0] = lnet_debug_log_upcall;
79 LASSERTF(file, "called on a null filename\n");
80 argv[1] = file; /* only need to pass the path of the file */
84 rc = call_usermodehelper(argv[0], argv, envp, 1);
85 if (rc < 0 && rc != -ENOENT) {
86 CERROR("Error %d invoking LNET debug log upcall %s %s; check /sys/kernel/debug/lnet/debug_log_upcall\n",
87 rc, argv[0], argv[1]);
89 CDEBUG(D_HA, "Invoked LNET debug log upcall %s %s\n",
94 void libcfs_run_upcall(char **argv)
100 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
103 argv[0] = lnet_upcall;
110 rc = call_usermodehelper(argv[0], argv, envp, 1);
111 if (rc < 0 && rc != -ENOENT) {
112 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; check /sys/kernel/debug/lnet/upcall\n",
113 rc, argv[0], argv[1],
114 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
115 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
116 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
117 argc < 6 ? "" : ",...");
119 CDEBUG(D_HA, "Invoked LNET upcall %s %s%s%s%s%s%s%s%s\n",
121 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
122 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
123 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
124 argc < 6 ? "" : ",...");
128 void libcfs_run_lbug_upcall(struct libcfs_debug_msg_data *msgdata)
133 snprintf(buf, sizeof(buf), "%d", msgdata->msg_line);
136 argv[2] = (char *)msgdata->msg_file;
137 argv[3] = (char *)msgdata->msg_fn;
141 libcfs_run_upcall(argv);
143 EXPORT_SYMBOL(libcfs_run_lbug_upcall);
145 /* coverity[+kill] */
146 void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msgdata)
148 libcfs_catastrophe = 1;
149 libcfs_debug_msg(msgdata, "LBUG\n");
151 if (in_interrupt()) {
152 panic("LBUG in interrupt.\n");
157 if (!libcfs_panic_on_lbug)
158 libcfs_debug_dumplog();
159 libcfs_run_lbug_upcall(msgdata);
160 if (libcfs_panic_on_lbug)
162 set_task_state(current, TASK_UNINTERRUPTIBLE);
166 EXPORT_SYMBOL(lbug_with_loc);
168 static int panic_notifier(struct notifier_block *self, unsigned long unused1,
171 if (libcfs_panic_in_progress)
174 libcfs_panic_in_progress = 1;
180 static struct notifier_block libcfs_panic_notifier = {
181 .notifier_call = panic_notifier,
186 void libcfs_register_panic_notifier(void)
188 atomic_notifier_chain_register(&panic_notifier_list,
189 &libcfs_panic_notifier);
192 void libcfs_unregister_panic_notifier(void)
194 atomic_notifier_chain_unregister(&panic_notifier_list,
195 &libcfs_panic_notifier);