Commit | Line | Data |
---|---|---|
d7e09d03 PT |
1 | /* |
2 | * GPL HEADER START | |
3 | * | |
4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
5 | * | |
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. | |
9 | * | |
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). | |
15 | * | |
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 | |
19 | * | |
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 | |
22 | * have any questions. | |
23 | * | |
24 | * GPL HEADER END | |
25 | */ | |
26 | /* | |
27 | * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
30 | * Copyright (c) 2012, Intel Corporation. | |
31 | */ | |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | * | |
36 | * libcfs/libcfs/linux/linux-debug.c | |
37 | * | |
38 | * Author: Phil Schwan <phil@clusterfs.com> | |
39 | */ | |
40 | ||
41 | #include <linux/module.h> | |
42 | #include <linux/kmod.h> | |
43 | #include <linux/notifier.h> | |
44 | #include <linux/kernel.h> | |
45 | #include <linux/mm.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> | |
d7e09d03 | 51 | #include <linux/completion.h> |
d7e09d03 | 52 | #include <linux/fs.h> |
d7e09d03 PT |
53 | #include <asm/uaccess.h> |
54 | #include <linux/miscdevice.h> | |
d7e09d03 PT |
55 | |
56 | # define DEBUG_SUBSYSTEM S_LNET | |
57 | ||
9fdaf8c0 GKH |
58 | #include "../../../include/linux/libcfs/libcfs.h" |
59 | #include "../../../include/linux/libcfs/linux/portals_compat25.h" | |
d7e09d03 | 60 | |
da0e6a7a | 61 | #include "../tracefile.h" |
d7e09d03 PT |
62 | |
63 | #include <linux/kallsyms.h> | |
64 | ||
65 | char lnet_upcall[1024] = "/usr/lib/lustre/lnet_upcall"; | |
66 | char lnet_debug_log_upcall[1024] = "/usr/lib/lustre/lnet_debug_log_upcall"; | |
67 | ||
68 | /** | |
69 | * Upcall function once a Lustre log has been dumped. | |
70 | * | |
71 | * \param file path of the dumped log | |
72 | */ | |
73 | void libcfs_run_debug_log_upcall(char *file) | |
74 | { | |
75 | char *argv[3]; | |
76 | int rc; | |
77 | char *envp[] = { | |
78 | "HOME=/", | |
79 | "PATH=/sbin:/bin:/usr/sbin:/usr/bin", | |
80 | NULL}; | |
d7e09d03 PT |
81 | |
82 | argv[0] = lnet_debug_log_upcall; | |
83 | ||
84 | LASSERTF(file != NULL, "called on a null filename\n"); | |
995c8b4a | 85 | argv[1] = file; /* only need to pass the path of the file */ |
d7e09d03 PT |
86 | |
87 | argv[2] = NULL; | |
88 | ||
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]); | |
94 | } else { | |
95 | CDEBUG(D_HA, "Invoked LNET debug log upcall %s %s\n", | |
96 | argv[0], argv[1]); | |
97 | } | |
d7e09d03 PT |
98 | } |
99 | ||
100 | void libcfs_run_upcall(char **argv) | |
101 | { | |
102 | int rc; | |
103 | int argc; | |
104 | char *envp[] = { | |
105 | "HOME=/", | |
106 | "PATH=/sbin:/bin:/usr/sbin:/usr/bin", | |
107 | NULL}; | |
d7e09d03 PT |
108 | |
109 | argv[0] = lnet_upcall; | |
110 | argc = 1; | |
111 | while (argv[argc] != NULL) | |
112 | argc++; | |
113 | ||
114 | LASSERT(argc >= 2); | |
115 | ||
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 ? "" : ",..."); | |
125 | } else { | |
126 | CDEBUG(D_HA, "Invoked LNET upcall %s %s%s%s%s%s%s%s%s\n", | |
127 | argv[0], argv[1], | |
128 | argc < 3 ? "" : ",", argc < 3 ? "" : argv[2], | |
129 | argc < 4 ? "" : ",", argc < 4 ? "" : argv[3], | |
130 | argc < 5 ? "" : ",", argc < 5 ? "" : argv[4], | |
131 | argc < 6 ? "" : ",..."); | |
132 | } | |
133 | } | |
134 | ||
135 | void libcfs_run_lbug_upcall(struct libcfs_debug_msg_data *msgdata) | |
136 | { | |
137 | char *argv[6]; | |
138 | char buf[32]; | |
139 | ||
ec83e611 | 140 | snprintf(buf, sizeof(buf), "%d", msgdata->msg_line); |
d7e09d03 PT |
141 | |
142 | argv[1] = "LBUG"; | |
143 | argv[2] = (char *)msgdata->msg_file; | |
144 | argv[3] = (char *)msgdata->msg_fn; | |
145 | argv[4] = buf; | |
146 | argv[5] = NULL; | |
147 | ||
148 | libcfs_run_upcall (argv); | |
149 | } | |
150 | ||
151 | /* coverity[+kill] */ | |
152 | void lbug_with_loc(struct libcfs_debug_msg_data *msgdata) | |
153 | { | |
154 | libcfs_catastrophe = 1; | |
155 | libcfs_debug_msg(msgdata, "LBUG\n"); | |
156 | ||
157 | if (in_interrupt()) { | |
158 | panic("LBUG in interrupt.\n"); | |
159 | /* not reached */ | |
160 | } | |
161 | ||
5d4450c4 | 162 | dump_stack(); |
d7e09d03 PT |
163 | if (!libcfs_panic_on_lbug) |
164 | libcfs_debug_dumplog(); | |
165 | libcfs_run_lbug_upcall(msgdata); | |
166 | if (libcfs_panic_on_lbug) | |
167 | panic("LBUG"); | |
168 | set_task_state(current, TASK_UNINTERRUPTIBLE); | |
169 | while (1) | |
170 | schedule(); | |
171 | } | |
172 | ||
d7e09d03 PT |
173 | static int panic_notifier(struct notifier_block *self, unsigned long unused1, |
174 | void *unused2) | |
175 | { | |
176 | if (libcfs_panic_in_progress) | |
177 | return 0; | |
178 | ||
179 | libcfs_panic_in_progress = 1; | |
180 | mb(); | |
181 | ||
182 | return 0; | |
183 | } | |
184 | ||
185 | static struct notifier_block libcfs_panic_notifier = { | |
805e517a EG |
186 | .notifier_call = panic_notifier, |
187 | .next = NULL, | |
188 | .priority = 10000, | |
d7e09d03 PT |
189 | }; |
190 | ||
191 | void libcfs_register_panic_notifier(void) | |
192 | { | |
193 | atomic_notifier_chain_register(&panic_notifier_list, &libcfs_panic_notifier); | |
194 | } | |
195 | ||
196 | void libcfs_unregister_panic_notifier(void) | |
197 | { | |
198 | atomic_notifier_chain_unregister(&panic_notifier_list, &libcfs_panic_notifier); | |
199 | } | |
200 | ||
d7e09d03 PT |
201 | EXPORT_SYMBOL(libcfs_run_upcall); |
202 | EXPORT_SYMBOL(libcfs_run_lbug_upcall); | |
203 | EXPORT_SYMBOL(lbug_with_loc); |