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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
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>
41 #include <linux/module.h>
42 #include <linux/kmod.h>
43 #include <linux/notifier.h>
44 #include <linux/kernel.h>
46 #include <linux/string.h>
47 #include <linux/stat.h>
48 #include <linux/errno.h>
49 #include <linux/unistd.h>
50 #include <linux/interrupt.h>
51 #include <linux/completion.h>
53 #include <asm/uaccess.h>
54 #include <linux/miscdevice.h>
56 # define DEBUG_SUBSYSTEM S_LNET
58 #include "../../../include/linux/libcfs/libcfs.h"
59 #include "../../../include/linux/libcfs/linux/portals_compat25.h"
61 #include "../tracefile.h"
63 #include <linux/kallsyms.h>
65 char lnet_upcall
[1024] = "/usr/lib/lustre/lnet_upcall";
66 char lnet_debug_log_upcall
[1024] = "/usr/lib/lustre/lnet_debug_log_upcall";
69 * Upcall function once a Lustre log has been dumped.
71 * \param file path of the dumped log
73 void libcfs_run_debug_log_upcall(char *file
)
79 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
82 argv
[0] = lnet_debug_log_upcall
;
84 LASSERTF(file
!= NULL
, "called on a null filename\n");
85 argv
[1] = file
; //only need to pass the path of the file
89 rc
= USERMODEHELPER(argv
[0], argv
, envp
);
90 if (rc
< 0 && rc
!= -ENOENT
) {
91 CERROR("Error %d invoking LNET debug log upcall %s %s; "
92 "check /proc/sys/lnet/debug_log_upcall\n",
93 rc
, argv
[0], argv
[1]);
95 CDEBUG(D_HA
, "Invoked LNET debug log upcall %s %s\n",
100 void libcfs_run_upcall(char **argv
)
106 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
109 argv
[0] = lnet_upcall
;
111 while (argv
[argc
] != NULL
)
116 rc
= USERMODEHELPER(argv
[0], argv
, envp
);
117 if (rc
< 0 && rc
!= -ENOENT
) {
118 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; "
119 "check /proc/sys/lnet/upcall\n",
120 rc
, argv
[0], argv
[1],
121 argc
< 3 ? "" : ",", argc
< 3 ? "" : argv
[2],
122 argc
< 4 ? "" : ",", argc
< 4 ? "" : argv
[3],
123 argc
< 5 ? "" : ",", argc
< 5 ? "" : argv
[4],
124 argc
< 6 ? "" : ",...");
126 CDEBUG(D_HA
, "Invoked LNET upcall %s %s%s%s%s%s%s%s%s\n",
128 argc
< 3 ? "" : ",", argc
< 3 ? "" : argv
[2],
129 argc
< 4 ? "" : ",", argc
< 4 ? "" : argv
[3],
130 argc
< 5 ? "" : ",", argc
< 5 ? "" : argv
[4],
131 argc
< 6 ? "" : ",...");
135 void libcfs_run_lbug_upcall(struct libcfs_debug_msg_data
*msgdata
)
140 snprintf(buf
, sizeof(buf
), "%d", msgdata
->msg_line
);
143 argv
[2] = (char *)msgdata
->msg_file
;
144 argv
[3] = (char *)msgdata
->msg_fn
;
148 libcfs_run_upcall (argv
);
151 /* coverity[+kill] */
152 void lbug_with_loc(struct libcfs_debug_msg_data
*msgdata
)
154 libcfs_catastrophe
= 1;
155 libcfs_debug_msg(msgdata
, "LBUG\n");
157 if (in_interrupt()) {
158 panic("LBUG in interrupt.\n");
163 if (!libcfs_panic_on_lbug
)
164 libcfs_debug_dumplog();
165 libcfs_run_lbug_upcall(msgdata
);
166 if (libcfs_panic_on_lbug
)
168 set_task_state(current
, TASK_UNINTERRUPTIBLE
);
173 static int panic_notifier(struct notifier_block
*self
, unsigned long unused1
,
176 if (libcfs_panic_in_progress
)
179 libcfs_panic_in_progress
= 1;
185 static struct notifier_block libcfs_panic_notifier
= {
186 .notifier_call
= panic_notifier
,
191 void libcfs_register_panic_notifier(void)
193 atomic_notifier_chain_register(&panic_notifier_list
, &libcfs_panic_notifier
);
196 void libcfs_unregister_panic_notifier(void)
198 atomic_notifier_chain_unregister(&panic_notifier_list
, &libcfs_panic_notifier
);
201 EXPORT_SYMBOL(libcfs_run_upcall
);
202 EXPORT_SYMBOL(libcfs_run_lbug_upcall
);
203 EXPORT_SYMBOL(lbug_with_loc
);