2010-05-18 02:18:00 +04:00
|
|
|
/*****************************************************************************\
|
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 08:38:26 +04:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2013-03-05 05:26:55 +04:00
|
|
|
* For details, see <http://zfsonlinux.org/>.
|
2010-05-18 02:18:00 +04:00
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 08:38:26 +04:00
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 08:38:26 +04:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-18 02:18:00 +04:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
\*****************************************************************************/
|
2008-05-26 08:38:26 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
/*
|
|
|
|
* Available Solaris debug functions. All of the ASSERT() macros will be
|
|
|
|
* compiled out when NDEBUG is defined, this is the default behavior for
|
|
|
|
* the SPL. To enable assertions use the --enable-debug with configure.
|
|
|
|
* The VERIFY() functions are never compiled out and cannot be disabled.
|
|
|
|
*
|
|
|
|
* PANIC() - Panic the node and print message.
|
|
|
|
* ASSERT() - Assert X is true, if not panic.
|
|
|
|
* ASSERTF() - Assert X is true, if not panic and print message.
|
|
|
|
* ASSERTV() - Wraps a variable declaration which is only used by ASSERT().
|
|
|
|
* ASSERT3S() - Assert signed X OP Y is true, if not panic.
|
|
|
|
* ASSERT3U() - Assert unsigned X OP Y is true, if not panic.
|
|
|
|
* ASSERT3P() - Assert pointer X OP Y is true, if not panic.
|
2013-05-11 01:27:30 +04:00
|
|
|
* ASSERT0() - Assert value is zero, if not panic.
|
2010-07-20 01:16:05 +04:00
|
|
|
* VERIFY() - Verify X is true, if not panic.
|
|
|
|
* VERIFY3S() - Verify signed X OP Y is true, if not panic.
|
|
|
|
* VERIFY3U() - Verify unsigned X OP Y is true, if not panic.
|
|
|
|
* VERIFY3P() - Verify pointer X OP Y is true, if not panic.
|
2013-05-11 01:27:30 +04:00
|
|
|
* VERIFY0() - Verify value is zero, if not panic.
|
2010-07-20 01:16:05 +04:00
|
|
|
*/
|
|
|
|
|
2008-03-01 03:45:59 +03:00
|
|
|
#ifndef _SPL_DEBUG_H
|
|
|
|
#define _SPL_DEBUG_H
|
|
|
|
|
2012-01-21 04:39:12 +04:00
|
|
|
#include <spl-debug.h>
|
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#ifdef NDEBUG /* Debugging Disabled */
|
2008-05-19 06:49:12 +04:00
|
|
|
|
2010-07-21 02:25:45 +04:00
|
|
|
/* Define SPL_DEBUG_STR to make clear which ASSERT definitions are used */
|
|
|
|
#define SPL_DEBUG_STR ""
|
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define PANIC(fmt, a...) \
|
2014-06-19 00:22:50 +04:00
|
|
|
spl_PANIC(__FILE__, __FUNCTION__, __LINE__, fmt, ## a)
|
2008-05-19 06:49:12 +04:00
|
|
|
|
|
|
|
#define __ASSERT(x) ((void)0)
|
|
|
|
#define ASSERT(x) ((void)0)
|
2009-01-22 20:41:47 +03:00
|
|
|
#define ASSERTF(x, y, z...) ((void)0)
|
2009-07-09 23:15:23 +04:00
|
|
|
#define ASSERTV(x)
|
2010-07-20 01:16:05 +04:00
|
|
|
#define VERIFY(cond) \
|
2014-06-19 00:22:50 +04:00
|
|
|
(void)(unlikely(!(cond)) && \
|
|
|
|
spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"%s", "VERIFY(" #cond ") failed\n"))
|
2008-05-19 06:49:12 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
|
2014-06-19 00:22:50 +04:00
|
|
|
(void)((!((TYPE)(LEFT) OP (TYPE)(RIGHT))) && \
|
|
|
|
spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
|
2010-07-20 01:16:05 +04:00
|
|
|
"failed (" FMT " " #OP " " FMT ")\n", \
|
2014-06-19 00:22:50 +04:00
|
|
|
CAST (LEFT), CAST (RIGHT)))
|
2008-05-19 06:49:12 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
|
|
|
|
#define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
|
|
|
|
(unsigned long long))
|
|
|
|
#define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
|
2013-06-21 21:02:26 +04:00
|
|
|
#define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long))
|
2008-05-19 06:49:12 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define ASSERT3S(x,y,z) ((void)0)
|
|
|
|
#define ASSERT3U(x,y,z) ((void)0)
|
|
|
|
#define ASSERT3P(x,y,z) ((void)0)
|
2013-05-11 01:27:30 +04:00
|
|
|
#define ASSERT0(x) ((void)0)
|
2008-05-19 06:49:12 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#else /* Debugging Enabled */
|
2008-05-19 06:49:12 +04:00
|
|
|
|
2010-07-21 02:25:45 +04:00
|
|
|
/* Define SPL_DEBUG_STR to make clear which ASSERT definitions are used */
|
|
|
|
#define SPL_DEBUG_STR " (DEBUG mode)"
|
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define PANIC(fmt, a...) \
|
2014-06-19 00:22:50 +04:00
|
|
|
spl_PANIC(__FILE__, __FUNCTION__, __LINE__, fmt, ## a)
|
2008-04-21 21:29:47 +04:00
|
|
|
|
2008-04-19 03:39:58 +04:00
|
|
|
/* ASSERTION that is safe to use within the debug system */
|
2010-07-20 01:16:05 +04:00
|
|
|
#define __ASSERT(cond) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(!(cond))) { \
|
|
|
|
printk(KERN_EMERG "ASSERTION(" #cond ") failed\n"); \
|
|
|
|
BUG(); \
|
|
|
|
} \
|
2008-04-19 03:39:58 +04:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* ASSERTION that will debug log used outside the debug sysytem */
|
2010-07-20 01:16:05 +04:00
|
|
|
#define ASSERT(cond) \
|
2014-06-19 00:22:50 +04:00
|
|
|
(void)(unlikely(!(cond)) && \
|
|
|
|
spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"%s", "ASSERTION(" #cond ") failed\n"))
|
2008-04-19 03:39:58 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define ASSERTF(cond, fmt, a...) \
|
2014-06-19 00:22:50 +04:00
|
|
|
(void)(unlikely(!(cond)) && \
|
|
|
|
spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"ASSERTION(" #cond ") failed: " fmt, ## a))
|
2008-04-19 03:39:58 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE, FMT, CAST) \
|
2014-06-19 00:22:50 +04:00
|
|
|
(void)((!((TYPE)(LEFT) OP (TYPE)(RIGHT))) && \
|
|
|
|
spl_PANIC(__FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
|
2010-07-20 01:16:05 +04:00
|
|
|
"failed (" FMT " " #OP " " FMT ")\n", \
|
2014-06-19 00:22:50 +04:00
|
|
|
CAST (LEFT), CAST (RIGHT)))
|
2008-04-19 03:39:58 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define VERIFY3S(x,y,z) VERIFY3_IMPL(x, y, z, int64_t, "%lld", (long long))
|
|
|
|
#define VERIFY3U(x,y,z) VERIFY3_IMPL(x, y, z, uint64_t, "%llu", \
|
|
|
|
(unsigned long long))
|
|
|
|
#define VERIFY3P(x,y,z) VERIFY3_IMPL(x, y, z, uintptr_t, "%p", (void *))
|
2013-06-21 21:02:26 +04:00
|
|
|
#define VERIFY0(x) VERIFY3_IMPL(0, ==, x, int64_t, "%lld", (long long))
|
2008-04-19 03:39:58 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define ASSERT3S(x,y,z) VERIFY3S(x, y, z)
|
|
|
|
#define ASSERT3U(x,y,z) VERIFY3U(x, y, z)
|
|
|
|
#define ASSERT3P(x,y,z) VERIFY3P(x, y, z)
|
2013-05-11 01:27:30 +04:00
|
|
|
#define ASSERT0(x) VERIFY0(x)
|
2008-04-19 03:39:58 +04:00
|
|
|
|
2010-07-20 01:16:05 +04:00
|
|
|
#define ASSERTV(x) x
|
|
|
|
#define VERIFY(x) ASSERT(x)
|
2008-04-19 03:39:58 +04:00
|
|
|
|
2008-05-19 06:49:12 +04:00
|
|
|
#endif /* NDEBUG */
|
2013-11-01 20:14:05 +04:00
|
|
|
|
2014-06-19 00:22:50 +04:00
|
|
|
/*
|
|
|
|
* Helpers for the Solaris debug macros above
|
|
|
|
*/
|
|
|
|
extern int spl_PANIC(char *filename, const char *functionname,
|
|
|
|
int lineno, const char *fmt, ...);
|
|
|
|
|
2013-11-01 20:14:05 +04:00
|
|
|
/*
|
|
|
|
* Compile-time assertion. The condition 'x' must be constant.
|
|
|
|
*/
|
|
|
|
#define CTASSERT_GLOBAL(x) _CTASSERT(x, __LINE__)
|
|
|
|
#define CTASSERT(x) { _CTASSERT(x, __LINE__); }
|
|
|
|
#define _CTASSERT(x, y) __CTASSERT(x, y)
|
|
|
|
#define __CTASSERT(x, y) \
|
|
|
|
typedef char __attribute__ ((unused)) \
|
|
|
|
__compile_time_assertion__ ## y[(x) ? 1 : -1]
|
|
|
|
|
2008-03-01 03:45:59 +03:00
|
|
|
#endif /* SPL_DEBUG_H */
|