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