Skip to contentSkip to conversation

btrfs-progs: Fix disable backtrace assert error

PATCH Superseded Qu Wenruo 3 participants 5 messages Jan 18, 2017 – Jan 19, 2017 Btrfs file system

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v3 1/1 btrfs-progs: Fix disable backtrace assert error

Due to commit 00e769d04c2c83029d6c71(btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON), which changed the assert_trace() parameter, the condition passed to assert/WARN_ON/BUG_ON are logical notted for backtrace enabled and disabled case.

Such behavior makes us easier to pass value wrong, and in fact it did cause us to pass wrong condition for ASSERT().

Instead of passing different conditions for ASSERT/WARN_ON/BUG_ON() manually, this patch will use ASSERT() to implement the resting ASSERT/WARN_ON/BUG(), so we don't need to pass 3 different conditions but only one.

Also, move WARN_ON() out of the ifdef branch, as it's completely the same for both branches.

Cc Goldwyn Rodrigues <[email protected]>

---
Sorry for late update, being digging the dev-replace/scrub bug

v2:
Keep ASSERT() outputing meaningful error string, use ASSERT() to implement BUG_ON() so only the abused BUG_ON() output is affected. Suggested by David.
v3:
Update commit message, since we use ASSERT() instead of BUG_ON() as main assert function now.

---
 kerncompat.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
kerncompat.h +5 -8
index 19ed3fc0..fe23774e 100644
@@ -291,18 +291,15 @@ static inline void assert_trace(const char *assertion, const char *filename,
 	abort();
 	exit(1);
 }
-
-#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
 #define	ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))
-#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
 #else
-#define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
-#define ASSERT(c) assert(!(c))
-#define BUG() assert(0)
+#define ASSERT(c) assert(c)
 #endif
 
+#define BUG_ON(c) ASSERT(!(c))
+#define BUG() BUG_ON(1)
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
+
 #define container_of(ptr, type, member) ({                      \
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 	        (type *)( (char *)__mptr - offsetof(type,member) );})
Signature · 1 line
2.11.0
#1 lore raw
Quoted 44 lines · Qu Wenruo

Due to commit 00e769d04c2c83029d6c71(btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON), which changed the assert_trace() parameter, the condition passed to assert/WARN_ON/BUG_ON are logical notted for backtrace enabled and disabled case.

Such behavior makes us easier to pass value wrong, and in fact it did cause us to pass wrong condition for ASSERT().

Instead of passing different conditions for ASSERT/WARN_ON/BUG_ON() manually, this patch will use ASSERT() to implement the resting ASSERT/WARN_ON/BUG(), so we don't need to pass 3 different conditions but only one.

Also, move WARN_ON() out of the ifdef branch, as it's completely the same for both branches.

Cc Goldwyn Rodrigues <[email protected]>

---
Sorry for late update, being digging the dev-replace/scrub bug

v2:
Keep ASSERT() outputing meaningful error string, use ASSERT() to implement BUG_ON() so only the abused BUG_ON() output is affected. Suggested by David.
v3:
Update commit message, since we use ASSERT() instead of BUG_ON() as main assert function now.

---
 kerncompat.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
kerncompat.h +0 -3
index 19ed3fc0..fe23774e 100644
@@ -291,18 +291,15 @@ static inline void assert_trace(const char *assertion, const char *filename,
 	abort();
 	exit(1);
 }
-
-#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
 #define	ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))

kerncompat.h static inline void assert_trace(const char *assertion, const char *filename, · line 299

Quoted 10 lines
kerncompat.h +2 -5
-#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
 #else
-#define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
-#define ASSERT(c) assert(!(c))
-#define BUG() assert(0)
+#define ASSERT(c) assert(c)
 #endif
 
+#define BUG_ON(c) ASSERT(!(c))

The problem with this is that you are killing the value printed as a part of the trace for BUG_ON(). The main reason why commit 00e769d04c2c83029d6c71 was written. Please be careful with your notting especially when the values are being printed.

Quoted 7 lines
kerncompat.h +3 -0
+#define BUG() BUG_ON(1)
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
+
 #define container_of(ptr, type, member) ({                      \
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 	        (type *)( (char *)__mptr - offsetof(type,member) );})
Signature · 1 line
Goldwyn
author
#2 lore raw
Quoted 56 lines · Goldwyn Rodrigues
Quoted 53 lines · Qu Wenruo

Due to commit 00e769d04c2c83029d6c71(btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON), which changed the assert_trace() parameter, the condition passed to assert/WARN_ON/BUG_ON are logical notted for backtrace enabled and disabled case.

Such behavior makes us easier to pass value wrong, and in fact it did cause us to pass wrong condition for ASSERT().

Instead of passing different conditions for ASSERT/WARN_ON/BUG_ON() manually, this patch will use ASSERT() to implement the resting ASSERT/WARN_ON/BUG(), so we don't need to pass 3 different conditions but only one.

Also, move WARN_ON() out of the ifdef branch, as it's completely the same for both branches.

Cc Goldwyn Rodrigues <[email protected]>

---
Sorry for late update, being digging the dev-replace/scrub bug

v2:
Keep ASSERT() outputing meaningful error string, use ASSERT() to implement BUG_ON() so only the abused BUG_ON() output is affected. Suggested by David.
v3:
Update commit message, since we use ASSERT() instead of BUG_ON() as main assert function now.

---
 kerncompat.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
kerncompat.h +1 -8
index 19ed3fc0..fe23774e 100644
@@ -291,18 +291,15 @@ static inline void assert_trace(const char *assertion, const char *filename,
 	abort();
 	exit(1);
 }
-
-#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
 #define	ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (long)!(c))
-#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
 #else
-#define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
-#define ASSERT(c) assert(!(c))
-#define BUG() assert(0)
+#define ASSERT(c) assert(c)
 #endif
 
Quoted 7 lines

kerncompat.h static inline void assert_trace(const char *assertion, const char *filename, · line 299

Quoted 1 line
kerncompat.h +1 -0
+#define BUG_ON(c) ASSERT(!(c))

The problem with this is that you are killing the value printed as a part of the trace for BUG_ON(). The main reason why commit 00e769d04c2c83029d6c71 was written. Please be careful with your notting especially when the values are being printed.

This is designed.

As ASSERT() is more meaningful than the abused BUG_ON(), I changed it to print correct value for ASSERT() and ignore BUG_ON().

Thanks,
Qu

Quoted 9 lines
Quoted 8 lines
kerncompat.h +3 -0
+#define BUG() BUG_ON(1)
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c))
+
 #define container_of(ptr, type, member) ({                      \
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 	        (type *)( (char *)__mptr - offsetof(type,member) );})
#3 lore raw
Quoted 72 lines · Qu Wenruo
Quoted 61 lines · Goldwyn Rodrigues
Quoted 58 lines · Qu Wenruo

Due to commit 00e769d04c2c83029d6c71(btrfs-progs: Correct value printed by assertions/BUG_ON/WARN_ON), which changed the assert_trace() parameter, the condition passed to assert/WARN_ON/BUG_ON are logical notted for backtrace enabled and disabled case.

Such behavior makes us easier to pass value wrong, and in fact it did cause us to pass wrong condition for ASSERT().

Instead of passing different conditions for ASSERT/WARN_ON/BUG_ON() manually, this patch will use ASSERT() to implement the resting ASSERT/WARN_ON/BUG(), so we don't need to pass 3 different conditions but only one.

Also, move WARN_ON() out of the ifdef branch, as it's completely the same for both branches.

Cc Goldwyn Rodrigues <[email protected]>

---
Sorry for late update, being digging the dev-replace/scrub bug

v2:
Keep ASSERT() outputing meaningful error string, use ASSERT() to implement BUG_ON() so only the abused BUG_ON() output is affected. Suggested by David.
v3:
Update commit message, since we use ASSERT() instead of BUG_ON() as main assert function now.

---
 kerncompat.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
kerncompat.h +1 -8
index 19ed3fc0..fe23774e 100644
@@ -291,18 +291,15 @@ static inline void assert_trace(const char
 *assertion, const char *filename,
     abort();
     exit(1);
 }
-
-#define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__,
 (long)(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
 (long)(c))
 #define    ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__,
 (long)!(c))
-#define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 1)
 #else
-#define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,
 (long)(c))
-#define ASSERT(c) assert(!(c))
-#define BUG() assert(0)
+#define ASSERT(c) assert(c)
 #endif
Quoted 7 lines
Quoted 1 line

+#define BUG_ON(c) ASSERT(!(c))

The problem with this is that you are killing the value printed as a part of the trace for BUG_ON(). The main reason why commit 00e769d04c2c83029d6c71 was written. Please be careful with your notting especially when the values are being printed.

Quoted 4 lines

This is designed.

As ASSERT() is more meaningful than the abused BUG_ON(), I changed it to print correct value for ASSERT() and ignore BUG_ON().

If ASSERT is meaningful, correct it. But please don't make BUG_ON worse and leave it as it is, at least until the time you can remove the BUG_ONs or convert it. It should print the correct value of why it did bug, or else it will print just 1, which is of no debug value.

Quoted 16 lines

Thanks,
Qu

Quoted 10 lines
Quoted 9 lines
kerncompat.h +2 -0
+#define BUG() BUG_ON(1)
+#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__,

(long)(c))
+

 #define container_of(ptr, type, member) ({                      \
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
             (type *)( (char *)__mptr - offsetof(type,member) );})
Signature · 1 line
Goldwyn
#4 lore raw
Quoted 10 lines · Goldwyn Rodrigues
Quoted 10 lines
Quoted 7 lines
Quoted 1 line

+#define BUG_ON(c) ASSERT(!(c))

The problem with this is that you are killing the value printed as a part of the trace for BUG_ON(). The main reason why commit 00e769d04c2c83029d6c71 was written. Please be careful with your notting especially when the values are being printed.

This is designed.

Quoted 7 lines
Quoted 2 lines

As ASSERT() is more meaningful than the abused BUG_ON(), I changed it to print correct value for ASSERT() and ignore BUG_ON().

If ASSERT is meaningful, correct it. But please don't make BUG_ON worse and leave it as it is, at least until the time you can remove the BUG_ONs or convert it. It should print the correct value of why it did bug, or else it will print just 1, which is of no debug value.

Agreed, we want to see the exact value.