diff options
author | Ned Bass <[email protected]> | 2017-07-25 23:09:48 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-07-25 23:09:48 -0700 |
commit | 8740cf4a2f5f7ff7fb6c214e0baf06356b2870b8 (patch) | |
tree | b653cfe22dfd57e65f29206a0b73563811893414 /module | |
parent | 9ff13dbe921c7177faee3f10c832e88bded39920 (diff) |
Add line info and SET_ERROR() to ZFS debug log
Redefine the SET_ERROR macro in terms of __dprintf() so the error
return codes get logged as both tracepoint events (if tracepoints are
enabled) and as ZFS debug log entries. This also allows us to use
the same definition of SET_ERROR() in kernel and user space.
Define a new debug flag ZFS_DEBUG_SET_ERROR=512 that may be bitwise
or'd into zfs_flags. Setting this flag enables both dprintf() and
SET_ERROR() messages in the debug log. That is, setting
ZFS_DEBUG_SET_ERROR and ZFS_DEBUG_DPRINTF|ZFS_DEBUG_SET_ERROR are
equivalent (this was done for sake of simplicity). Leaving
ZFS_DEBUG_SET_ERROR unset suppresses the SET_ERROR() messages which
helps avoid cluttering up the logs.
To enable SET_ERROR() logging, run:
echo 1 > /sys/module/zfs/parameters/zfs_dbgmsg_enable
echo 512 > /sys/module/zfs/parameters/zfs_flags
Remove the zfs_set_error_class tracepoints event class since
SET_ERROR() now uses __dprintf(). This sacrifices a bit of
granularity when selecting individual tracepoint events to enable but
it makes the code simpler.
Include file, function, and line number information in debug log
entries. The information is now added to the message buffer in
__dprintf() and as a result the zfs_dprintf_class tracepoints event
class was changed from a 4 parameter interface to a single parameter.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ned Bass <[email protected]>
Closes #6400
Diffstat (limited to 'module')
-rw-r--r-- | module/zfs/zfs_debug.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/module/zfs/zfs_debug.c b/module/zfs/zfs_debug.c index 90c1d7361..d1dba3f8f 100644 --- a/module/zfs/zfs_debug.c +++ b/module/zfs/zfs_debug.c @@ -161,6 +161,13 @@ __zfs_dbgmsg(char *buf) mutex_exit(&zfs_dbgmsgs_lock); } +void +__set_error(const char *file, const char *func, int line, int err) +{ + if (zfs_flags & ZFS_DEBUG_SET_ERROR) + __dprintf(file, func, line, "error %lu", err); +} + #ifdef _KERNEL void __dprintf(const char *file, const char *func, int line, const char *fmt, ...) @@ -170,8 +177,10 @@ __dprintf(const char *file, const char *func, int line, const char *fmt, ...) size_t size; char *buf; char *nl; + int i; - if (!zfs_dbgmsg_enable && !(zfs_flags & ZFS_DEBUG_DPRINTF)) + if (!zfs_dbgmsg_enable && + !(zfs_flags & (ZFS_DEBUG_DPRINTF | ZFS_DEBUG_SET_ERROR))) return; size = 1024; @@ -187,9 +196,13 @@ __dprintf(const char *file, const char *func, int line, const char *fmt, ...) newfile = file; } - va_start(adx, fmt); - (void) vsnprintf(buf, size, fmt, adx); - va_end(adx); + i = snprintf(buf, size, "%s:%d:%s(): ", newfile, line, func); + + if (i < size) { + va_start(adx, fmt); + (void) vsnprintf(buf + i, size - i, fmt, adx); + va_end(adx); + } /* * Get rid of trailing newline. @@ -209,9 +222,8 @@ __dprintf(const char *file, const char *func, int line, const char *fmt, ...) * # Dump the ring buffer. * $ cat /sys/kernel/debug/tracing/trace */ - if (zfs_flags & ZFS_DEBUG_DPRINTF) - DTRACE_PROBE4(zfs__dprintf, - char *, newfile, char *, func, int, line, char *, buf); + if (zfs_flags & (ZFS_DEBUG_DPRINTF | ZFS_DEBUG_SET_ERROR)) + DTRACE_PROBE1(zfs__dprintf, char *, buf); /* * To get this data enable the zfs debug log as shown: |