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 static int handled_panic; /* to avoid recursive calls to notifiers */
85 char portals_upcall[1024] = "/usr/lib/lustre/portals_upcall";
87 void portals_debug_dumplog_internal(void *arg)
89 void *journal_info = current->journal_info;
90 current->journal_info = NULL;
92 snprintf(debug_file_name, sizeof(debug_file_path) - 1,
93 "%s.%ld.%ld", debug_file_path, CURRENT_SECONDS, (long)arg);
94 printk(KERN_ALERT "LustreError: dumping log to %s\n", debug_file_name);
95 tracefile_dump_all_pages(debug_file_name);
97 current->journal_info = journal_info;
100 int portals_debug_dumplog_thread(void *arg)
102 kportal_daemonize("");
104 portals_debug_dumplog_internal(arg);
105 wake_up(&debug_ctlwq);
109 void portals_debug_dumplog(void)
112 DECLARE_WAITQUEUE(wait, current);
115 /* we're being careful to ensure that the kernel thread is
116 * able to set our state to running as it exits before we
117 * get to schedule() */
118 set_current_state(TASK_INTERRUPTIBLE);
119 add_wait_queue(&debug_ctlwq, &wait);
121 rc = kernel_thread(portals_debug_dumplog_thread,
122 (void *)(long)current->pid,
123 CLONE_VM | CLONE_FS | CLONE_FILES);
125 printk(KERN_ERR "LustreError: cannot start log dump thread: "
130 /* be sure to teardown if kernel_thread() failed */
131 remove_wait_queue(&debug_ctlwq, &wait);
132 set_current_state(TASK_RUNNING);
135 static int panic_dumplog(struct notifier_block *self, unsigned long unused1,
143 if (in_interrupt()) {
148 while (current->lock_depth >= 0)
150 portals_debug_dumplog();
154 static struct notifier_block lustre_panic_notifier = {
155 notifier_call : panic_dumplog,
160 int portals_debug_init(unsigned long bufsize)
162 notifier_chain_register(&panic_notifier_list, &lustre_panic_notifier);
163 return tracefile_init();
166 int portals_debug_cleanup(void)
169 notifier_chain_unregister(&panic_notifier_list, &lustre_panic_notifier);
173 int portals_debug_clear_buffer(void)
179 /* Debug markers, although printed by S_PORTALS
180 * should not be be marked as such. */
181 #undef DEBUG_SUBSYSTEM
182 #define DEBUG_SUBSYSTEM S_UNDEFINED
183 int portals_debug_mark_buffer(char *text)
185 CDEBUG(D_TRACE,"***************************************************\n");
186 CDEBUG(D_WARNING, "DEBUG MARKER: %s\n", text);
187 CDEBUG(D_TRACE,"***************************************************\n");
191 #undef DEBUG_SUBSYSTEM
192 #define DEBUG_SUBSYSTEM S_PORTALS
194 void portals_debug_set_level(unsigned int debug_level)
196 printk(KERN_WARNING "Lustre: Setting portals debug level to %08x\n",
198 portal_debug = debug_level;
201 void portals_run_upcall(char **argv)
207 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
211 argv[0] = portals_upcall;
213 while (argv[argc] != NULL)
218 rc = USERMODEHELPER(argv[0], argv, envp);
220 CERROR("Error %d invoking portals upcall %s %s%s%s%s%s%s%s%s; "
221 "check /proc/sys/portals/upcall\n",
222 rc, argv[0], argv[1],
223 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
224 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
225 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
226 argc < 6 ? "" : ",...");
228 CERROR("Invoked portals upcall %s %s%s%s%s%s%s%s%s\n",
230 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
231 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
232 argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
233 argc < 6 ? "" : ",...");
237 void portals_run_lbug_upcall(char *file, const char *fn, const int line)
243 snprintf (buf, sizeof buf, "%d", line);
247 argv[3] = (char *)fn;
251 portals_run_upcall (argv);
254 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
256 if (nid == PTL_NID_ANY) {
257 snprintf(str, PTL_NALFMT_SIZE, "%s", "PTL_NID_ANY");
262 /* XXX this could be a nal method of some sort, 'cept it's config
263 * dependent whether (say) socknal NIDs are actually IP addresses... */
271 snprintf(str, PTL_NALFMT_SIZE, "%u:%u.%u.%u.%u",
272 (__u32)(nid >> 32), HIPQUAD(nid));
277 snprintf(str, PTL_NALFMT_SIZE, "%u:%u",
278 (__u32)(nid >> 32), (__u32)nid);
282 snprintf(str, PTL_NALFMT_SIZE, "?%x? %llx",
283 nal, (long long)nid);
289 char *portals_id2str(int nal, ptl_process_id_t id, char *str)
293 portals_nid2str(nal, id.nid, str);
295 snprintf(str + len, PTL_NALFMT_SIZE - len, "-%u", id.pid);
301 void portals_debug_dumpstack(struct task_struct *tsk)
303 #if defined(__arch_um__)
305 CWARN("stack dump for pid %d (%d) requested; wake up gdb.\n",
306 tsk->pid, UML_PID(tsk));
308 #elif defined(HAVE_SHOW_TASK)
309 /* this is exported by lustre kernel version 42 */
310 extern void show_task(struct task_struct *);
314 CWARN("showing stack for process %d\n", tsk->pid);
317 CWARN("can't show stack: kernel doesn't export show_task\n");
321 struct task_struct *portals_current(void)
323 CWARN("current task struct is %p\n", current);
327 EXPORT_SYMBOL(portals_debug_dumpstack);
328 EXPORT_SYMBOL(portals_current);
329 #endif /* __KERNEL__ */
331 EXPORT_SYMBOL(portals_debug_dumplog);
332 EXPORT_SYMBOL(portals_debug_set_level);
333 EXPORT_SYMBOL(portals_run_upcall);
334 EXPORT_SYMBOL(portals_run_lbug_upcall);
335 EXPORT_SYMBOL(portals_nid2str);
336 EXPORT_SYMBOL(portals_id2str);