mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-04 09:09:56 +00:00
Swap DTRACE_PROBE* with Linux tracepoints
This patch leverages Linux tracepoints from within the ZFS on Linux code base. It also refactors the debug code to bring it back in sync with Illumos. The information exported via tracepoints can be used for a variety of reasons (e.g. debugging, tuning, general exploration/understanding, etc). It is advantageous to use Linux tracepoints as the mechanism to export this kind of information (as opposed to something else) for a number of reasons: * A number of external tools can make use of our tracepoints "automatically" (e.g. perf, systemtap) * Tracepoints are designed to be extremely cheap when disabled * It's one of the "accepted" ways to export this kind of information; many other kernel subsystems use tracepoints too. Unfortunately, though, there are a few caveats as well: * Linux tracepoints appear to only be available to GPL licensed modules due to the way certain kernel functions are exported. Thus, to actually make use of the tracepoints introduced by this patch, one might have to patch and re-compile the kernel; exporting the necessary functions to non-GPL modules. * Prior to upstream kernel version v3.14-rc6-30-g66cc69e, Linux tracepoints are not available for unsigned kernel modules (tracepoints will get disabled due to the module's 'F' taint). Thus, one either has to sign the zfs kernel module prior to loading it, or use a kernel versioned v3.14-rc6-30-g66cc69e or newer. Assuming the above two requirements are satisfied, lets look at an example of how this patch can be used and what information it exposes (all commands run as 'root'): # list all zfs tracepoints available $ ls /sys/kernel/debug/tracing/events/zfs enable filter zfs_arc__delete zfs_arc__evict zfs_arc__hit zfs_arc__miss zfs_l2arc__evict zfs_l2arc__hit zfs_l2arc__iodone zfs_l2arc__miss zfs_l2arc__read zfs_l2arc__write zfs_new_state__mfu zfs_new_state__mru # enable all zfs tracepoints, clear the tracepoint ring buffer $ echo 1 > /sys/kernel/debug/tracing/events/zfs/enable $ echo 0 > /sys/kernel/debug/tracing/trace # import zpool called 'tank', inspect tracepoint data (each line was # truncated, they're too long for a commit message otherwise) $ zpool import tank $ cat /sys/kernel/debug/tracing/trace | head -n35 # tracer: nop # # entries-in-buffer/entries-written: 1219/1219 #P:8 # # _-----=> irqs-off # / _----=> need-resched # | / _---=> hardirq/softirq # || / _--=> preempt-depth # ||| / delay # TASK-PID CPU# |||| TIMESTAMP FUNCTION # | | | |||| | | lt-zpool-30132 [003] .... 91344.200050: zfs_arc__miss: hdr... z_rd_int/0-30156 [003] .... 91344.200611: zfs_new_state__mru... lt-zpool-30132 [003] .... 91344.201173: zfs_arc__miss: hdr... z_rd_int/1-30157 [003] .... 91344.201756: zfs_new_state__mru... lt-zpool-30132 [003] .... 91344.201795: zfs_arc__miss: hdr... z_rd_int/2-30158 [003] .... 91344.202099: zfs_new_state__mru... lt-zpool-30132 [003] .... 91344.202126: zfs_arc__hit: hdr ... lt-zpool-30132 [003] .... 91344.202130: zfs_arc__hit: hdr ... lt-zpool-30132 [003] .... 91344.202134: zfs_arc__hit: hdr ... lt-zpool-30132 [003] .... 91344.202146: zfs_arc__miss: hdr... z_rd_int/3-30159 [003] .... 91344.202457: zfs_new_state__mru... lt-zpool-30132 [003] .... 91344.202484: zfs_arc__miss: hdr... z_rd_int/4-30160 [003] .... 91344.202866: zfs_new_state__mru... lt-zpool-30132 [003] .... 91344.202891: zfs_arc__hit: hdr ... lt-zpool-30132 [001] .... 91344.203034: zfs_arc__miss: hdr... z_rd_iss/1-30149 [001] .... 91344.203749: zfs_new_state__mru... lt-zpool-30132 [001] .... 91344.203789: zfs_arc__hit: hdr ... lt-zpool-30132 [001] .... 91344.203878: zfs_arc__miss: hdr... z_rd_iss/3-30151 [001] .... 91344.204315: zfs_new_state__mru... lt-zpool-30132 [001] .... 91344.204332: zfs_arc__hit: hdr ... lt-zpool-30132 [001] .... 91344.204337: zfs_arc__hit: hdr ... lt-zpool-30132 [001] .... 91344.204352: zfs_arc__hit: hdr ... lt-zpool-30132 [001] .... 91344.204356: zfs_arc__hit: hdr ... lt-zpool-30132 [001] .... 91344.204360: zfs_arc__hit: hdr ... To highlight the kind of detailed information that is being exported using this infrastructure, I've taken the first tracepoint line from the output above and reformatted it such that it fits in 80 columns: lt-zpool-30132 [003] .... 91344.200050: zfs_arc__miss: hdr { dva 0x1:0x40082 birth 15491 cksum0 0x163edbff3a flags 0x640 datacnt 1 type 1 size 2048 spa 3133524293419867460 state_type 0 access 0 mru_hits 0 mru_ghost_hits 0 mfu_hits 0 mfu_ghost_hits 0 l2_hits 0 refcount 1 } bp { dva0 0x1:0x40082 dva1 0x1:0x3000e5 dva2 0x1:0x5a006e cksum 0x163edbff3a:0x75af30b3dd6:0x1499263ff5f2b:0x288bd118815e00 lsize 2048 } zb { objset 0 object 0 level -1 blkid 0 } For the specific tracepoint shown here, 'zfs_arc__miss', data is exported detailing the arc_buf_hdr_t (hdr), blkptr_t (bp), and zbookmark_t (zb) that caused the ARC miss (down to the exact DVA!). This kind of precise and detailed information can be extremely valuable when trying to answer certain kinds of questions. For anybody unfamiliar but looking to build on this, I found the XFS source code along with the following three web links to be extremely helpful: * http://lwn.net/Articles/379903/ * http://lwn.net/Articles/381064/ * http://lwn.net/Articles/383362/ I should also node the more "boring" aspects of this patch: * The ZFS_LINUX_COMPILE_IFELSE autoconf macro was modified to support a sixth paramter. This parameter is used to populate the contents of the new conftest.h file. If no sixth parameter is provided, conftest.h will be empty. * The ZFS_LINUX_TRY_COMPILE_HEADER autoconf macro was introduced. This macro is nearly identical to the ZFS_LINUX_TRY_COMPILE macro, except it has support for a fifth option that is then passed as the sixth parameter to ZFS_LINUX_COMPILE_IFELSE. These autoconf changes were needed to test the availability of the Linux tracepoint macros. Due to the odd nature of the Linux tracepoint macro API, a separate ".h" must be created (the path and filename is used internally by the kernel's define_trace.h file). * The HAVE_DECLARE_EVENT_CLASS autoconf macro was introduced. This is to determine if we can safely enable the Linux tracepoint functionality. We need to selectively disable the tracepoint code due to the kernel exporting certain functions as GPL only. Without this check, the build process will fail at link time. In addition, the SET_ERROR macro was modified into a tracepoint as well. To do this, the 'sdt.h' file was moved into the 'include/sys' directory and now contains a userspace portion and a kernel space portion. The dprintf and zfs_dbgmsg* interfaces are now implemented as tracepoint as well. Signed-off-by: Prakash Surya <surya1@llnl.gov> Signed-off-by: Ned Bass <bass6@llnl.gov> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
This commit is contained in:
parent
5024046763
commit
0b39b9f96f
59
config/kernel-declare-event-class.m4
Normal file
59
config/kernel-declare-event-class.m4
Normal file
@ -0,0 +1,59 @@
|
||||
dnl #
|
||||
dnl # Ensure the DECLARE_EVENT_CLASS macro is available to non-GPL modules.
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_AC_KERNEL_DECLARE_EVENT_CLASS], [
|
||||
tmp_flags="$EXTRA_KCFLAGS"
|
||||
EXTRA_KCFLAGS="-I\$(src)"
|
||||
|
||||
AC_MSG_CHECKING([whether DECLARE_EVENT_CLASS() is available])
|
||||
ZFS_LINUX_TRY_COMPILE_HEADER([
|
||||
#include <linux/module.h>
|
||||
MODULE_LICENSE(ZFS_META_LICENSE);
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include "conftest.h"
|
||||
],[
|
||||
trace_zfs_autoconf_event_one(1UL);
|
||||
trace_zfs_autoconf_event_two(2UL);
|
||||
],[
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_DECLARE_EVENT_CLASS, 1,
|
||||
[DECLARE_EVENT_CLASS() is available])
|
||||
],[
|
||||
AC_MSG_RESULT(no)
|
||||
],[
|
||||
#if !defined(_CONFTEST_H) || defined(TRACE_HEADER_MULTI_READ)
|
||||
#define _CONFTEST_H
|
||||
|
||||
#undef TRACE_SYSTEM
|
||||
#define TRACE_SYSTEM zfs
|
||||
#include <linux/tracepoint.h>
|
||||
|
||||
DECLARE_EVENT_CLASS(zfs_autoconf_event_class,
|
||||
TP_PROTO(unsigned long i),
|
||||
TP_ARGS(i),
|
||||
TP_STRUCT__entry(
|
||||
__field(unsigned long, i)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->i = i;
|
||||
),
|
||||
TP_printk("i = %lu", __entry->i)
|
||||
);
|
||||
|
||||
#define DEFINE_AUTOCONF_EVENT(name) \
|
||||
DEFINE_EVENT(zfs_autoconf_event_class, name, \
|
||||
TP_PROTO(unsigned long i), \
|
||||
TP_ARGS(i))
|
||||
DEFINE_AUTOCONF_EVENT(zfs_autoconf_event_one);
|
||||
DEFINE_AUTOCONF_EVENT(zfs_autoconf_event_two);
|
||||
|
||||
#endif /* _CONFTEST_H */
|
||||
|
||||
#undef TRACE_INCLUDE_PATH
|
||||
#define TRACE_INCLUDE_PATH .
|
||||
#define TRACE_INCLUDE_FILE conftest
|
||||
#include <trace/define_trace.h>
|
||||
])
|
||||
EXTRA_KCFLAGS="$tmp_flags"
|
||||
])
|
@ -6,6 +6,7 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
|
||||
ZFS_AC_SPL
|
||||
ZFS_AC_TEST_MODULE
|
||||
ZFS_AC_KERNEL_CONFIG
|
||||
ZFS_AC_KERNEL_DECLARE_EVENT_CLASS
|
||||
ZFS_AC_KERNEL_BDEV_BLOCK_DEVICE_OPERATIONS
|
||||
ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
|
||||
ZFS_AC_KERNEL_TYPE_FMODE_T
|
||||
@ -506,9 +507,18 @@ AC_DEFUN([ZFS_AC_KERNEL_CONFIG_DEBUG_LOCK_ALLOC], [
|
||||
])
|
||||
|
||||
dnl #
|
||||
dnl # ZFS_LINUX_CONFTEST
|
||||
dnl # ZFS_LINUX_CONFTEST_H
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_LINUX_CONFTEST], [
|
||||
AC_DEFUN([ZFS_LINUX_CONFTEST_H], [
|
||||
cat - <<_ACEOF >conftest.h
|
||||
$1
|
||||
_ACEOF
|
||||
])
|
||||
|
||||
dnl #
|
||||
dnl # ZFS_LINUX_CONFTEST_C
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_LINUX_CONFTEST_C], [
|
||||
cat confdefs.h - <<_ACEOF >conftest.c
|
||||
$1
|
||||
_ACEOF
|
||||
@ -534,13 +544,14 @@ dnl #
|
||||
dnl # ZFS_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_LINUX_COMPILE_IFELSE], [
|
||||
m4_ifvaln([$1], [ZFS_LINUX_CONFTEST([$1])])
|
||||
m4_ifvaln([$1], [ZFS_LINUX_CONFTEST_C([$1])])
|
||||
m4_ifvaln([$6], [ZFS_LINUX_CONFTEST_H([$6])], [ZFS_LINUX_CONFTEST_H([])])
|
||||
rm -Rf build && mkdir -p build && touch build/conftest.mod.c
|
||||
echo "obj-m := conftest.o" >build/Makefile
|
||||
modpost_flag=''
|
||||
test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
|
||||
AS_IF(
|
||||
[AC_TRY_COMMAND(cp conftest.c build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
|
||||
[AC_TRY_COMMAND(cp conftest.c conftest.h build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
|
||||
[$4],
|
||||
[_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
|
||||
)
|
||||
@ -627,3 +638,16 @@ AC_DEFUN([ZFS_LINUX_TRY_COMPILE_SYMBOL], [
|
||||
fi
|
||||
fi
|
||||
])
|
||||
|
||||
dnl #
|
||||
dnl # ZFS_LINUX_TRY_COMPILE_HEADER
|
||||
dnl # like ZFS_LINUX_TRY_COMPILE, except the contents conftest.h are
|
||||
dnl # provided via the fifth parameter
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_LINUX_TRY_COMPILE_HEADER],
|
||||
[ZFS_LINUX_COMPILE_IFELSE(
|
||||
[AC_LANG_SOURCE([ZFS_LANG_PROGRAM([[$1]], [[$2]])])],
|
||||
[modules],
|
||||
[test -s build/conftest.o],
|
||||
[$3], [$4], [AC_LANG_SOURCE([$5])])
|
||||
])
|
||||
|
@ -40,11 +40,13 @@ COMMON_H = \
|
||||
$(top_srcdir)/include/sys/rrwlock.h \
|
||||
$(top_srcdir)/include/sys/sa.h \
|
||||
$(top_srcdir)/include/sys/sa_impl.h \
|
||||
$(top_srcdir)/include/sys/sdt.h \
|
||||
$(top_srcdir)/include/sys/spa_boot.h \
|
||||
$(top_srcdir)/include/sys/space_map.h \
|
||||
$(top_srcdir)/include/sys/space_reftree.h \
|
||||
$(top_srcdir)/include/sys/spa.h \
|
||||
$(top_srcdir)/include/sys/spa_impl.h \
|
||||
$(top_srcdir)/include/sys/trace.h \
|
||||
$(top_srcdir)/include/sys/txg.h \
|
||||
$(top_srcdir)/include/sys/txg_impl.h \
|
||||
$(top_srcdir)/include/sys/u8_textprep_data.h \
|
||||
|
70
include/sys/sdt.h
Normal file
70
include/sys/sdt.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* The contents of this file are subject to the terms of the
|
||||
* Common Development and Distribution License, Version 1.0 only
|
||||
* (the "License"). You may not use this file except in compliance
|
||||
* with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
* or http://www.opensolaris.org/os/licensing.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL HEADER in each
|
||||
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||
* If applicable, add the following below this CDDL HEADER, with the
|
||||
* fields enclosed by brackets "[]" replaced with your own identifying
|
||||
* information: Portions Copyright [yyyy] [name of copyright owner]
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_SDT_H
|
||||
#define _SYS_SDT_H
|
||||
|
||||
#ifndef _KERNEL
|
||||
|
||||
#define ZFS_PROBE(a) ((void) 0)
|
||||
#define ZFS_PROBE1(a, c) ((void) 0)
|
||||
#define ZFS_PROBE2(a, c, e) ((void) 0)
|
||||
#define ZFS_PROBE3(a, c, e, g) ((void) 0)
|
||||
#define ZFS_PROBE4(a, c, e, g, i) ((void) 0)
|
||||
#define ZFS_SET_ERROR(err) ((void) 0)
|
||||
|
||||
#else
|
||||
|
||||
#if defined(HAVE_DECLARE_EVENT_CLASS)
|
||||
|
||||
#include <sys/trace.h>
|
||||
|
||||
/*
|
||||
* The set-error SDT probe is extra static, in that we declare its fake
|
||||
* function literally, rather than with the DTRACE_PROBE1() macro. This is
|
||||
* necessary so that SET_ERROR() can evaluate to a value, which wouldn't
|
||||
* be possible if it required multiple statements (to declare the function
|
||||
* and then call it).
|
||||
*
|
||||
* SET_ERROR() uses the comma operator so that it can be used without much
|
||||
* additional code. For example, "return (EINVAL);" becomes
|
||||
* "return (SET_ERROR(EINVAL));". Note that the argument will be evaluated
|
||||
* twice, so it should not have side effects (e.g. something like:
|
||||
* "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice).
|
||||
*/
|
||||
#define SET_ERROR(err) \
|
||||
(trace_zfs_set__error(__FILE__, __func__, __LINE__, err), err)
|
||||
|
||||
#else
|
||||
|
||||
#undef SET_ERROR
|
||||
#define SET_ERROR(err) (err)
|
||||
|
||||
#endif /* HAVE_DECLARE_EVENT_CLASS */
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* _SYS_SDT_H */
|
1038
include/sys/trace.h
Normal file
1038
include/sys/trace.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -66,6 +66,7 @@
|
||||
#include <sys/sunddi.h>
|
||||
#include <sys/ctype.h>
|
||||
#include <sys/disp.h>
|
||||
#include <sys/trace.h>
|
||||
#include <linux/dcache_compat.h>
|
||||
#include <linux/utsname_compat.h>
|
||||
|
||||
@ -140,15 +141,12 @@
|
||||
#define CE_PANIC 3 /* panic */
|
||||
#define CE_IGNORE 4 /* print nothing */
|
||||
|
||||
extern int aok;
|
||||
|
||||
/*
|
||||
* ZFS debugging
|
||||
*/
|
||||
|
||||
extern void dprintf_setup(int *argc, char **argv);
|
||||
extern void __dprintf(const char *file, const char *func,
|
||||
int line, const char *fmt, ...);
|
||||
|
||||
extern void cmn_err(int, const char *, ...);
|
||||
extern void vcmn_err(int, const char *, va_list);
|
||||
extern void panic(const char *, ...);
|
||||
@ -156,7 +154,8 @@ extern void vpanic(const char *, va_list);
|
||||
|
||||
#define fm_panic panic
|
||||
|
||||
#ifdef __sun
|
||||
extern int aok;
|
||||
|
||||
/*
|
||||
* DTrace SDT probes have different signatures in userland than they do in
|
||||
* kernel. If they're being used in kernel code, re-define them out of
|
||||
@ -202,9 +201,6 @@ extern void vpanic(const char *, va_list);
|
||||
* "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice).
|
||||
*/
|
||||
#define SET_ERROR(err) (ZFS_SET_ERROR(err), err)
|
||||
#else
|
||||
#define SET_ERROR(err) (err)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Threads. TS_STACK_MIN is dictated by the minimum allowed pthread stack
|
||||
|
@ -38,14 +38,6 @@ extern "C" {
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ZFS debugging - Always enabled for user space builds.
|
||||
*/
|
||||
|
||||
#if !defined(ZFS_DEBUG) && !defined(_KERNEL)
|
||||
#define ZFS_DEBUG
|
||||
#endif
|
||||
|
||||
extern int zfs_flags;
|
||||
extern int zfs_recover;
|
||||
extern int zfs_free_leak_on_eio;
|
||||
@ -59,29 +51,15 @@ extern int zfs_free_leak_on_eio;
|
||||
#define ZFS_DEBUG_ZIO_FREE (1<<6)
|
||||
#define ZFS_DEBUG_HISTOGRAM_VERIFY (1<<7)
|
||||
|
||||
/*
|
||||
* Always log zfs debug messages to the spl debug subsystem as SS_USER1.
|
||||
* When the SPL is configured with debugging enabled these messages will
|
||||
* appear in the internal spl debug log, otherwise they are a no-op.
|
||||
*/
|
||||
#if defined(_KERNEL)
|
||||
|
||||
#include <spl-debug.h>
|
||||
#define dprintf(...) \
|
||||
if (zfs_flags & ZFS_DEBUG_DPRINTF) \
|
||||
__SDEBUG(NULL, SS_USER1, SD_DPRINTF, __VA_ARGS__)
|
||||
|
||||
/*
|
||||
* When zfs is running is user space the debugging is always enabled.
|
||||
* The messages will be printed using the __dprintf() function and
|
||||
* filtered based on the zfs_flags variable.
|
||||
*/
|
||||
#else
|
||||
#define dprintf(...) \
|
||||
if (zfs_flags & ZFS_DEBUG_DPRINTF) \
|
||||
#if defined(HAVE_DECLARE_EVENT_CLASS) || !defined(_KERNEL)
|
||||
extern void __dprintf(const char *file, const char *func,
|
||||
int line, const char *fmt, ...);
|
||||
#define dprintf(...) \
|
||||
if (zfs_flags & ZFS_DEBUG_DPRINTF) \
|
||||
__dprintf(__FILE__, __func__, __LINE__, __VA_ARGS__)
|
||||
|
||||
#endif /* _KERNEL */
|
||||
#else
|
||||
#define dprintf(...) ((void)0)
|
||||
#endif /* HAVE_DECLARE_EVENT_CLASS || !_KERNEL */
|
||||
|
||||
extern void zfs_panic_recover(const char *fmt, ...);
|
||||
|
||||
@ -93,12 +71,8 @@ typedef struct zfs_dbgmsg {
|
||||
|
||||
extern void zfs_dbgmsg_init(void);
|
||||
extern void zfs_dbgmsg_fini(void);
|
||||
#if defined(_KERNEL) && defined(__linux__)
|
||||
#define zfs_dbgmsg(...) dprintf(__VA_ARGS__)
|
||||
#else
|
||||
extern void zfs_dbgmsg(const char *fmt, ...);
|
||||
extern void zfs_dbgmsg_print(const char *tag);
|
||||
#endif
|
||||
|
||||
#ifndef _KERNEL
|
||||
extern int dprintf_find_string(const char *string);
|
||||
|
@ -33,7 +33,6 @@ libspl_HEADERS = \
|
||||
$(top_srcdir)/lib/libspl/include/sys/param.h \
|
||||
$(top_srcdir)/lib/libspl/include/sys/priv.h \
|
||||
$(top_srcdir)/lib/libspl/include/sys/processor.h \
|
||||
$(top_srcdir)/lib/libspl/include/sys/sdt.h \
|
||||
$(top_srcdir)/lib/libspl/include/sys/stack.h \
|
||||
$(top_srcdir)/lib/libspl/include/sys/stat.h \
|
||||
$(top_srcdir)/lib/libspl/include/sys/stropts.h \
|
||||
|
@ -70,6 +70,7 @@ libzpool_la_SOURCES = \
|
||||
$(top_srcdir)/module/zfs/space_map.c \
|
||||
$(top_srcdir)/module/zfs/space_reftree.c \
|
||||
$(top_srcdir)/module/zfs/txg.c \
|
||||
$(top_srcdir)/module/zfs/trace.c \
|
||||
$(top_srcdir)/module/zfs/uberblock.c \
|
||||
$(top_srcdir)/module/zfs/unique.c \
|
||||
$(top_srcdir)/module/zfs/vdev.c \
|
||||
|
@ -52,6 +52,7 @@ $(MODULE)-objs += @top_srcdir@/module/zfs/spa_stats.o
|
||||
$(MODULE)-objs += @top_srcdir@/module/zfs/space_map.o
|
||||
$(MODULE)-objs += @top_srcdir@/module/zfs/space_reftree.o
|
||||
$(MODULE)-objs += @top_srcdir@/module/zfs/txg.o
|
||||
$(MODULE)-objs += @top_srcdir@/module/zfs/trace.o
|
||||
$(MODULE)-objs += @top_srcdir@/module/zfs/uberblock.o
|
||||
$(MODULE)-objs += @top_srcdir@/module/zfs/unique.o
|
||||
$(MODULE)-objs += @top_srcdir@/module/zfs/vdev.o
|
||||
|
@ -238,6 +238,53 @@ static avl_tree_t spa_l2cache_avl;
|
||||
kmem_cache_t *spa_buffer_pool;
|
||||
int spa_mode_global;
|
||||
|
||||
#ifdef ZFS_DEBUG
|
||||
/* Everything except dprintf and spa is on by default in debug builds */
|
||||
int zfs_flags = ~(ZFS_DEBUG_DPRINTF | ZFS_DEBUG_SPA);
|
||||
#else
|
||||
int zfs_flags = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* This should only be used as a last resort, as it typically results
|
||||
* in leaked space, or worse.
|
||||
*/
|
||||
int zfs_recover = B_FALSE;
|
||||
|
||||
/*
|
||||
* If destroy encounters an EIO while reading metadata (e.g. indirect
|
||||
* blocks), space referenced by the missing metadata can not be freed.
|
||||
* Normally this causes the background destroy to become "stalled", as
|
||||
* it is unable to make forward progress. While in this stalled state,
|
||||
* all remaining space to free from the error-encountering filesystem is
|
||||
* "temporarily leaked". Set this flag to cause it to ignore the EIO,
|
||||
* permanently leak the space from indirect blocks that can not be read,
|
||||
* and continue to free everything else that it can.
|
||||
*
|
||||
* The default, "stalling" behavior is useful if the storage partially
|
||||
* fails (i.e. some but not all i/os fail), and then later recovers. In
|
||||
* this case, we will be able to continue pool operations while it is
|
||||
* partially failed, and when it recovers, we can continue to free the
|
||||
* space, with no leaks. However, note that this case is actually
|
||||
* fairly rare.
|
||||
*
|
||||
* Typically pools either (a) fail completely (but perhaps temporarily,
|
||||
* e.g. a top-level vdev going offline), or (b) have localized,
|
||||
* permanent errors (e.g. disk returns the wrong data due to bit flip or
|
||||
* firmware bug). In case (a), this setting does not matter because the
|
||||
* pool will be suspended and the sync thread will not be able to make
|
||||
* forward progress regardless. In case (b), because the error is
|
||||
* permanent, the best we can do is leak the minimum amount of space,
|
||||
* which is what setting this flag will do. Therefore, it is reasonable
|
||||
* for this flag to normally be set, but we chose the more conservative
|
||||
* approach of not setting it, so that there is no possibility of
|
||||
* leaking space in the "partial temporary" failure case.
|
||||
*/
|
||||
int zfs_free_leak_on_eio = B_FALSE;
|
||||
|
||||
/*
|
||||
* Expiration time in milliseconds. This value has two meanings. First it is
|
||||
* used to determine when the spa_deadman() logic should fire. By default the
|
||||
@ -1319,6 +1366,16 @@ spa_freeze(spa_t *spa)
|
||||
txg_wait_synced(spa_get_dsl(spa), freeze_txg);
|
||||
}
|
||||
|
||||
void
|
||||
zfs_panic_recover(const char *fmt, ...)
|
||||
{
|
||||
va_list adx;
|
||||
|
||||
va_start(adx, fmt);
|
||||
vcmn_err(zfs_recover ? CE_WARN : CE_PANIC, fmt, adx);
|
||||
va_end(adx);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a stripped-down version of strtoull, suitable only for converting
|
||||
* lowercase hexadecimal numbers that don't overflow.
|
||||
@ -1923,6 +1980,16 @@ EXPORT_SYMBOL(spa_mode);
|
||||
|
||||
EXPORT_SYMBOL(spa_namespace_lock);
|
||||
|
||||
module_param(zfs_flags, int, 0644);
|
||||
MODULE_PARM_DESC(zfs_flags, "Set additional debugging flags");
|
||||
|
||||
module_param(zfs_recover, int, 0644);
|
||||
MODULE_PARM_DESC(zfs_recover, "Set to attempt to recover from fatal errors");
|
||||
|
||||
module_param(zfs_free_leak_on_eio, int, 0644);
|
||||
MODULE_PARM_DESC(zfs_free_leak_on_eio,
|
||||
"Set to ignore IO errors during free and permanently leak the space");
|
||||
|
||||
module_param(zfs_deadman_synctime_ms, ulong, 0644);
|
||||
MODULE_PARM_DESC(zfs_deadman_synctime_ms, "Expiration time in milliseconds");
|
||||
|
||||
|
@ -2,9 +2,8 @@
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* The contents of this file are subject to the terms of the
|
||||
* Common Development and Distribution License, Version 1.0 only
|
||||
* (the "License"). You may not use this file except in compliance
|
||||
* with the License.
|
||||
* Common Development and Distribution License (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
* or http://www.opensolaris.org/os/licensing.
|
||||
@ -20,17 +19,21 @@
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
* Each Linux tracepoints subsystem must define CREATE_TRACE_POINTS in one
|
||||
* (and only one) C file, so this dummy file exists for that purpose.
|
||||
*/
|
||||
|
||||
#ifndef _LIBSPL_SYS_SDT_H
|
||||
#define _LIBSPL_SYS_SDT_H
|
||||
#include <sys/arc_impl.h>
|
||||
#include <sys/vdev_impl.h>
|
||||
#include <sys/zio.h>
|
||||
#include <sys/dbuf.h>
|
||||
#include <sys/dmu_objset.h>
|
||||
#include <sys/dsl_dataset.h>
|
||||
#include <sys/dmu_tx.h>
|
||||
#include <sys/dnode.h>
|
||||
#include <sys/zfs_znode.h>
|
||||
#include <sys/zil_impl.h>
|
||||
#include <sys/zrlock.h>
|
||||
|
||||
#define DTRACE_PROBE(a) ((void) 0)
|
||||
#define DTRACE_PROBE1(a, b, c) ((void) 0)
|
||||
#define DTRACE_PROBE2(a, b, c, d, e) ((void) 0)
|
||||
#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void) 0)
|
||||
#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void) 0)
|
||||
|
||||
#endif
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include <sys/trace.h>
|
@ -25,99 +25,22 @@
|
||||
|
||||
#include <sys/zfs_context.h>
|
||||
|
||||
#if !defined(_KERNEL) || !defined(__linux__)
|
||||
list_t zfs_dbgmsgs;
|
||||
int zfs_dbgmsg_size;
|
||||
kmutex_t zfs_dbgmsgs_lock;
|
||||
int zfs_dbgmsg_maxsize = 4<<20; /* 4MB */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* This should only be used as a last resort, as it typically results
|
||||
* in leaked space, or worse.
|
||||
*/
|
||||
int zfs_recover = B_FALSE;
|
||||
|
||||
/*
|
||||
* If destroy encounters an EIO while reading metadata (e.g. indirect
|
||||
* blocks), space referenced by the missing metadata can not be freed.
|
||||
* Normally this causes the background destroy to become "stalled", as
|
||||
* it is unable to make forward progress. While in this stalled state,
|
||||
* all remaining space to free from the error-encountering filesystem is
|
||||
* "temporarily leaked". Set this flag to cause it to ignore the EIO,
|
||||
* permanently leak the space from indirect blocks that can not be read,
|
||||
* and continue to free everything else that it can.
|
||||
*
|
||||
* The default, "stalling" behavior is useful if the storage partially
|
||||
* fails (i.e. some but not all i/os fail), and then later recovers. In
|
||||
* this case, we will be able to continue pool operations while it is
|
||||
* partially failed, and when it recovers, we can continue to free the
|
||||
* space, with no leaks. However, note that this case is actually
|
||||
* fairly rare.
|
||||
*
|
||||
* Typically pools either (a) fail completely (but perhaps temporarily,
|
||||
* e.g. a top-level vdev going offline), or (b) have localized,
|
||||
* permanent errors (e.g. disk returns the wrong data due to bit flip or
|
||||
* firmware bug). In case (a), this setting does not matter because the
|
||||
* pool will be suspended and the sync thread will not be able to make
|
||||
* forward progress regardless. In case (b), because the error is
|
||||
* permanent, the best we can do is leak the minimum amount of space,
|
||||
* which is what setting this flag will do. Therefore, it is reasonable
|
||||
* for this flag to normally be set, but we chose the more conservative
|
||||
* approach of not setting it, so that there is no possibility of
|
||||
* leaking space in the "partial temporary" failure case.
|
||||
*/
|
||||
int zfs_free_leak_on_eio = B_FALSE;
|
||||
|
||||
|
||||
void
|
||||
zfs_panic_recover(const char *fmt, ...)
|
||||
{
|
||||
va_list adx;
|
||||
|
||||
va_start(adx, fmt);
|
||||
vcmn_err(zfs_recover ? CE_WARN : CE_PANIC, fmt, adx);
|
||||
va_end(adx);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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_init(void)
|
||||
{
|
||||
#if !defined(_KERNEL) || !defined(__linux__)
|
||||
list_create(&zfs_dbgmsgs, sizeof (zfs_dbgmsg_t),
|
||||
offsetof(zfs_dbgmsg_t, zdm_node));
|
||||
mutex_init(&zfs_dbgmsgs_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
#endif
|
||||
|
||||
if (zfs_flags == 0) {
|
||||
#if defined(_KERNEL)
|
||||
zfs_flags = ZFS_DEBUG_DPRINTF;
|
||||
spl_debug_set_mask(spl_debug_get_mask() | SD_DPRINTF);
|
||||
spl_debug_set_subsys(spl_debug_get_subsys() | SS_USER1);
|
||||
#else
|
||||
zfs_flags = ~ZFS_DEBUG_DPRINTF;
|
||||
#endif /* _KERNEL */
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
zfs_dbgmsg_fini(void)
|
||||
{
|
||||
#if !defined(_KERNEL) || !defined(__linux__)
|
||||
zfs_dbgmsg_t *zdm;
|
||||
|
||||
while ((zdm = list_remove_head(&zfs_dbgmsgs)) != NULL) {
|
||||
@ -127,25 +50,24 @@ zfs_dbgmsg_fini(void)
|
||||
}
|
||||
mutex_destroy(&zfs_dbgmsgs_lock);
|
||||
ASSERT0(zfs_dbgmsg_size);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(_KERNEL) || !defined(__linux__)
|
||||
/*
|
||||
* Print these messages by running:
|
||||
* echo ::zfs_dbgmsg | mdb -k
|
||||
* To get this data enable the zfs__dbgmsg tracepoint as shown:
|
||||
*
|
||||
* Monitor these messages by running:
|
||||
* dtrace -qn 'zfs-dbgmsg{printf("%s\n", stringof(arg0))}'
|
||||
* # Enable zfs__dbgmsg tracepoint, clear the tracepoint ring buffer
|
||||
* $ echo 1 > /sys/kernel/debug/tracing/events/zfs/enable
|
||||
* $ echo 0 > /sys/kernel/debug/tracing/trace
|
||||
*
|
||||
* When used with libzpool, monitor with:
|
||||
* dtrace -qn 'zfs$pid::zfs_dbgmsg:probe1{printf("%s\n", copyinstr(arg1))}'
|
||||
* # Dump the ring buffer.
|
||||
* $ cat /sys/kernel/debug/tracing/trace
|
||||
*/
|
||||
void
|
||||
zfs_dbgmsg(const char *fmt, ...)
|
||||
{
|
||||
int size;
|
||||
va_list adx;
|
||||
char *nl;
|
||||
zfs_dbgmsg_t *zdm;
|
||||
|
||||
va_start(adx, fmt);
|
||||
@ -156,13 +78,20 @@ zfs_dbgmsg(const char *fmt, ...)
|
||||
* 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 = kmem_alloc(sizeof (zfs_dbgmsg_t) + size, KM_PUSHPAGE);
|
||||
zdm->zdm_timestamp = gethrestime_sec();
|
||||
|
||||
va_start(adx, fmt);
|
||||
(void) vsnprintf(zdm->zdm_msg, size + 1, fmt, adx);
|
||||
va_end(adx);
|
||||
|
||||
/*
|
||||
* Get rid of trailing newline.
|
||||
*/
|
||||
nl = strrchr(zdm->zdm_msg, '\n');
|
||||
if (nl != NULL)
|
||||
*nl = '\0';
|
||||
|
||||
DTRACE_PROBE1(zfs__dbgmsg, char *, zdm->zdm_msg);
|
||||
|
||||
mutex_enter(&zfs_dbgmsgs_lock);
|
||||
@ -180,6 +109,7 @@ zfs_dbgmsg(const char *fmt, ...)
|
||||
void
|
||||
zfs_dbgmsg_print(const char *tag)
|
||||
{
|
||||
#if !defined(_KERNEL)
|
||||
zfs_dbgmsg_t *zdm;
|
||||
|
||||
(void) printf("ZFS_DBGMSG(%s):\n", tag);
|
||||
@ -188,17 +118,5 @@ zfs_dbgmsg_print(const char *tag)
|
||||
zdm = list_next(&zfs_dbgmsgs, zdm))
|
||||
(void) printf("%s\n", zdm->zdm_msg);
|
||||
mutex_exit(&zfs_dbgmsgs_lock);
|
||||
#endif /* !_KERNEL */
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_KERNEL)
|
||||
module_param(zfs_flags, int, 0644);
|
||||
MODULE_PARM_DESC(zfs_flags, "Set additional debugging flags");
|
||||
|
||||
module_param(zfs_recover, int, 0644);
|
||||
MODULE_PARM_DESC(zfs_recover, "Set to attempt to recover from fatal errors");
|
||||
|
||||
module_param(zfs_free_leak_on_eio, int, 0644);
|
||||
MODULE_PARM_DESC(zfs_free_leak_on_eio,
|
||||
"Set to ignore IO errors during free and permanently leak the space");
|
||||
#endif /* _KERNEL */
|
||||
|
@ -247,6 +247,55 @@ static int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
|
||||
int zfs_set_prop_nvlist(const char *, zprop_source_t, nvlist_t *, nvlist_t *);
|
||||
static int get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp);
|
||||
|
||||
#if defined(HAVE_DECLARE_EVENT_CLASS)
|
||||
void
|
||||
__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
|
||||
{
|
||||
const char *newfile;
|
||||
size_t size = 4096;
|
||||
char *buf = kmem_alloc(size, KM_PUSHPAGE);
|
||||
char *nl;
|
||||
va_list adx;
|
||||
|
||||
/*
|
||||
* Get rid of annoying prefix to filename.
|
||||
*/
|
||||
newfile = strrchr(file, '/');
|
||||
if (newfile != NULL) {
|
||||
newfile = newfile + 1; /* Get rid of leading / */
|
||||
} else {
|
||||
newfile = file;
|
||||
}
|
||||
|
||||
va_start(adx, fmt);
|
||||
(void) vsnprintf(buf, size, fmt, adx);
|
||||
va_end(adx);
|
||||
|
||||
/*
|
||||
* Get rid of trailing newline.
|
||||
*/
|
||||
nl = strrchr(buf, '\n');
|
||||
if (nl != NULL)
|
||||
*nl = '\0';
|
||||
|
||||
/*
|
||||
* To get this data enable the zfs__dprintf trace point as shown:
|
||||
*
|
||||
* # Enable zfs__dprintf tracepoint, clear the tracepoint ring buffer
|
||||
* $ echo 1 > /sys/module/zfs/parameters/zfs_flags
|
||||
* $ echo 1 > /sys/kernel/debug/tracing/events/zfs/enable
|
||||
* $ echo 0 > /sys/kernel/debug/tracing/trace
|
||||
*
|
||||
* # Dump the ring buffer.
|
||||
* $ cat /sys/kernel/debug/tracing/trace
|
||||
*/
|
||||
DTRACE_PROBE4(zfs__dprintf,
|
||||
char *, newfile, char *, func, int, line, char *, buf);
|
||||
|
||||
kmem_free(buf, size);
|
||||
}
|
||||
#endif /* HAVE_DECLARE_EVENT_CLASS */
|
||||
|
||||
static void
|
||||
history_str_free(char *buf)
|
||||
{
|
||||
|
@ -33,7 +33,6 @@ MODULE-OPTIONS:
|
||||
|
||||
$0 zfs="zfs_prefetch_disable=1"
|
||||
$0 zfs="zfs_prefetch_disable=1 zfs_mdcomp_disable=1"
|
||||
$0 spl="spl_debug_mask=0"
|
||||
|
||||
EOF
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user