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 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/kmod.h>
30 #include <linux/notifier.h>
31 #include <linux/kernel.h>
33 #include <linux/string.h>
34 #include <linux/stat.h>
35 #include <linux/errno.h>
36 #include <linux/smp_lock.h>
37 #include <linux/unistd.h>
38 #include <linux/interrupt.h>
39 #include <asm/system.h>
40 #include <asm/uaccess.h>
41 #include <linux/completion.h>
44 #include <linux/stat.h>
45 #include <asm/uaccess.h>
46 #include <asm/segment.h>
47 #include <linux/miscdevice.h>
48 #include <linux/version.h>
50 # define DEBUG_SUBSYSTEM S_PORTALS
52 #include <linux/kp30.h>
53 #include <linux/portals_compat25.h>
54 #include <linux/libcfs.h>
56 #include "tracefile.h"
58 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
59 #include <linux/kallsyms.h>
62 unsigned int portal_subsystem_debug = ~0 - (S_PORTALS | S_NAL);
63 EXPORT_SYMBOL(portal_subsystem_debug);
65 unsigned int portal_debug = (D_WARNING | D_DLMTRACE | D_ERROR | D_EMERG | D_HA |
66 D_RPCTRACE | D_VFSTRACE);
67 EXPORT_SYMBOL(portal_debug);
69 unsigned int portal_printk;
70 EXPORT_SYMBOL(portal_printk);
72 unsigned int portal_stack;
73 EXPORT_SYMBOL(portal_stack);
76 atomic_t portal_kmemory = ATOMIC_INIT(0);
77 EXPORT_SYMBOL(portal_kmemory);
80 static DECLARE_WAIT_QUEUE_HEAD(debug_ctlwq);
82 char debug_file_path[1024] = "/tmp/lustre-log";
83 static char debug_file_name[1024];
84 char portals_upcall[1024] = "/usr/lib/lustre/portals_upcall";
86 void portals_debug_dumplog_internal(void *arg)
88 void *journal_info = current->journal_info;
89 current->journal_info = NULL;
91 snprintf(debug_file_name, sizeof(debug_file_path) - 1,
92 "%s.%ld.%ld", debug_file_path, CURRENT_SECONDS, (long)arg);
93 printk(KERN_ALERT "LustreError: dumping log to %s\n", debug_file_name);
94 tracefile_dump_all_pages(debug_file_name);
96 current->journal_info = journal_info;
99 int portals_debug_dumplog_thread(void *arg)
101 kportal_daemonize("");
103 portals_debug_dumplog_internal(arg);
104 wake_up(&debug_ctlwq);
108 void portals_debug_dumplog(void)
111 DECLARE_WAITQUEUE(wait, current);
114 /* we're being careful to ensure that the kernel thread is
115 * able to set our state to running as it exits before we
116 * get to schedule() */
117 set_current_state(TASK_INTERRUPTIBLE);
118 add_wait_queue(&debug_ctlwq, &wait);
120 rc = kernel_thread(portals_debug_dumplog_thread,
121 (void *)(long)current->pid,
122 CLONE_VM | CLONE_FS | CLONE_FILES);
124 printk(KERN_ERR "LustreError: cannot start log dump thread: "
129 /* be sure to teardown if kernel_thread() failed */
130 remove_wait_queue(&debug_ctlwq, &wait);
131 set_current_state(TASK_RUNNING);
134 #ifdef PORTALS_DUMP_ON_PANIC
135 static int panic_dumplog(struct notifier_block *self, unsigned long unused1,
138 static int handled_panic; /* to avoid recursive calls to notifiers */
145 if (in_interrupt()) {
150 while (current->lock_depth >= 0)
152 portals_debug_dumplog();
156 static struct notifier_block lustre_panic_notifier = {
157 notifier_call : panic_dumplog,
164 extern void *lus_portals_debug;
167 int portals_debug_init(unsigned long bufsize)
170 lus_portals_debug = &portals_debug_msg;
172 #ifdef PORTALS_DUMP_ON_PANIC
173 /* This is currently disabled because it spews far too much to the
174 * console on the rare cases it is ever triggered. */
175 notifier_chain_register(&panic_notifier_list, &lustre_panic_notifier);
177 return tracefile_init();
180 int portals_debug_cleanup(void)
183 #ifdef PORTALS_DUMP_ON_PANIC
184 notifier_chain_unregister(&panic_notifier_list, &lustre_panic_notifier);
187 lus_portals_debug = NULL;
192 int portals_debug_clear_buffer(void)
198 /* Debug markers, although printed by S_PORTALS
199 * should not be be marked as such. */
200 #undef DEBUG_SUBSYSTEM
201 #define DEBUG_SUBSYSTEM S_UNDEFINED
202 int portals_debug_mark_buffer(char *text)
204 CDEBUG(D_TRACE,"***************************************************\n");
205 CDEBUG(D_WARNING, "DEBUG MARKER: %s\n", text);
206 CDEBUG(D_TRACE,"***************************************************\n");
210 #undef DEBUG_SUBSYSTEM
211 #define DEBUG_SUBSYSTEM S_PORTALS
213 void portals_debug_set_level(unsigned int debug_level)
215 printk(KERN_WARNING "Lustre: Setting portals debug level to %08x\n",
217 portal_debug = debug_level;
220 void portals_run_upcall(char **argv)
226 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
230 argv[0] = portals_upcall;
232 while (argv[argc] != NULL)
237 rc = USERMODEHELPER(argv[0], argv, envp);
239 CERROR("Error %d invoking portals upcall %s %s%s%s%s%s%s%s%s; "
240 "check /proc/sys/portals/upcall\n",
241 rc, argv[0], argv[1],
242 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
243 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
244 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
245 argc < 6 ? "" : ",...");
247 CERROR("Invoked portals upcall %s %s%s%s%s%s%s%s%s\n",
249 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
250 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
251 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
252 argc < 6 ? "" : ",...");
256 void portals_run_lbug_upcall(char *file, const char *fn, const int line)
262 snprintf (buf, sizeof buf, "%d", line);
266 argv[3] = (char *)fn;
270 portals_run_upcall (argv);
273 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
275 if (nid == PTL_NID_ANY) {
276 snprintf(str, PTL_NALFMT_SIZE, "%s", "PTL_NID_ANY");
281 /* XXX this could be a nal method of some sort, 'cept it's config
282 * dependent whether (say) socknal NIDs are actually IP addresses... */
291 snprintf(str, PTL_NALFMT_SIZE, "%u:%u.%u.%u.%u",
292 (__u32)(nid >> 32), HIPQUAD(nid));
297 snprintf(str, PTL_NALFMT_SIZE, "%u:%u",
298 (__u32)(nid >> 32), (__u32)nid);
302 snprintf(str, PTL_NALFMT_SIZE, "?%x? %llx",
303 nal, (long long)nid);
309 char *portals_id2str(int nal, ptl_process_id_t id, char *str)
313 portals_nid2str(nal, id.nid, str);
315 snprintf(str + len, PTL_NALFMT_SIZE - len, "-%u", id.pid);
321 void portals_debug_dumpstack(struct task_struct *tsk)
323 #if defined(__arch_um__)
325 CWARN("stack dump for pid %d (%d) requested; wake up gdb.\n",
326 tsk->pid, UML_PID(tsk));
328 #elif defined(HAVE_SHOW_TASK)
329 /* this is exported by lustre kernel version 42 */
330 extern void show_task(struct task_struct *);
334 CWARN("showing stack for process %d\n", tsk->pid);
337 CWARN("can't show stack: kernel doesn't export show_task\n");
341 struct task_struct *portals_current(void)
343 CWARN("current task struct is %p\n", current);
347 EXPORT_SYMBOL(portals_debug_dumpstack);
348 EXPORT_SYMBOL(portals_current);
349 #endif /* __KERNEL__ */
351 EXPORT_SYMBOL(portals_debug_dumplog);
352 EXPORT_SYMBOL(portals_debug_set_level);
353 EXPORT_SYMBOL(portals_run_upcall);
354 EXPORT_SYMBOL(portals_run_lbug_upcall);
355 EXPORT_SYMBOL(portals_nid2str);
356 EXPORT_SYMBOL(portals_id2str);