Skip to contentSkip to conversation

Btrfs: add support for asserts

PATCH In review Josef Bacik 5 participants 15 messages Aug 26, 2013 – Aug 28, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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,

---
 fs/btrfs/Kconfig |    9 +++++++++
 fs/btrfs/ctree.h |   16 ++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
fs/btrfs/Kconfig +9 -0
index 2b3b832..398cbd5 100644
@@ -72,3 +72,12 @@ config BTRFS_DEBUG
 	  performance, or export extra information via sysfs.
 
 	  If unsure, say N.
+
+config BTRFS_ASSERT
+	bool "Btrfs assert support"
+	depends on BTRFS_FS
+	help
+	  Enable run-time assertion checking.  This will result in panics if
+	  any of the assertions trip.  This is meant for btrfs developers only.
+
+	  If unsure, say N.
fs/btrfs/ctree.h +16 -0
index c90be01..8278a3f 100644
@@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 #define btrfs_debug(fs_info, fmt, args...) \
 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
 
+#ifdef BTRFS_ASSERT
+
+static inline void assfail(char *expr, char *file, int lin)
+{
+	printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d",
+	       expr, file, line);
+	BUG();
+}
+
+#define ASSERT(expr)	\
+	(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
+#else
+#define ASSERT(expr)	((void)0)
+#endif
+
+#define btrfs_assert()
 __printf(5, 6)
 void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
 		     unsigned int line, int errno, const char *fmt, ...);
Signature · 1 line
1.7.7.6
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Josef Bacik

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,

+1000 for inheriting the wildly popular XFS assfail() technology. ;)

I think this is a step in the right direction, it'll make it easier to clearly mark things which are logic assertions vs. things which are just punts in more common error-handling paths.

Thanks,

-Eric

Quoted 50 lines
---
 fs/btrfs/Kconfig |    9 +++++++++
 fs/btrfs/ctree.h |   16 ++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
fs/btrfs/Kconfig +9 -0
index 2b3b832..398cbd5 100644
@@ -72,3 +72,12 @@ config BTRFS_DEBUG
 	  performance, or export extra information via sysfs.
 
 	  If unsure, say N.
+
+config BTRFS_ASSERT
+	bool "Btrfs assert support"
+	depends on BTRFS_FS
+	help
+	  Enable run-time assertion checking.  This will result in panics if
+	  any of the assertions trip.  This is meant for btrfs developers only.
+
+	  If unsure, say N.
fs/btrfs/ctree.h +16 -0
index c90be01..8278a3f 100644
@@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 #define btrfs_debug(fs_info, fmt, args...) \
 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
 
+#ifdef BTRFS_ASSERT
+
+static inline void assfail(char *expr, char *file, int lin)
+{
+	printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d",
+	       expr, file, line);
+	BUG();
+}
+
+#define ASSERT(expr)	\
+	(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
+#else
+#define ASSERT(expr)	((void)0)
+#endif
+
+#define btrfs_assert()
 __printf(5, 6)
 void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
 		     unsigned int line, int errno, const char *fmt, ...);
#2 lore raw
In reply to Josef Bacik
Quoted 3 lines

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.

I like the sound of that!

Quoted 4 lines
fs/btrfs/ctree.h +0 -0
@@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 #define btrfs_debug(fs_info, fmt, args...) \

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3824

Quoted 10 lines
fs/btrfs/ctree.h +8 -0
 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
 
+#ifdef BTRFS_ASSERT
+
+static inline void assfail(char *expr, char *file, int lin)
+{
+	printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d",
+	       expr, file, line);
+	BUG();
+}

I'm not sure why this is needed.

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3827

Quoted 2 lines
fs/btrfs/ctree.h +2 -0
+#define ASSERT(expr)	\
+	(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))

(Passing the assertion is unlikely()? I know, this is from xfs... still.)

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3830

Quoted 3 lines
fs/btrfs/ctree.h +3 -0
+#else
+#define ASSERT(expr)	((void)0)
+#endif

Anyway, if you're going to do it this way, why not:

	#ifdef BTRFS_ASSERT
	#define btrfs_assert(cond)  BUG_ON(!(cond))
	#else
	#define btrfs_assert(cond)  do { if (cond) ; } while (0)
	#endif

?

- z

#3 lore raw
Quoted 12 lines · Zach Brown
Quoted 3 lines

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.

I like the sound of that!

Quoted 6 lines
fs/btrfs/ctree.h +0 -0
@@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 #define btrfs_debug(fs_info, fmt, args...) \
 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
 
Quoted 10 lines

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3824

Quoted 8 lines
fs/btrfs/ctree.h +8 -0
+#ifdef BTRFS_ASSERT
+
+static inline void assfail(char *expr, char *file, int lin)
+{
+	printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d",
+	       expr, file, line);
+	BUG();
+}

I'm not sure why this is needed.

I think it's because we'd like to see the assertion that failed in plain text, which then would need a function as above, but we'd rather not see that _every_ ASSERT() failure was at the line of the BUG() in the helper function...

i.e. when xfs trips it does this:

XFS: Assertion failed: first <= last && last < BBTOB(bp->b_length),
file: fs/xfs/xfs_trans_buf.c, line: 568

------------[ cut here ]------------
kernel BUG at fs/xfs/xfs_message.c:108!

note the 2 different line numbers; 568 is what's relevant, 108 is not.

Quoted 5 lines

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3827

Quoted 2 lines
fs/btrfs/ctree.h +2 -0
+#define ASSERT(expr)	\
+	(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))

(Passing the assertion is unlikely()? I know, this is from xfs... still.)

hah, that's great.

Quoted 11 lines

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3830

Quoted 3 lines
fs/btrfs/ctree.h +3 -0
+#else
+#define ASSERT(expr)	((void)0)
+#endif

Anyway, if you're going to do it this way, why not:

	#ifdef BTRFS_ASSERT
	#define btrfs_assert(cond)  BUG_ON(!(cond))
	#else
	#define btrfs_assert(cond)  do { if (cond) ; } while (0)
	#endif

I think the only downside is that the BUG_ON() won't print the conditional that failed, IIRC.

-Eric

Quoted 3 lines

?

- z

#4 lore raw
Quoted 8 lines
Quoted 5 lines
	#ifdef BTRFS_ASSERT
	#define btrfs_assert(cond)  BUG_ON(!(cond))
	#else
	#define btrfs_assert(cond)  do { if (cond) ; } while (0)
	#endif

I think the only downside is that the BUG_ON() won't print the conditional that failed, IIRC.

Sure, if you wanted to go the heavier informative route. I might also add format and args in that case.

- z

#5 lore raw
In reply to Zach Brown
Quoted 23 lines · Zach Brown
Quoted 3 lines

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.

I like the sound of that!

Quoted 4 lines
fs/btrfs/ctree.h +0 -0
@@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 #define btrfs_debug(fs_info, fmt, args...) \

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3824

Quoted 10 lines
fs/btrfs/ctree.h +8 -0
 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
 
+#ifdef BTRFS_ASSERT
+
+static inline void assfail(char *expr, char *file, int lin)
+{
+	printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d",
+	       expr, file, line);
+	BUG();
+}

I'm not sure why this is needed.

Quoted 6 lines

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3827

Quoted 2 lines
fs/btrfs/ctree.h +2 -0
+#define ASSERT(expr)	\
+	(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))

(Passing the assertion is unlikely()? I know, this is from xfs... still.)

Yeah I copy+pasted and then thought about it after I sent it. I will fix it up.

Quoted 6 lines

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3830

Quoted 3 lines
fs/btrfs/ctree.h +3 -0
+#else
+#define ASSERT(expr)	((void)0)
+#endif

Anyway, if you're going to do it this way, why not:

Quoted 6 lines
	#ifdef BTRFS_ASSERT
	#define btrfs_assert(cond)  BUG_ON(!(cond))
	#else
	#define btrfs_assert(cond)  do { if (cond) ; } while (0)
	#endif

I like the verbosity, especially with random kernel versions and such, it will help me figure out where we BUG_ON()'ed without having to checkout a particular version and go hunting. Thanks,

Josef

#6 lore raw
Quoted 46 lines · Josef Bacik
Quoted 23 lines · Zach Brown
Quoted 3 lines

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.

I like the sound of that!

Quoted 4 lines
fs/btrfs/ctree.h +0 -0
@@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 #define btrfs_debug(fs_info, fmt, args...) \

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3824

Quoted 10 lines
fs/btrfs/ctree.h +8 -0
 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
 
+#ifdef BTRFS_ASSERT
+
+static inline void assfail(char *expr, char *file, int lin)
+{
+	printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d",
+	       expr, file, line);
+	BUG();
+}

I'm not sure why this is needed.

Quoted 6 lines

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3827

Quoted 2 lines
fs/btrfs/ctree.h +2 -0
+#define ASSERT(expr)	\
+	(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))

(Passing the assertion is unlikely()? I know, this is from xfs... still.)

Yeah I copy+pasted and then thought about it after I sent it. I will fix it up.

Quoted 6 lines

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3830

Quoted 3 lines
fs/btrfs/ctree.h +3 -0
+#else
+#define ASSERT(expr)	((void)0)
+#endif

Anyway, if you're going to do it this way, why not:

Quoted 6 lines
	#ifdef BTRFS_ASSERT
	#define btrfs_assert(cond)  BUG_ON(!(cond))
	#else
	#define btrfs_assert(cond)  do { if (cond) ; } while (0)
	#endif
Quoted 3 lines

I like the verbosity, especially with random kernel versions and such, it will help me figure out where we BUG_ON()'ed without having to checkout a particular version and go hunting. Thanks,

Agreed. One of the positives of the obnoxious reiserfs warning IDs is that it uniquely identifies a call site across kernel versions. You can tell at a glance that it's the same failure you may have been chasing for a while. Anything to make the ID-at-a-glance easy is worth it.

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#7 lore raw
In reply to Josef Bacik
Quoted 9 lines · Josef Bacik

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,

I don't think the complaint is so much about the number of BUG_ONs, but that there's no distinction between something that is supposed to be impossible and something that is improbable. The BUG_ONs to keep code correctness are good and are littered all over the kernel with positive results. The BUG_ONs that are there in place of real error handling served their purpose and need to be replaced.

So, I don't know if it's a net win to compile the "good" BUG_ONs out of the code. Especially if a user runs into something strange yet familiar and the first response is "oh, huh, can you rebuild with asserts enabled?"

For the call sites that are unimplemented error handling, something to annotate those so that we can keep track of them and gradually eliminate those too would be good, though.

-Jeff

Quoted 51 lines
---
 fs/btrfs/Kconfig |    9 +++++++++
 fs/btrfs/ctree.h |   16 ++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
fs/btrfs/Kconfig +9 -0
index 2b3b832..398cbd5 100644
@@ -72,3 +72,12 @@ config BTRFS_DEBUG
 	  performance, or export extra information via sysfs.
 
 	  If unsure, say N.
+
+config BTRFS_ASSERT
+	bool "Btrfs assert support"
+	depends on BTRFS_FS
+	help
+	  Enable run-time assertion checking.  This will result in panics if
+	  any of the assertions trip.  This is meant for btrfs developers only.
+
+	  If unsure, say N.
fs/btrfs/ctree.h +16 -0
index c90be01..8278a3f 100644
@@ -3814,6 +3814,22 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 #define btrfs_debug(fs_info, fmt, args...) \
 	btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
 
+#ifdef BTRFS_ASSERT
+
+static inline void assfail(char *expr, char *file, int lin)
+{
+	printk(KERN_ERR "BTRFS assertion failed: %s, file: %s, line: %d",
+	       expr, file, line);
+	BUG();
+}
+
+#define ASSERT(expr)	\
+	(unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
+#else
+#define ASSERT(expr)	((void)0)
+#endif
+
+#define btrfs_assert()
 __printf(5, 6)
 void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
 		     unsigned int line, int errno, const char *fmt, ...);
Signature · 2 lines
Jeff Mahoney
SUSE Labs
#8 lore raw
Quoted 18 lines · Jeff Mahoney
Quoted 9 lines · Josef Bacik

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,

I don't think the complaint is so much about the number of BUG_ONs, but that there's no distinction between something that is supposed to be impossible and something that is improbable. The BUG_ONs to keep code correctness are good and are littered all over the kernel with positive results. The BUG_ONs that are there in place of real error handling served their purpose and need to be replaced.

Quoted 4 lines

So, I don't know if it's a net win to compile the "good" BUG_ONs out of the code. Especially if a user runs into something strange yet familiar and the first response is "oh, huh, can you rebuild with asserts enabled?"

Either I provide an option for it or distros do it themselves, this cuts out the middle man. I'd really rather they just be on all the time since they aren't things we should hit anyway, but at least this way people have a choice. Thanks,

#9 lore raw
Quoted 19 lines · Josef Bacik
Quoted 18 lines · Jeff Mahoney
Quoted 9 lines · Josef Bacik

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,

I don't think the complaint is so much about the number of BUG_ONs, but that there's no distinction between something that is supposed to be impossible and something that is improbable. The BUG_ONs to keep code correctness are good and are littered all over the kernel with positive results. The BUG_ONs that are there in place of real error handling served their purpose and need to be replaced.

Quoted 8 lines
Quoted 4 lines

So, I don't know if it's a net win to compile the "good" BUG_ONs out of the code. Especially if a user runs into something strange yet familiar and the first response is "oh, huh, can you rebuild with asserts enabled?"

Either I provide an option for it or distros do it themselves, this cuts out the middle man. I'd really rather they just be on all the time since they aren't things we should hit anyway, but at least this way people have a choice.

Ok. With my distro hat on, I can tell you I'll be leaving them on. :)

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#10 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 25 lines · Jeff Mahoney
Quoted 24 lines · Josef Bacik
Quoted 22 lines · Jeff Mahoney
Quoted 9 lines · Josef Bacik

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,

I don't think the complaint is so much about the number of BUG_ONs, but that there's no distinction between something that is supposed to be impossible and something that is improbable. The BUG_ONs to keep code correctness are good and are littered all over the kernel with positive results. The BUG_ONs that are there in place of real error handling served their purpose and need to be replaced.

So, I don't know if it's a net win to compile the "good" BUG_ONs out of the code. Especially if a user runs into something strange yet familiar and the first response is "oh, huh, can you rebuild with asserts enabled?"

Quoted 7 lines
Quoted 3 lines

Either I provide an option for it or distros do it themselves, this cuts out the middle man. I'd really rather they just be on all the time since they aren't things we should hit anyway, but at least this way people have a choice.

Ok. With my distro hat on, I can tell you I'll be leaving them on. :)

-Jeff

XFS also has XFS_WARN as a config option, which keeps all the assertions in place, but printk's & backtraces w/o the icky BUG(). That might be good to add as well, and perhaps best for a shipping distro (vs. a developer debugging who might want to drop a core file when the assert trips).

- -Eric

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJSHRhOAAoJECCuFpLhPd7gYbcP/034ADG3dwTa83FaAWuAurg7 byKWG4EwRqt3PYjUgruxBJAc426O7tz6j1NNTrAwZys9/GJOsisPShA8gO0f+W/A +bQZJlXoUMbbwVPMcCqsnKMKlXNyKoqgME9AUQOrzMB/SgDtC9Y/OgdqgWF/58UV X1KC3OOtcfQr/1t19AZuNhJ5oHfytoscv3nnnW5872t1JtL8daomak4fyDuRKgRV 45kQ726nafUlXNmi1TG8GadlcmKxxbBm0vt2ui6RtZWVauPE4Gej+iEUux9WtwSc 48eOQ5iqbFVzC8v++Rc1eT28mBIjSetr+O/Tk+VL4TvYCKA2trMAltNAFinv9AB0 Q+Z9F1K26aFe/Z/gcM57j+c0VOkv1tvSElF1iJcVHPuRvV7k+548g+KVzbXNDPBP vuV2fnUCpw/XHQlrI+efYLs7Ies0TuV2eGPhmbKWjhossPwOeng71zxuiXSbNMBE gVcHg6idXjCdaCCIYuJr8+5K4ngnpTEbAUs4C2x6iHzuHZcXScEHWYU/nHvizElL bCZ162QSeQZAd+NgSzoZSmv4XqFMj6c4q60XvhAuu3fpkVPVY4GshcFhT14Onhfl /054HqdQIXjUGOdbeuUwmXoaqzpSKDhBmZ0G+ykarD1KRCaEW61JrnFepRPO7G69 Q3oiPIbvdvCw3BZAJaGL
=7vvX
-----END PGP SIGNATURE-----

#11 lore raw
Quoted 30 lines · Eric Sandeen
Quoted 28 lines · Jeff Mahoney
Quoted 27 lines · Josef Bacik
Quoted 18 lines · Jeff Mahoney
Quoted 9 lines · Josef Bacik

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,

I don't think the complaint is so much about the number of BUG_ONs, but that there's no distinction between something that is supposed to be impossible and something that is improbable. The BUG_ONs to keep code correctness are good and are littered all over the kernel with positive results. The BUG_ONs that are there in place of real error handling served their purpose and need to be replaced.

Quoted 4 lines

So, I don't know if it's a net win to compile the "good" BUG_ONs out of the code. Especially if a user runs into something strange yet familiar and the first response is "oh, huh, can you rebuild with asserts enabled?"

Either I provide an option for it or distros do it themselves, this cuts out the middle man. I'd really rather they just be on all the time since they aren't things we should hit anyway, but at least this way people have a choice.

Quoted 8 lines
Quoted 3 lines

Ok. With my distro hat on, I can tell you I'll be leaving them on. :)

-Jeff

XFS also has XFS_WARN as a config option, which keeps all the assertions in place, but printk's & backtraces w/o the icky BUG(). That might be good to add as well, and perhaps best for a shipping distro (vs. a developer debugging who might want to drop a core file when the assert trips).

Isn't that the distinction between BUG_ON and WARN_ON? If it's worth a BUG_ON, things should be bad enough (or could result in being bad enough) that we want to bail out.

-Jeff

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#12 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 40 lines · Jeff Mahoney
Quoted 30 lines · Eric Sandeen
Quoted 28 lines · Jeff Mahoney
Quoted 27 lines · Josef Bacik
Quoted 18 lines · Jeff Mahoney
Quoted 9 lines · Josef Bacik

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,

I don't think the complaint is so much about the number of BUG_ONs, but that there's no distinction between something that is supposed to be impossible and something that is improbable. The BUG_ONs to keep code correctness are good and are littered all over the kernel with positive results. The BUG_ONs that are there in place of real error handling served their purpose and need to be replaced.

Quoted 4 lines

So, I don't know if it's a net win to compile the "good" BUG_ONs out of the code. Especially if a user runs into something strange yet familiar and the first response is "oh, huh, can you rebuild with asserts enabled?"

Either I provide an option for it or distros do it themselves, this cuts out the middle man. I'd really rather they just be on all the time since they aren't things we should hit anyway, but at least this way people have a choice.

Quoted 8 lines
Quoted 3 lines

Ok. With my distro hat on, I can tell you I'll be leaving them on. :)

-Jeff

XFS also has XFS_WARN as a config option, which keeps all the assertions in place, but printk's & backtraces w/o the icky BUG(). That might be good to add as well, and perhaps best for a shipping distro (vs. a developer debugging who might want to drop a core file when the assert trips).

Quoted 5 lines

Isn't that the distinction between BUG_ON and WARN_ON? If it's worth a BUG_ON, things should be bad enough (or could result in being bad enough) that we want to bail out.

-Jeff

Maybe; just FWIW here was Dave's rationale for xfs. Right now btrfs doesn't have the behavior-changing side effect (no BTRFS_DEBUG config) though, so maybe the distinction is less important...

xfs: introduce CONFIG_XFS_WARN

Running a CONFIG_XFS_DEBUG kernel in production environments is not the best idea as it introduces significant overhead, can change the behaviour of algorithms (such as allocation) to improve test coverage, and (most importantly) panic the machine on non-fatal errors.

There are many cases where all we want to do is run a kernel with more bounds checking enabled, such as is provided by the ASSERT() statements throughout the code, but without all the potential overhead and drawbacks.

This patch converts all the ASSERT statements to evaluate as WARN_ON(1) statements and hence if they fail dump a warning and a stack trace to the log. This has minimal overhead and does not change any algorithms, and will allow us to find strange "out of bounds" problems more easily on production machines.

There are a few places where assert statements contain debug only code. These are converted to be debug-or-warn only code so that we still get all the assert checks in the code.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJSHRn5AAoJECCuFpLhPd7gpsQQAJlFGX/t9b/LASxSisiv/wdL ZoQXHhCzxpzVVdsWstzOY0bVXw8vdsG2E+nmih2S6T7AzkoqPDoEnYE9CqpNQFFy Ca/kJOcfE1T4mIwKZwLHATkJX0V/S6nY7jPa7xdcseie+1H7ldSPaM5Jb6fkvXg/ 8lNPTikGeoRJdUwQN4xxNgsivITfJpl65Z+AVg5UAUqqUKZtYZLfVeAlyQFKvOyl /am80yLLzhFODtV3GcWkaYcInBaB2AaVlqHrpTnf53gG9JGynyFjnZGlysz0flSs wstNKLOon+wNBg1Dz0HrUSVma87g5hc1WtaZFC/qI3uHuoatsxOWxG6+LXZlr2CN Jsq3ZwHHxOs4MLgyEYlSirpgKqn/aKA+J8O0mNlltBj2lpU2hKgPS7dmMw5o8VAM 1uei1er15eBlCY0uBncRXIcLEcXfRXo9b69ErQBIbCN7xrGyWdbZ/DVtElaFeImh Lw+iBXebBbw6SCqCMZFc3vpYdF+9RP6shImBlsqxTzKs5M1gISrFtCF0GqOuPrWt 7jyrredhpKACAaOpxPW8UWh2vL+q51JWzzZKYE35Gy4M/8E64TQ0rYhLGj7x+TYU FWYzpONK0x7XbmgtEKTutwi9w+vfSlMzFNpUavwFeTZIh8Dw1tEO3dBn59Rs9Oz8 Widxpe+hqz/qK/0O4rTb
=4nmO
-----END PGP SIGNATURE-----

#13 lore raw
Quoted 45 lines · Eric Sandeen
Quoted 43 lines · Jeff Mahoney
Quoted 30 lines · Eric Sandeen
Quoted 28 lines · Jeff Mahoney
Quoted 27 lines · Josef Bacik
Quoted 18 lines · Jeff Mahoney
Quoted 9 lines · Josef Bacik

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,

I don't think the complaint is so much about the number of BUG_ONs, but that there's no distinction between something that is supposed to be impossible and something that is improbable. The BUG_ONs to keep code correctness are good and are littered all over the kernel with positive results. The BUG_ONs that are there in place of real error handling served their purpose and need to be replaced.

Quoted 4 lines

So, I don't know if it's a net win to compile the "good" BUG_ONs out of the code. Especially if a user runs into something strange yet familiar and the first response is "oh, huh, can you rebuild with asserts enabled?"

Either I provide an option for it or distros do it themselves, this cuts out the middle man. I'd really rather they just be on all the time since they aren't things we should hit anyway, but at least this way people have a choice.

Quoted 8 lines
Quoted 3 lines

Ok. With my distro hat on, I can tell you I'll be leaving them on. :)

-Jeff

XFS also has XFS_WARN as a config option, which keeps all the assertions in place, but printk's & backtraces w/o the icky BUG(). That might be good to add as well, and perhaps best for a shipping distro (vs. a developer debugging who might want to drop a core file when the assert trips).

Isn't that the distinction between BUG_ON and WARN_ON? If it's worth a BUG_ON, things should be bad enough (or could result in being bad enough) that we want to bail out.

Quoted 5 lines
Quoted 1 line

-Jeff

Maybe; just FWIW here was Dave's rationale for xfs. Right now btrfs doesn't have the behavior-changing side effect (no BTRFS_DEBUG config) though, so maybe the distinction is less important...

Yeah, I'd agree with the distinction not being there in btrfs (yet). ReiserFS has a similar mode where there are a ton of checks that are optionally enabled and does invasive things that can slow things down. It's disabled pretty much universally AFAIK. One of the things (low) on my TODO list is to go through all of those and move them into regular checks since some of them are the types of things fsfuzzer likes to trip over.

-Jeff

Quoted 27 lines

xfs: introduce CONFIG_XFS_WARN

Running a CONFIG_XFS_DEBUG kernel in production environments is not the best idea as it introduces significant overhead, can change the behaviour of algorithms (such as allocation) to improve test coverage, and (most importantly) panic the machine on non-fatal errors.

There are many cases where all we want to do is run a kernel with more bounds checking enabled, such as is provided by the ASSERT() statements throughout the code, but without all the potential overhead and drawbacks.

This patch converts all the ASSERT statements to evaluate as WARN_ON(1) statements and hence if they fail dump a warning and a stack trace to the log. This has minimal overhead and does not change any algorithms, and will allow us to find strange "out of bounds" problems more easily on production machines.

There are a few places where assert statements contain debug only code. These are converted to be debug-or-warn only code so that we still get all the assert checks in the code.

Signature · 2 lines
Jeff Mahoney
SUSE Labs
#14 lore raw
In reply to Josef Bacik

fs/btrfs/ctree.h void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) · line 3819

Quoted 3 lines · Josef Bacik
fs/btrfs/ctree.h +3 -0
+#ifdef BTRFS_ASSERT
+
+static inline void assfail(char *expr, char *file, int lin)

typo: lin instead of line