Illumos #3006
[zfs.git] / module / zfs / zfs_debug.c
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright (c) 2012 by Delphix. All rights reserved.
24  */
25
26 #include <sys/zfs_context.h>
27
28 /*
29  * Enable various debugging features.
30  */
31 int zfs_flags = 0;
32
33 /*
34  * zfs_recover can be set to nonzero to attempt to recover from
35  * otherwise-fatal errors, typically caused by on-disk corruption.  When
36  * set, calls to zfs_panic_recover() will turn into warning messages.
37  */
38 int zfs_recover = 0;
39
40
41 void
42 zfs_panic_recover(const char *fmt, ...)
43 {
44         va_list adx;
45
46         va_start(adx, fmt);
47         vcmn_err(zfs_recover ? CE_WARN : CE_PANIC, fmt, adx);
48         va_end(adx);
49 }
50
51 /*
52  * Debug logging is enabled by default for production kernel builds.
53  * The overhead for this is negligible and the logs can be valuable when
54  * debugging.  For non-production user space builds all debugging except
55  * logging is enabled since performance is no longer a concern.
56  */
57 void
58 zfs_dbgmsg_init(void)
59 {
60         if (zfs_flags == 0) {
61 #if defined(_KERNEL)
62                 zfs_flags = ZFS_DEBUG_DPRINTF;
63                 spl_debug_set_mask(spl_debug_get_mask() | SD_DPRINTF);
64                 spl_debug_set_subsys(spl_debug_get_subsys() | SS_USER1);
65 #else
66                 zfs_flags = ~ZFS_DEBUG_DPRINTF;
67 #endif /* _KERNEL */
68         }
69 }
70
71 void
72 zfs_dbgmsg_fini(void)
73 {
74         return;
75 }
76
77
78 #if defined(_KERNEL)
79 module_param(zfs_flags, int, 0644);
80 MODULE_PARM_DESC(zfs_flags, "Set additional debugging flags");
81
82 module_param(zfs_recover, int, 0644);
83 MODULE_PARM_DESC(zfs_recover, "Set to attempt to recover from fatal errors");
84 #endif /* _KERNEL */