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 | S_NAL);
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);
49 atomic_t portal_kmemory = ATOMIC_INIT(0);
50 EXPORT_SYMBOL(portal_kmemory);
53 static cfs_waitq_t debug_ctlwq;
55 char debug_file_path[1024] = "/tmp/lustre-log";
56 static char debug_file_name[1024];
58 void portals_debug_dumplog_internal(void *arg)
60 CFS_DECL_JOURNAL_DATA;
64 snprintf(debug_file_name, sizeof(debug_file_path) - 1,
65 "%s.%ld.%ld", debug_file_path, cfs_time_current_sec(), (long)arg);
66 printk(KERN_ALERT "LustreError: dumping log to %s\n", debug_file_name);
67 tracefile_dump_all_pages(debug_file_name);
72 int portals_debug_dumplog_thread(void *arg)
74 kportal_daemonize("");
76 portals_debug_dumplog_internal(arg);
77 cfs_waitq_signal(&debug_ctlwq);
81 void portals_debug_dumplog(void)
87 /* we're being careful to ensure that the kernel thread is
88 * able to set our state to running as it exits before we
89 * get to schedule() */
90 cfs_waitlink_init(&wait);
91 set_current_state(TASK_INTERRUPTIBLE);
92 cfs_waitq_add(&debug_ctlwq, &wait);
94 rc = cfs_kernel_thread(portals_debug_dumplog_thread,
95 (void *)(long)cfs_curproc_pid(),
96 CLONE_VM | CLONE_FS | CLONE_FILES);
98 printk(KERN_ERR "LustreError: cannot start log dump thread: "
103 /* be sure to teardown if kernel_thread() failed */
104 cfs_waitq_del(&debug_ctlwq, &wait);
105 set_current_state(TASK_RUNNING);
108 #ifdef PORTALS_DUMP_ON_PANIC
109 static int panic_dumplog(struct notifier_block *self, unsigned long unused1,
112 static int handled_panic; /* to avoid recursive calls to notifiers */
119 if (in_interrupt()) {
124 while (current->lock_depth >= 0)
126 portals_debug_dumplog();
130 static struct notifier_block lustre_panic_notifier = {
131 notifier_call : panic_dumplog,
138 extern void *lus_portals_debug;
141 int portals_debug_init(unsigned long bufsize)
143 cfs_waitq_init(&debug_ctlwq);
145 lus_portals_debug = &portals_debug_msg;
147 #ifdef PORTALS_DUMP_ON_PANIC
148 /* This is currently disabled because it spews far too much to the
149 * console on the rare cases it is ever triggered. */
150 notifier_chain_register(&panic_notifier_list, &lustre_panic_notifier);
152 return tracefile_init();
155 int portals_debug_cleanup(void)
158 #ifdef PORTALS_DUMP_ON_PANIC
159 notifier_chain_unregister(&panic_notifier_list, &lustre_panic_notifier);
162 lus_portals_debug = NULL;
167 int portals_debug_clear_buffer(void)
173 /* Debug markers, although printed by S_PORTALS
174 * should not be be marked as such. */
175 #undef DEBUG_SUBSYSTEM
176 #define DEBUG_SUBSYSTEM S_UNDEFINED
177 int portals_debug_mark_buffer(char *text)
179 CDEBUG(D_TRACE,"***************************************************\n");
180 CDEBUG(D_WARNING, "DEBUG MARKER: %s\n", text);
181 CDEBUG(D_TRACE,"***************************************************\n");
185 #undef DEBUG_SUBSYSTEM
186 #define DEBUG_SUBSYSTEM S_PORTALS
188 void portals_debug_set_level(unsigned int debug_level)
190 printk(KERN_WARNING "Lustre: Setting portals debug level to %08x\n",
192 portal_debug = debug_level;
195 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
197 if (nid == PTL_NID_ANY) {
198 snprintf(str, PTL_NALFMT_SIZE, "%s", "PTL_NID_ANY");
203 /* XXX this could be a nal method of some sort, 'cept it's config
204 * dependent whether (say) socknal NIDs are actually IP addresses... */
213 /* HIPQUAD requires __u32, but we can't cast in it */
214 __u32 nid32 = (__u32)nid;
215 if ((__u32)(nid >> 32)) {
216 snprintf(str, PTL_NALFMT_SIZE, "%u:%u.%u.%u.%u",
217 (__u32)(nid >> 32), HIPQUAD(nid32));
219 snprintf(str, PTL_NALFMT_SIZE, "%u.%u.%u.%u",
227 snprintf(str, PTL_NALFMT_SIZE, "%u:%u",
228 (__u32)(nid >> 32), (__u32)nid);
232 snprintf(str, PTL_NALFMT_SIZE, "?%x? %llx",
233 nal, (long long)nid);
239 char *portals_id2str(int nal, ptl_process_id_t id, char *str)
243 portals_nid2str(nal, id.nid, str);
245 snprintf(str + len, PTL_NALFMT_SIZE - len, "-%u", id.pid);
249 EXPORT_SYMBOL(portals_debug_dumplog);
250 EXPORT_SYMBOL(portals_debug_set_level);
251 EXPORT_SYMBOL(portals_nid2str);
252 EXPORT_SYMBOL(portals_id2str);