diff options
author | Josef Bacik <jbacik@fusionio.com> | 2013-08-26 16:53:15 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2013-09-01 08:16:32 -0400 |
commit | 2e17c7c65e5dcbb53a6384a3406244f62bca189c (patch) | |
tree | 9c4c368a46a5e34b4406ad9d5f966596f35b834f /fs | |
parent | 726551ebc79c0a41f66376463ebe8c84c89c1151 (diff) |
Btrfs: add support for asserts
One of the complaints we get a lot is how many BUG_ON()'s we have. So to help
with this I'm introducing a kconfig option to enable/disable a new ASSERT()
mechanism much like what XFS does. This will allow us developers to still get
our nice panics but allow users/distros to compile them out. With this we can
go through and convert any BUG_ON()'s that we have to catch actual programming
mistakes to the new ASSERT() and then fix everybody else to return errors. This
will also allow developers to leave sanity checks in their new code to make sure
we don't trip over problems while testing stuff and vetting new features.
Thanks,
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/Kconfig | 9 | ||||
-rw-r--r-- | fs/btrfs/ctree.h | 16 |
2 files changed, 25 insertions, 0 deletions
diff --git a/fs/btrfs/Kconfig b/fs/btrfs/Kconfig index 2b3b83296977..398cbd517be2 100644 --- a/fs/btrfs/Kconfig +++ b/fs/btrfs/Kconfig | |||
@@ -72,3 +72,12 @@ config BTRFS_DEBUG | |||
72 | performance, or export extra information via sysfs. | 72 | performance, or export extra information via sysfs. |
73 | 73 | ||
74 | If unsure, say N. | 74 | If unsure, say N. |
75 | |||
76 | config BTRFS_ASSERT | ||
77 | bool "Btrfs assert support" | ||
78 | depends on BTRFS_FS | ||
79 | help | ||
80 | Enable run-time assertion checking. This will result in panics if | ||
81 | any of the assertions trip. This is meant for btrfs developers only. | ||
82 | |||
83 | If unsure, say N. | ||
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index c90be01cbe67..1f3fd584e5f4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) | |||
3814 | #define btrfs_debug(fs_info, fmt, args...) \ | 3814 | #define btrfs_debug(fs_info, fmt, args...) \ |
3815 | btrfs_printk(fs_info, KERN_DEBUG fmt, ##args) | 3815 | btrfs_printk(fs_info, KERN_DEBUG fmt, ##args) |
3816 | 3816 | ||
3817 | #ifdef CONFIG_BTRFS_ASSERT | ||
3818 | |||
3819 | static inline void assfail(char *expr, char *file, int line) | ||
3820 | { | ||
3821 | printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d", | ||
3822 | expr, file, line); | ||
3823 | BUG(); | ||
3824 | } | ||
3825 | |||
3826 | #define ASSERT(expr) \ | ||
3827 | (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) | ||
3828 | #else | ||
3829 | #define ASSERT(expr) ((void)0) | ||
3830 | #endif | ||
3831 | |||
3832 | #define btrfs_assert() | ||
3817 | __printf(5, 6) | 3833 | __printf(5, 6) |
3818 | void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function, | 3834 | void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function, |
3819 | unsigned int line, int errno, const char *fmt, ...); | 3835 | unsigned int line, int errno, const char *fmt, ...); |