1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  */
21eda14cbcSMatt Macy /*
22eda14cbcSMatt Macy  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23eda14cbcSMatt Macy  * Copyright (c) 2012, 2019 by Delphix. All rights reserved.
24eda14cbcSMatt Macy  */
25eda14cbcSMatt Macy 
26eda14cbcSMatt Macy #ifndef _SYS_ZFS_DEBUG_H
27eda14cbcSMatt Macy #define	_SYS_ZFS_DEBUG_H
28eda14cbcSMatt Macy 
29eda14cbcSMatt Macy #ifdef	__cplusplus
30eda14cbcSMatt Macy extern "C" {
31eda14cbcSMatt Macy #endif
32eda14cbcSMatt Macy 
33eda14cbcSMatt Macy #ifndef TRUE
34eda14cbcSMatt Macy #define	TRUE 1
35eda14cbcSMatt Macy #endif
36eda14cbcSMatt Macy 
37eda14cbcSMatt Macy #ifndef FALSE
38eda14cbcSMatt Macy #define	FALSE 0
39eda14cbcSMatt Macy #endif
40eda14cbcSMatt Macy 
41eda14cbcSMatt Macy extern int zfs_flags;
42eda14cbcSMatt Macy extern int zfs_recover;
43eda14cbcSMatt Macy extern int zfs_free_leak_on_eio;
44eda14cbcSMatt Macy extern int zfs_dbgmsg_enable;
45eda14cbcSMatt Macy 
46eda14cbcSMatt Macy #define	ZFS_DEBUG_DPRINTF		(1 << 0)
47eda14cbcSMatt Macy #define	ZFS_DEBUG_DBUF_VERIFY		(1 << 1)
48eda14cbcSMatt Macy #define	ZFS_DEBUG_DNODE_VERIFY		(1 << 2)
49eda14cbcSMatt Macy #define	ZFS_DEBUG_SNAPNAMES		(1 << 3)
50eda14cbcSMatt Macy #define	ZFS_DEBUG_MODIFY		(1 << 4)
51eda14cbcSMatt Macy /* 1<<5 was previously used, try not to reuse */
52eda14cbcSMatt Macy #define	ZFS_DEBUG_ZIO_FREE		(1 << 6)
53eda14cbcSMatt Macy #define	ZFS_DEBUG_HISTOGRAM_VERIFY	(1 << 7)
54eda14cbcSMatt Macy #define	ZFS_DEBUG_METASLAB_VERIFY	(1 << 8)
55eda14cbcSMatt Macy #define	ZFS_DEBUG_SET_ERROR		(1 << 9)
56eda14cbcSMatt Macy #define	ZFS_DEBUG_INDIRECT_REMAP	(1 << 10)
57eda14cbcSMatt Macy #define	ZFS_DEBUG_TRIM			(1 << 11)
58eda14cbcSMatt Macy #define	ZFS_DEBUG_LOG_SPACEMAP		(1 << 12)
59184c1b94SMartin Matuska #define	ZFS_DEBUG_METASLAB_ALLOC	(1 << 13)
602a58b312SMartin Matuska #define	ZFS_DEBUG_BRT			(1 << 14)
61*e716630dSMartin Matuska #define	ZFS_DEBUG_RAIDZ_RECONSTRUCT	(1 << 15)
62eda14cbcSMatt Macy 
63eda14cbcSMatt Macy extern void __set_error(const char *file, const char *func, int line, int err);
64eda14cbcSMatt Macy extern void __zfs_dbgmsg(char *buf);
65eda14cbcSMatt Macy extern void __dprintf(boolean_t dprint, const char *file, const char *func,
6633b8c039SMartin Matuska     int line, const char *fmt, ...)  __attribute__((format(printf, 5, 6)));
67eda14cbcSMatt Macy 
68eda14cbcSMatt Macy /*
69eda14cbcSMatt Macy  * Some general principles for using zfs_dbgmsg():
70eda14cbcSMatt Macy  * 1. We don't want to pollute the log with typically-irrelevant messages,
71eda14cbcSMatt Macy  *    so don't print too many messages in the "normal" code path - O(1)
72eda14cbcSMatt Macy  *    per txg.
73eda14cbcSMatt Macy  * 2. We want to know for sure what happened, so make the message specific
74eda14cbcSMatt Macy  *    (e.g. *which* thing am I operating on).
75eda14cbcSMatt Macy  * 3. Do print a message when something unusual or unexpected happens
76eda14cbcSMatt Macy  *    (e.g. error cases).
77eda14cbcSMatt Macy  * 4. Print a message when making user-initiated on-disk changes.
78eda14cbcSMatt Macy  *
79eda14cbcSMatt Macy  * Note that besides principle 1, another reason that we don't want to
80eda14cbcSMatt Macy  * use zfs_dbgmsg in high-frequency routines is the potential impact
81eda14cbcSMatt Macy  * that it can have on performance.
82eda14cbcSMatt Macy  */
83eda14cbcSMatt Macy #define	zfs_dbgmsg(...) \
84eda14cbcSMatt Macy 	if (zfs_dbgmsg_enable) \
85eda14cbcSMatt Macy 		__dprintf(B_FALSE, __FILE__, __func__, __LINE__, __VA_ARGS__)
86eda14cbcSMatt Macy 
87eda14cbcSMatt Macy #ifdef ZFS_DEBUG
88eda14cbcSMatt Macy /*
89eda14cbcSMatt Macy  * To enable this:
90eda14cbcSMatt Macy  *
91eda14cbcSMatt Macy  * $ echo 1 >/sys/module/zfs/parameters/zfs_flags
92eda14cbcSMatt Macy  */
93eda14cbcSMatt Macy #define	dprintf(...) \
94eda14cbcSMatt Macy 	if (zfs_flags & ZFS_DEBUG_DPRINTF) \
95eda14cbcSMatt Macy 		__dprintf(B_TRUE, __FILE__, __func__, __LINE__, __VA_ARGS__)
96eda14cbcSMatt Macy #else
97eda14cbcSMatt Macy #define	dprintf(...) ((void)0)
98eda14cbcSMatt Macy #endif /* ZFS_DEBUG */
99eda14cbcSMatt Macy 
100eda14cbcSMatt Macy extern void zfs_panic_recover(const char *fmt, ...);
101eda14cbcSMatt Macy 
102eda14cbcSMatt Macy extern void zfs_dbgmsg_init(void);
103eda14cbcSMatt Macy extern void zfs_dbgmsg_fini(void);
104eda14cbcSMatt Macy 
105eda14cbcSMatt Macy #ifndef _KERNEL
106eda14cbcSMatt Macy extern int dprintf_find_string(const char *string);
107eda14cbcSMatt Macy extern void zfs_dbgmsg_print(const char *tag);
108eda14cbcSMatt Macy #endif
109eda14cbcSMatt Macy 
110eda14cbcSMatt Macy #ifdef	__cplusplus
111eda14cbcSMatt Macy }
112eda14cbcSMatt Macy #endif
113eda14cbcSMatt Macy 
114eda14cbcSMatt Macy #endif	/* _SYS_ZFS_DEBUG_H */
115