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 # define DEBUG_SUBSYSTEM S_PORTALS
29 #include <libcfs/kp30.h>
30 #include <libcfs/libcfs.h>
32 #include "tracefile.h"
34 unsigned int portal_subsystem_debug = ~0 - (S_PORTALS);
35 EXPORT_SYMBOL(portal_subsystem_debug);
37 unsigned int portal_debug = (D_WARNING | D_DLMTRACE | D_ERROR | D_EMERG | D_HA |
38 D_RPCTRACE | D_VFSTRACE | D_CONFIG | D_IOCTL |
40 EXPORT_SYMBOL(portal_debug);
42 unsigned int portal_printk;
43 EXPORT_SYMBOL(portal_printk);
45 unsigned int portal_stack;
46 EXPORT_SYMBOL(portal_stack);
48 unsigned int portals_catastrophe;
49 EXPORT_SYMBOL(portals_catastrophe);
52 atomic_t portal_kmemory = ATOMIC_INIT(0);
53 EXPORT_SYMBOL(portal_kmemory);
56 static cfs_waitq_t debug_ctlwq;
58 char debug_file_path[1024] = "/tmp/lustre-log";
59 static char debug_file_name[1024];
61 void portals_debug_dumplog_internal(void *arg)
63 CFS_DECL_JOURNAL_DATA;
67 snprintf(debug_file_name, sizeof(debug_file_path) - 1,
68 "%s.%ld.%ld", debug_file_path, cfs_time_current_sec(), (long)arg);
69 printk(KERN_ALERT "LustreError: dumping log to %s\n", debug_file_name);
70 tracefile_dump_all_pages(debug_file_name);
75 int portals_debug_dumplog_thread(void *arg)
77 kportal_daemonize("");
79 portals_debug_dumplog_internal(arg);
80 cfs_waitq_signal(&debug_ctlwq);
84 void portals_debug_dumplog(void)
90 /* we're being careful to ensure that the kernel thread is
91 * able to set our state to running as it exits before we
92 * get to schedule() */
93 cfs_waitlink_init(&wait);
94 set_current_state(TASK_INTERRUPTIBLE);
95 cfs_waitq_add(&debug_ctlwq, &wait);
97 rc = cfs_kernel_thread(portals_debug_dumplog_thread,
98 (void *)(long)cfs_curproc_pid(),
99 CLONE_VM | CLONE_FS | CLONE_FILES);
101 printk(KERN_ERR "LustreError: cannot start log dump thread: "
106 /* be sure to teardown if kernel_thread() failed */
107 cfs_waitq_del(&debug_ctlwq, &wait);
108 set_current_state(TASK_RUNNING);
111 #ifdef PORTALS_DUMP_ON_PANIC
112 static int panic_dumplog(struct notifier_block *self, unsigned long unused1,
115 static int handled_panic; /* to avoid recursive calls to notifiers */
122 if (in_interrupt()) {
127 while (current->lock_depth >= 0)
129 portals_debug_dumplog();
133 static struct notifier_block lustre_panic_notifier = {
134 notifier_call : panic_dumplog,
141 extern void *lus_portals_debug;
144 int portals_debug_init(unsigned long bufsize)
146 cfs_waitq_init(&debug_ctlwq);
148 lus_portals_debug = &portals_debug_msg;
150 #ifdef PORTALS_DUMP_ON_PANIC
151 /* This is currently disabled because it spews far too much to the
152 * console on the rare cases it is ever triggered. */
153 notifier_chain_register(&panic_notifier_list, &lustre_panic_notifier);
155 return tracefile_init();
158 int portals_debug_cleanup(void)
161 #ifdef PORTALS_DUMP_ON_PANIC
162 notifier_chain_unregister(&panic_notifier_list, &lustre_panic_notifier);
165 lus_portals_debug = NULL;
170 int portals_debug_clear_buffer(void)
176 /* Debug markers, although printed by S_PORTALS
177 * should not be be marked as such. */
178 #undef DEBUG_SUBSYSTEM
179 #define DEBUG_SUBSYSTEM S_UNDEFINED
180 int portals_debug_mark_buffer(char *text)
182 CDEBUG(D_TRACE,"***************************************************\n");
183 CDEBUG(D_WARNING, "DEBUG MARKER: %s\n", text);
184 CDEBUG(D_TRACE,"***************************************************\n");
188 #undef DEBUG_SUBSYSTEM
189 #define DEBUG_SUBSYSTEM S_PORTALS
191 void portals_debug_set_level(unsigned int debug_level)
193 printk(KERN_WARNING "Lustre: Setting portals debug level to %08x\n",
195 portal_debug = debug_level;
198 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
200 if (nid == PTL_NID_ANY) {
201 snprintf(str, PTL_NALFMT_SIZE, "%s", "PTL_NID_ANY");
205 switch(NALID_FROM_IFACE(nal)){
206 /* XXX this could be a nal method of some sort, 'cept it's config
207 * dependent whether (say) socknal NIDs are actually IP addresses... */
216 /* HIPQUAD requires __u32, but we can't cast in it */
217 __u32 nid32 = (__u32)nid;
218 if ((__u32)(nid >> 32)) {
219 snprintf(str, PTL_NALFMT_SIZE, "%u:%u.%u.%u.%u",
220 (__u32)(nid >> 32), HIPQUAD(nid32));
222 snprintf(str, PTL_NALFMT_SIZE, "%u.%u.%u.%u",
230 snprintf(str, PTL_NALFMT_SIZE, "%u:%u",
231 (__u32)(nid >> 32), (__u32)nid);
235 case PTL_IFACE_SS_ACCEL:
236 snprintf(str, PTL_NALFMT_SIZE, "%u", (__u32)nid);
240 snprintf(str, PTL_NALFMT_SIZE, "?%x? %llx",
241 nal, (long long)nid);
247 char *portals_id2str(int nal, ptl_process_id_t id, char *str)
251 portals_nid2str(nal, id.nid, str);
253 snprintf(str + len, PTL_NALFMT_SIZE - len, "-%u", id.pid);
257 EXPORT_SYMBOL(portals_debug_dumplog);
258 EXPORT_SYMBOL(portals_debug_set_level);
259 EXPORT_SYMBOL(portals_nid2str);
260 EXPORT_SYMBOL(portals_id2str);