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);
39 EXPORT_SYMBOL(portal_debug);
41 unsigned int portal_printk;
42 EXPORT_SYMBOL(portal_printk);
44 unsigned int portal_stack;
45 EXPORT_SYMBOL(portal_stack);
48 atomic_t portal_kmemory = ATOMIC_INIT(0);
49 EXPORT_SYMBOL(portal_kmemory);
52 static cfs_waitq_t debug_ctlwq;
54 char debug_file_path[1024] = "/tmp/lustre-log";
55 static char debug_file_name[1024];
57 void portals_debug_dumplog_internal(void *arg)
59 CFS_DECL_JOURNAL_DATA;
63 snprintf(debug_file_name, sizeof(debug_file_path) - 1,
64 "%s.%ld.%ld", debug_file_path, cfs_time_current_sec(), (long)arg);
65 printk(KERN_ALERT "LustreError: dumping log to %s\n", debug_file_name);
66 tracefile_dump_all_pages(debug_file_name);
71 int portals_debug_dumplog_thread(void *arg)
73 kportal_daemonize("");
75 portals_debug_dumplog_internal(arg);
76 cfs_waitq_signal(&debug_ctlwq);
80 void portals_debug_dumplog(void)
86 /* we're being careful to ensure that the kernel thread is
87 * able to set our state to running as it exits before we
88 * get to schedule() */
89 cfs_waitlink_init(&wait);
90 set_current_state(TASK_INTERRUPTIBLE);
91 cfs_waitq_add(&debug_ctlwq, &wait);
93 rc = cfs_kernel_thread(portals_debug_dumplog_thread,
94 (void *)(long)cfs_curproc_pid(),
95 CLONE_VM | CLONE_FS | CLONE_FILES);
97 printk(KERN_ERR "LustreError: cannot start log dump thread: "
102 /* be sure to teardown if kernel_thread() failed */
103 cfs_waitq_del(&debug_ctlwq, &wait);
104 set_current_state(TASK_RUNNING);
107 #ifdef PORTALS_DUMP_ON_PANIC
108 static int panic_dumplog(struct notifier_block *self, unsigned long unused1,
111 static int handled_panic; /* to avoid recursive calls to notifiers */
118 if (in_interrupt()) {
123 while (current->lock_depth >= 0)
125 portals_debug_dumplog();
129 static struct notifier_block lustre_panic_notifier = {
130 notifier_call : panic_dumplog,
137 extern void *lus_portals_debug;
140 int portals_debug_init(unsigned long bufsize)
142 cfs_waitq_init(&debug_ctlwq);
144 lus_portals_debug = &portals_debug_msg;
146 #ifdef PORTALS_DUMP_ON_PANIC
147 /* This is currently disabled because it spews far too much to the
148 * console on the rare cases it is ever triggered. */
149 notifier_chain_register(&panic_notifier_list, &lustre_panic_notifier);
151 return tracefile_init();
154 int portals_debug_cleanup(void)
157 #ifdef PORTALS_DUMP_ON_PANIC
158 notifier_chain_unregister(&panic_notifier_list, &lustre_panic_notifier);
161 lus_portals_debug = NULL;
166 int portals_debug_clear_buffer(void)
172 /* Debug markers, although printed by S_PORTALS
173 * should not be be marked as such. */
174 #undef DEBUG_SUBSYSTEM
175 #define DEBUG_SUBSYSTEM S_UNDEFINED
176 int portals_debug_mark_buffer(char *text)
178 CDEBUG(D_TRACE,"***************************************************\n");
179 CDEBUG(D_WARNING, "DEBUG MARKER: %s\n", text);
180 CDEBUG(D_TRACE,"***************************************************\n");
184 #undef DEBUG_SUBSYSTEM
185 #define DEBUG_SUBSYSTEM S_PORTALS
187 void portals_debug_set_level(unsigned int debug_level)
189 printk(KERN_WARNING "Lustre: Setting portals debug level to %08x\n",
191 portal_debug = debug_level;
194 char *portals_nid2str(int nal, ptl_nid_t nid, char *str)
196 if (nid == PTL_NID_ANY) {
197 snprintf(str, PTL_NALFMT_SIZE, "%s", "PTL_NID_ANY");
202 /* XXX this could be a nal method of some sort, 'cept it's config
203 * dependent whether (say) socknal NIDs are actually IP addresses... */
212 /* HIPQUAD requires __u32, but we can't cast in it */
213 __u32 nid32 = (__u32)nid;
214 if ((__u32)(nid >> 32)) {
215 snprintf(str, PTL_NALFMT_SIZE, "%u:%u.%u.%u.%u",
216 (__u32)(nid >> 32), HIPQUAD(nid32));
218 snprintf(str, PTL_NALFMT_SIZE, "%u.%u.%u.%u",
226 snprintf(str, PTL_NALFMT_SIZE, "%u:%u",
227 (__u32)(nid >> 32), (__u32)nid);
231 snprintf(str, PTL_NALFMT_SIZE, "?%x? %llx",
232 nal, (long long)nid);
238 char *portals_id2str(int nal, ptl_process_id_t id, char *str)
242 portals_nid2str(nal, id.nid, str);
244 snprintf(str + len, PTL_NALFMT_SIZE - len, "-%u", id.pid);
248 EXPORT_SYMBOL(portals_debug_dumplog);
249 EXPORT_SYMBOL(portals_debug_set_level);
250 EXPORT_SYMBOL(portals_nid2str);
251 EXPORT_SYMBOL(portals_id2str);