1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * This file and its contents are supplied under the terms of the 4 * Common Development and Distribution License ("CDDL"), version 1.0. 5 * You may only use this file in accordance with the terms of version 6 * 1.0 of the CDDL. 7 * 8 * A full copy of the text of the CDDL should have accompanied this 9 * source. A copy of the CDDL is also available via the Internet at 10 * https://opensource.org/license/CDDL-1.0. 11 */ 12 /* 13 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 14 * Copyright (c) 2012, 2019 by Delphix. All rights reserved. 15 */ 16 17 #ifndef _SYS_ZFS_DEBUG_H 18 #define _SYS_ZFS_DEBUG_H 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 #ifndef TRUE 25 #define TRUE 1 26 #endif 27 28 #ifndef FALSE 29 #define FALSE 0 30 #endif 31 32 #include <sys/nvpair.h> 33 #include <sys/zfs_debug_os.h> 34 35 extern int zfs_flags; 36 extern int zfs_recover; 37 extern int zfs_free_leak_on_eio; 38 extern int zfs_dbgmsg_enable; 39 40 #define ZFS_DEBUG_DPRINTF (1 << 0) 41 #define ZFS_DEBUG_DBUF_VERIFY (1 << 1) 42 #define ZFS_DEBUG_DNODE_VERIFY (1 << 2) 43 #define ZFS_DEBUG_SNAPNAMES (1 << 3) 44 #define ZFS_DEBUG_MODIFY (1 << 4) 45 /* 1<<5 was previously used, try not to reuse */ 46 #define ZFS_DEBUG_ZIO_FREE (1 << 6) 47 #define ZFS_DEBUG_HISTOGRAM_VERIFY (1 << 7) 48 #define ZFS_DEBUG_METASLAB_VERIFY (1 << 8) 49 #define ZFS_DEBUG_SET_ERROR (1 << 9) 50 #define ZFS_DEBUG_INDIRECT_REMAP (1 << 10) 51 #define ZFS_DEBUG_TRIM (1 << 11) 52 #define ZFS_DEBUG_LOG_SPACEMAP (1 << 12) 53 #define ZFS_DEBUG_METASLAB_ALLOC (1 << 13) 54 #define ZFS_DEBUG_BRT (1 << 14) 55 #define ZFS_DEBUG_RAIDZ_RECONSTRUCT (1 << 15) 56 #define ZFS_DEBUG_DDT (1 << 16) 57 58 extern void __set_error(const char *file, const char *func, int line, int err); 59 extern void __zfs_dbgmsg(char *buf); 60 extern void __dprintf(boolean_t dprint, const char *file, const char *func, 61 int line, const char *fmt, ...) __attribute__((format(__printf__, 5, 6))); 62 63 /* 64 * Some general principles for using zfs_dbgmsg(): 65 * 1. We don't want to pollute the log with typically-irrelevant messages, 66 * so don't print too many messages in the "normal" code path - O(1) 67 * per txg. 68 * 2. We want to know for sure what happened, so make the message specific 69 * (e.g. *which* thing am I operating on). 70 * 3. Do print a message when something unusual or unexpected happens 71 * (e.g. error cases). 72 * 4. Print a message when making user-initiated on-disk changes. 73 * 74 * Note that besides principle 1, another reason that we don't want to 75 * use zfs_dbgmsg in high-frequency routines is the potential impact 76 * that it can have on performance. 77 */ 78 #define zfs_dbgmsg(...) \ 79 if (zfs_dbgmsg_enable) \ 80 __dprintf(B_FALSE, __FILE__, __func__, __LINE__, __VA_ARGS__) 81 82 #ifdef ZFS_DEBUG 83 /* 84 * To enable this: 85 * 86 * $ echo 1 >/sys/module/zfs/parameters/zfs_flags 87 */ 88 #define dprintf(...) \ 89 if (zfs_flags & ZFS_DEBUG_DPRINTF) \ 90 __dprintf(B_TRUE, __FILE__, __func__, __LINE__, __VA_ARGS__) 91 #else 92 #define dprintf(...) ((void)0) 93 #endif /* ZFS_DEBUG */ 94 95 extern void zfs_panic_recover(const char *fmt, ...); 96 97 extern void zfs_dbgmsg_init(void); 98 extern void zfs_dbgmsg_fini(void); 99 100 /* 101 * When printing an nvlist, print one beginning line with the file/func/line 102 * number and the text "nvlist <var name>:" followed by all the nvlist lines 103 * without the file/fun/line number. This makes the nvlist lines easy to read. 104 */ 105 #define zfs_dbgmsg_nvlist(nv) \ 106 if (zfs_dbgmsg_enable) { \ 107 zfs_dbgmsg("nvlist "#nv":"); \ 108 __zfs_dbgmsg_nvlist(nv); \ 109 } 110 111 #define zfs_dbgmsg(...) \ 112 if (zfs_dbgmsg_enable) \ 113 __dprintf(B_FALSE, __FILE__, __func__, __LINE__, __VA_ARGS__) 114 115 116 extern void __zfs_dbgmsg_nvlist(nvlist_t *nv); 117 118 #ifndef _KERNEL 119 extern int dprintf_find_string(const char *string); 120 extern void zfs_dbgmsg_print(int fd, const char *tag); 121 #endif 122 123 #ifdef __cplusplus 124 } 125 #endif 126 127 #endif /* _SYS_ZFS_DEBUG_H */ 128