diff options
author | Brian Behlendorf <[email protected]> | 2012-01-20 15:02:57 -0800 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2012-02-02 11:24:30 -0800 |
commit | d7e398ce1a3e6f9c705af43955a684685a798c32 (patch) | |
tree | 06ff1d5c4431f8194d5b50c1824532b816902dc0 /module/zfs/zfs_debug.c | |
parent | 0c5dde492ff4fadcc9c43477c81b3d3824ac41db (diff) |
Cleanup ZFS debug infrastructure
Historically the internal zfs debug infrastructure has been
scattered throughout the code. Since we expect to start making
more use of this code this patch performs some cleanup.
* Consolidate the zfs debug infrastructure in the zfs_debug.[ch]
files. This includes moving the zfs_flags and zfs_recover
variables, plus moving the zfs_panic_recover() function.
* Remove the existing unused functionality in zfs_debug.c and
replace it with code which correctly utilized the spl logging
infrastructure.
* Remove the __dprintf() function from zfs_ioctl.c. This is
dead code, the dprintf() functionality in the kernel relies
on the spl log support.
* Remove dprintf() from hdr_recl(). This wasn't particularly
useful and was missing the required format specifier anyway.
* Subsequent patches should unify the dprintf() and zfs_dbgmsg()
functions.
Signed-off-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'module/zfs/zfs_debug.c')
-rw-r--r-- | module/zfs/zfs_debug.c | 96 |
1 files changed, 42 insertions, 54 deletions
diff --git a/module/zfs/zfs_debug.c b/module/zfs/zfs_debug.c index d0f411a99..f4b5e6fa1 100644 --- a/module/zfs/zfs_debug.c +++ b/module/zfs/zfs_debug.c @@ -24,72 +24,60 @@ #include <sys/zfs_context.h> -list_t zfs_dbgmsgs; -int zfs_dbgmsg_size; -kmutex_t zfs_dbgmsgs_lock; -int zfs_dbgmsg_maxsize = 1<<20; /* 1MB */ +/* + * Enable various debugging features. + */ +int zfs_flags = 0; + +/* + * zfs_recover can be set to nonzero to attempt to recover from + * otherwise-fatal errors, typically caused by on-disk corruption. When + * set, calls to zfs_panic_recover() will turn into warning messages. + */ +int zfs_recover = 0; -void -zfs_dbgmsg_init(void) -{ - list_create(&zfs_dbgmsgs, sizeof (zfs_dbgmsg_t), - offsetof(zfs_dbgmsg_t, zdm_node)); - mutex_init(&zfs_dbgmsgs_lock, NULL, MUTEX_DEFAULT, NULL); -} void -zfs_dbgmsg_fini(void) +zfs_panic_recover(const char *fmt, ...) { - zfs_dbgmsg_t *zdm; + va_list adx; - while ((zdm = list_remove_head(&zfs_dbgmsgs)) != NULL) { - int size = sizeof (zfs_dbgmsg_t) + strlen(zdm->zdm_msg); - kmem_free(zdm, size); - zfs_dbgmsg_size -= size; - } - mutex_destroy(&zfs_dbgmsgs_lock); - ASSERT3U(zfs_dbgmsg_size, ==, 0); + va_start(adx, fmt); + vcmn_err(zfs_recover ? CE_WARN : CE_PANIC, fmt, adx); + va_end(adx); } /* - * Print these messages by running: - * echo ::zfs_dbgmsg | mdb -k - * - * Monitor these messages by running: - * dtrace -q -n 'zfs-dbgmsg{printf("%s\n", stringof(arg0))}' + * Debug logging is enabled by default for production kernel builds. + * The overhead for this is negligible and the logs can be valuable when + * debugging. For non-production user space builds all debugging except + * logging is enabled since performance is no longer a concern. */ void -zfs_dbgmsg(const char *fmt, ...) +zfs_dbgmsg_init(void) { - int size; - va_list adx; - zfs_dbgmsg_t *zdm; - - va_start(adx, fmt); - size = vsnprintf(NULL, 0, fmt, adx); - va_end(adx); + if (zfs_flags == 0) { +#if defined(_KERNEL) + zfs_flags = ZFS_DEBUG_DPRINTF; + spl_debug_mask |= SD_DPRINTF; + spl_debug_subsys |= SS_USER1; +#else + zfs_flags = ~ZFS_DEBUG_DPRINTF; +#endif /* _KERNEL */ + } +} - /* - * There is one byte of string in sizeof (zfs_dbgmsg_t), used - * for the terminating null. - */ - zdm = kmem_alloc(sizeof (zfs_dbgmsg_t) + size, KM_SLEEP); - zdm->zdm_timestamp = gethrestime_sec(); +void +zfs_dbgmsg_fini(void) +{ + return; +} - va_start(adx, fmt); - (void) vsnprintf(zdm->zdm_msg, size + 1, fmt, adx); - va_end(adx); - DTRACE_PROBE1(zfs__dbgmsg, char *, zdm->zdm_msg); +#if defined(_KERNEL) +module_param(zfs_flags, int, 0644); +MODULE_PARM_DESC(zfs_flags, "Set additional debugging flags"); - mutex_enter(&zfs_dbgmsgs_lock); - list_insert_tail(&zfs_dbgmsgs, zdm); - zfs_dbgmsg_size += sizeof (zfs_dbgmsg_t) + size; - while (zfs_dbgmsg_size > zfs_dbgmsg_maxsize) { - zdm = list_remove_head(&zfs_dbgmsgs); - size = sizeof (zfs_dbgmsg_t) + strlen(zdm->zdm_msg); - kmem_free(zdm, size); - zfs_dbgmsg_size -= size; - } - mutex_exit(&zfs_dbgmsgs_lock); -} +module_param(zfs_recover, int, 0644); +MODULE_PARM_DESC(zfs_recover, "Set to attempt to recover from fatal errors"); +#endif /* _KERNEL */ |