4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/libcfs/debug.c
38 * Author: Phil Schwan <phil@clusterfs.com>
42 # define DEBUG_SUBSYSTEM S_LNET
44 #include "../../include/linux/libcfs/libcfs.h"
45 #include "tracefile.h"
47 static char debug_file_name
[1024];
49 unsigned int libcfs_subsystem_debug
= ~0;
50 EXPORT_SYMBOL(libcfs_subsystem_debug
);
51 module_param(libcfs_subsystem_debug
, int, 0644);
52 MODULE_PARM_DESC(libcfs_subsystem_debug
, "Lustre kernel debug subsystem mask");
54 unsigned int libcfs_debug
= (D_CANTMASK
|
55 D_NETERROR
| D_HA
| D_CONFIG
| D_IOCTL
);
56 EXPORT_SYMBOL(libcfs_debug
);
57 module_param(libcfs_debug
, int, 0644);
58 MODULE_PARM_DESC(libcfs_debug
, "Lustre kernel debug mask");
60 static int libcfs_param_debug_mb_set(const char *val
,
61 const struct kernel_param
*kp
)
66 rc
= kstrtouint(val
, 0, &num
);
70 if (!*((unsigned int *)kp
->arg
)) {
71 *((unsigned int *)kp
->arg
) = num
;
75 rc
= cfs_trace_set_debug_mb(num
);
78 *((unsigned int *)kp
->arg
) = cfs_trace_get_debug_mb();
83 /* While debug_mb setting look like unsigned int, in fact
84 * it needs quite a bunch of extra processing, so we define special
85 * debugmb parameter type with corresponding methods to handle this case
87 static struct kernel_param_ops param_ops_debugmb
= {
88 .set
= libcfs_param_debug_mb_set
,
89 .get
= param_get_uint
,
92 #define param_check_debugmb(name, p) \
93 __param_check(name, p, unsigned int)
95 static unsigned int libcfs_debug_mb
;
96 module_param(libcfs_debug_mb
, debugmb
, 0644);
97 MODULE_PARM_DESC(libcfs_debug_mb
, "Total debug buffer size.");
99 unsigned int libcfs_printk
= D_CANTMASK
;
100 module_param(libcfs_printk
, uint
, 0644);
101 MODULE_PARM_DESC(libcfs_printk
, "Lustre kernel debug console mask");
103 unsigned int libcfs_console_ratelimit
= 1;
104 module_param(libcfs_console_ratelimit
, uint
, 0644);
105 MODULE_PARM_DESC(libcfs_console_ratelimit
, "Lustre kernel debug console ratelimit (0 to disable)");
107 static int param_set_delay_minmax(const char *val
,
108 const struct kernel_param
*kp
,
115 rc
= kstrtoint(val
, 0, &sec
);
119 d
= cfs_time_seconds(sec
) / 100;
120 if (d
< min
|| d
> max
)
123 *((unsigned int *)kp
->arg
) = d
;
128 static int param_get_delay(char *buffer
, const struct kernel_param
*kp
)
130 unsigned int d
= *(unsigned int *)kp
->arg
;
132 return sprintf(buffer
, "%u", (unsigned int)cfs_duration_sec(d
* 100));
135 unsigned int libcfs_console_max_delay
;
136 unsigned int libcfs_console_min_delay
;
138 static int param_set_console_max_delay(const char *val
,
139 const struct kernel_param
*kp
)
141 return param_set_delay_minmax(val
, kp
,
142 libcfs_console_min_delay
, INT_MAX
);
145 static struct kernel_param_ops param_ops_console_max_delay
= {
146 .set
= param_set_console_max_delay
,
147 .get
= param_get_delay
,
150 #define param_check_console_max_delay(name, p) \
151 __param_check(name, p, unsigned int)
153 module_param(libcfs_console_max_delay
, console_max_delay
, 0644);
154 MODULE_PARM_DESC(libcfs_console_max_delay
, "Lustre kernel debug console max delay (jiffies)");
156 static int param_set_console_min_delay(const char *val
,
157 const struct kernel_param
*kp
)
159 return param_set_delay_minmax(val
, kp
,
160 1, libcfs_console_max_delay
);
163 static struct kernel_param_ops param_ops_console_min_delay
= {
164 .set
= param_set_console_min_delay
,
165 .get
= param_get_delay
,
168 #define param_check_console_min_delay(name, p) \
169 __param_check(name, p, unsigned int)
171 module_param(libcfs_console_min_delay
, console_min_delay
, 0644);
172 MODULE_PARM_DESC(libcfs_console_min_delay
, "Lustre kernel debug console min delay (jiffies)");
174 static int param_set_uint_minmax(const char *val
,
175 const struct kernel_param
*kp
,
176 unsigned int min
, unsigned int max
)
183 ret
= kstrtouint(val
, 0, &num
);
184 if (ret
< 0 || num
< min
|| num
> max
)
186 *((unsigned int *)kp
->arg
) = num
;
190 static int param_set_uintpos(const char *val
, const struct kernel_param
*kp
)
192 return param_set_uint_minmax(val
, kp
, 1, -1);
195 static struct kernel_param_ops param_ops_uintpos
= {
196 .set
= param_set_uintpos
,
197 .get
= param_get_uint
,
200 #define param_check_uintpos(name, p) \
201 __param_check(name, p, unsigned int)
203 unsigned int libcfs_console_backoff
= CDEBUG_DEFAULT_BACKOFF
;
204 module_param(libcfs_console_backoff
, uintpos
, 0644);
205 MODULE_PARM_DESC(libcfs_console_backoff
, "Lustre kernel debug console backoff factor");
207 unsigned int libcfs_debug_binary
= 1;
209 unsigned int libcfs_stack
= 3 * THREAD_SIZE
/ 4;
210 EXPORT_SYMBOL(libcfs_stack
);
212 unsigned int libcfs_catastrophe
;
213 EXPORT_SYMBOL(libcfs_catastrophe
);
215 unsigned int libcfs_panic_on_lbug
= 1;
216 module_param(libcfs_panic_on_lbug
, uint
, 0644);
217 MODULE_PARM_DESC(libcfs_panic_on_lbug
, "Lustre kernel panic on LBUG");
219 static wait_queue_head_t debug_ctlwq
;
221 char libcfs_debug_file_path_arr
[PATH_MAX
] = LIBCFS_DEBUG_FILE_PATH_DEFAULT
;
223 /* We need to pass a pointer here, but elsewhere this must be a const */
224 static char *libcfs_debug_file_path
;
225 module_param(libcfs_debug_file_path
, charp
, 0644);
226 MODULE_PARM_DESC(libcfs_debug_file_path
,
227 "Path for dumping debug logs, set 'NONE' to prevent log dumping");
229 int libcfs_panic_in_progress
;
231 /* libcfs_debug_token2mask() expects the returned string in lower-case */
233 libcfs_debug_subsys2str(int subsys
)
235 switch (1 << subsys
) {
293 /* libcfs_debug_token2mask() expects the returned string in lower-case */
295 libcfs_debug_dbg2str(int debug
)
297 switch (1 << debug
) {
362 libcfs_debug_mask2str(char *str
, int size
, int mask
, int is_subsys
)
364 const char *(*fn
)(int bit
) = is_subsys
? libcfs_debug_subsys2str
:
365 libcfs_debug_dbg2str
;
370 if (mask
== 0) { /* "0" */
374 } else { /* space-separated tokens */
375 for (i
= 0; i
< 32; i
++) {
376 if ((mask
& (1 << i
)) == 0)
380 if (!token
) /* unused bit */
383 if (len
> 0) { /* separator? */
389 while (*token
!= 0) {
398 /* terminate 'str' */
408 libcfs_debug_str2mask(int *mask
, const char *str
, int is_subsys
)
410 const char *(*fn
)(int bit
) = is_subsys
? libcfs_debug_subsys2str
:
411 libcfs_debug_dbg2str
;
417 /* Allow a number for backwards compatibility */
419 for (n
= strlen(str
); n
> 0; n
--)
420 if (!isspace(str
[n
- 1]))
423 t
= sscanf(str
, "%i%n", &m
, &matched
);
424 if (t
>= 1 && matched
== n
) {
425 /* don't print warning for lctl set_param debug=0 or -1 */
426 if (m
!= 0 && m
!= -1)
427 CWARN("You are trying to use a numerical value for the mask - this will be deprecated in a future release.\n");
432 return cfs_str2mask(str
, fn
, mask
, is_subsys
? 0 : D_CANTMASK
,
437 * Dump Lustre log to ::debug_file_path by calling tracefile_dump_all_pages()
439 void libcfs_debug_dumplog_internal(void *arg
)
443 journal_info
= current
->journal_info
;
444 current
->journal_info
= NULL
;
446 if (strncmp(libcfs_debug_file_path_arr
, "NONE", 4) != 0) {
447 snprintf(debug_file_name
, sizeof(debug_file_name
) - 1,
448 "%s.%lld.%ld", libcfs_debug_file_path_arr
,
449 (s64
)ktime_get_real_seconds(), (long_ptr_t
)arg
);
450 pr_alert("LustreError: dumping log to %s\n", debug_file_name
);
451 cfs_tracefile_dump_all_pages(debug_file_name
);
452 libcfs_run_debug_log_upcall(debug_file_name
);
455 current
->journal_info
= journal_info
;
458 static int libcfs_debug_dumplog_thread(void *arg
)
460 libcfs_debug_dumplog_internal(arg
);
461 wake_up(&debug_ctlwq
);
465 void libcfs_debug_dumplog(void)
468 struct task_struct
*dumper
;
470 /* we're being careful to ensure that the kernel thread is
471 * able to set our state to running as it exits before we
474 init_waitqueue_entry(&wait
, current
);
475 set_current_state(TASK_INTERRUPTIBLE
);
476 add_wait_queue(&debug_ctlwq
, &wait
);
478 dumper
= kthread_run(libcfs_debug_dumplog_thread
,
479 (void *)(long)current_pid(),
480 "libcfs_debug_dumper");
482 pr_err("LustreError: cannot start log dump thread: %ld\n",
487 /* be sure to teardown if cfs_create_thread() failed */
488 remove_wait_queue(&debug_ctlwq
, &wait
);
489 set_current_state(TASK_RUNNING
);
491 EXPORT_SYMBOL(libcfs_debug_dumplog
);
493 int libcfs_debug_init(unsigned long bufsize
)
496 unsigned int max
= libcfs_debug_mb
;
498 init_waitqueue_head(&debug_ctlwq
);
500 if (libcfs_console_max_delay
<= 0 || /* not set by user or */
501 libcfs_console_min_delay
<= 0 || /* set to invalid values */
502 libcfs_console_min_delay
>= libcfs_console_max_delay
) {
503 libcfs_console_max_delay
= CDEBUG_DEFAULT_MAX_DELAY
;
504 libcfs_console_min_delay
= CDEBUG_DEFAULT_MIN_DELAY
;
507 if (libcfs_debug_file_path
) {
508 strlcpy(libcfs_debug_file_path_arr
,
509 libcfs_debug_file_path
,
510 sizeof(libcfs_debug_file_path_arr
));
513 /* If libcfs_debug_mb is set to an invalid value or uninitialized
514 * then just make the total buffers smp_num_cpus * TCD_MAX_PAGES
516 if (max
> cfs_trace_max_debug_mb() || max
< num_possible_cpus()) {
519 max
= max
/ num_possible_cpus();
520 max
<<= (20 - PAGE_SHIFT
);
522 rc
= cfs_tracefile_init(max
);
525 libcfs_register_panic_notifier();
526 libcfs_debug_mb
= cfs_trace_get_debug_mb();
532 int libcfs_debug_cleanup(void)
534 libcfs_unregister_panic_notifier();
535 cfs_tracefile_exit();
539 int libcfs_debug_clear_buffer(void)
541 cfs_trace_flush_pages();
545 /* Debug markers, although printed by S_LNET should not be be marked as such. */
546 #undef DEBUG_SUBSYSTEM
547 #define DEBUG_SUBSYSTEM S_UNDEFINED
548 int libcfs_debug_mark_buffer(const char *text
)
551 "***************************************************\n");
552 LCONSOLE(D_WARNING
, "DEBUG MARKER: %s\n", text
);
554 "***************************************************\n");
559 #undef DEBUG_SUBSYSTEM
560 #define DEBUG_SUBSYSTEM S_LNET