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 44 extern int zfs_flags; 45 extern int zfs_recover; 46 extern int zfs_free_leak_on_eio; 47 extern int zfs_dbgmsg_enable; 48 49 #define ZFS_DEBUG_DPRINTF (1 << 0) 50 #define ZFS_DEBUG_DBUF_VERIFY (1 << 1) 51 #define ZFS_DEBUG_DNODE_VERIFY (1 << 2) 52 #define ZFS_DEBUG_SNAPNAMES (1 << 3) 53 #define ZFS_DEBUG_MODIFY (1 << 4) 54 /* 1<<5 was previously used, try not to reuse */ 55 #define ZFS_DEBUG_ZIO_FREE (1 << 6) 56 #define ZFS_DEBUG_HISTOGRAM_VERIFY (1 << 7) 57 #define ZFS_DEBUG_METASLAB_VERIFY (1 << 8) 58 #define ZFS_DEBUG_SET_ERROR (1 << 9) 59 #define ZFS_DEBUG_INDIRECT_REMAP (1 << 10) 60 #define ZFS_DEBUG_TRIM (1 << 11) 61 #define ZFS_DEBUG_LOG_SPACEMAP (1 << 12) 62 #define ZFS_DEBUG_METASLAB_ALLOC (1 << 13) 63 #define ZFS_DEBUG_BRT (1 << 14) 64 #define ZFS_DEBUG_RAIDZ_RECONSTRUCT (1 << 15) 65 #define ZFS_DEBUG_DDT (1 << 16) 66 67 extern void __set_error(const char *file, const char *func, int line, int err); 68 extern void __zfs_dbgmsg(char *buf); 69 extern void __dprintf(boolean_t dprint, const char *file, const char *func, 70 int line, const char *fmt, ...) __attribute__((format(printf, 5, 6))); 71 72 /* 73 * Some general principles for using zfs_dbgmsg(): 74 * 1. We don't want to pollute the log with typically-irrelevant messages, 75 * so don't print too many messages in the "normal" code path - O(1) 76 * per txg. 77 * 2. We want to know for sure what happened, so make the message specific 78 * (e.g. *which* thing am I operating on). 79 * 3. Do print a message when something unusual or unexpected happens 80 * (e.g. error cases). 81 * 4. Print a message when making user-initiated on-disk changes. 82 * 83 * Note that besides principle 1, another reason that we don't want to 84 * use zfs_dbgmsg in high-frequency routines is the potential impact 85 * that it can have on performance. 86 */ 87 #define zfs_dbgmsg(...) \ 88 if (zfs_dbgmsg_enable) \ 89 __dprintf(B_FALSE, __FILE__, __func__, __LINE__, __VA_ARGS__) 90 91 #ifdef ZFS_DEBUG 92 /* 93 * To enable this: 94 * 95 * $ echo 1 >/sys/module/zfs/parameters/zfs_flags 96 */ 97 #define dprintf(...) \ 98 if (zfs_flags & ZFS_DEBUG_DPRINTF) \ 99 __dprintf(B_TRUE, __FILE__, __func__, __LINE__, __VA_ARGS__) 100 #else 101 #define dprintf(...) ((void)0) 102 #endif /* ZFS_DEBUG */ 103 104 extern void zfs_panic_recover(const char *fmt, ...); 105 106 extern void zfs_dbgmsg_init(void); 107 extern void zfs_dbgmsg_fini(void); 108 109 /* 110 * When printing an nvlist, print one beginning line with the file/func/line 111 * number and the text "nvlist <var name>:" followed by all the nvlist lines 112 * without the file/fun/line number. This makes the nvlist lines easy to read. 113 */ 114 #define zfs_dbgmsg_nvlist(nv) \ 115 if (zfs_dbgmsg_enable) { \ 116 zfs_dbgmsg("nvlist "#nv":"); \ 117 __zfs_dbgmsg_nvlist(nv); \ 118 } 119 120 #define zfs_dbgmsg(...) \ 121 if (zfs_dbgmsg_enable) \ 122 __dprintf(B_FALSE, __FILE__, __func__, __LINE__, __VA_ARGS__) 123 124 125 extern void __zfs_dbgmsg_nvlist(nvlist_t *nv); 126 127 #ifndef _KERNEL 128 extern int dprintf_find_string(const char *string); 129 extern void zfs_dbgmsg_print(int fd, const char *tag); 130 #endif 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif /* _SYS_ZFS_DEBUG_H */ 137