All of lore.kernel.org
 help / color / mirror / Atom feed
From: Naohiro Aota <naota@elisp.net>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC] btrfs-progs: Show backtrace on BUGs
Date: Thu, 21 Aug 2014 21:04:07 +0900	[thread overview]
Message-ID: <87zjey82x4.fsf@elisp.net> (raw)

"btrfs check" is still under heavy development and so there are some
BUGs beging hit. "btrfs check" can be run on limited environment which
lacks gdb to debug the abort in detail. If we could see backtrace, it
will be easier to find a root cause of the BUG.

Following is my "btrfs check" output with and without the patch.

without patch:

ref mismatch on [1437411180544 16384] extent item 3, found 2
btrfs: extent_io.c:612: free_extent_buffer: Assertion `!(eb->flags & 1)' failed.
enabling repair mode
Checking filesystem on /dev/sdb2
UUID: a53121ee-679f-4241-bb44-ceb5a1a7beb7

with patch:

ref mismatch on [1437411180544 16384] extent item 3, found 2
btrfs check(free_extent_buffer+0xa3)[0x808ff89]
btrfs check[0x8090222]
btrfs check(alloc_extent_buffer+0xa7)[0x80903d0]
btrfs check(btrfs_find_create_tree_block+0x2e)[0x807edef]
btrfs check(btrfs_alloc_free_block+0x299)[0x808a3c4]
btrfs check(__btrfs_cow_block+0x1d4)[0x8078896]
btrfs check(btrfs_cow_block+0x150)[0x807934d]
btrfs check(btrfs_search_slot+0x136)[0x807c041]
btrfs check[0x8065a6b]
btrfs check[0x806bc0f]
btrfs check(cmd_check+0xc8f)[0x806d03a]
btrfs check(main+0x167)[0x804f5ec]
/lib/libc.so.6(__libc_start_main+0xe6)[0xf754c4f6]
btrfs check[0x804f061]
btrfsck: extent_io.c:612: free_extent_buffer: Assertion `!(eb->flags & 1)' failed.
enabling repair mode
Checking filesystem on /dev/sdb2
UUID: a53121ee-679f-4241-bb44-ceb5a1a7beb7

Now it's much clear that there's something wrong around
alloc_extent_buffer.

Signed-off-by: Naohiro Aota <naota@elisp.net>
---
 Makefile     |  2 +-
 kerncompat.h | 29 ++++++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 76565e8..9db5441 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CC = gcc
 LN = ln
 AR = ar
 AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -DBTRFS_FLAT_INCLUDES -fno-strict-aliasing -fPIC
-CFLAGS = -g -O1 -fno-strict-aliasing
+CFLAGS = -g -O1 -fno-strict-aliasing -rdynamic
 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
 	  root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
 	  extent-cache.o extent_io.o volumes.o utils.o repair.o \
diff --git a/kerncompat.h b/kerncompat.h
index f370cd8..94fadc8 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -27,6 +27,7 @@
 #include <byteswap.h>
 #include <assert.h>
 #include <stddef.h>
+#include <execinfo.h>
 #include <linux/types.h>
 
 #ifndef READ
@@ -50,7 +51,18 @@
 #define ULONG_MAX       (~0UL)
 #endif
 
-#define BUG() assert(0)
+#define MAX_BACKTRACE 128
+#define show_trace()						\
+	do {							\
+		void *trace[MAX_BACKTRACE];			\
+		int n = backtrace(trace, MAX_BACKTRACE);	\
+		backtrace_symbols_fd(trace, n, 2);		\
+	} while(0)
+#define BUG()					\
+	do {					\
+		show_trace();			\
+		assert(0);			\
+	} while(0)
 #ifdef __CHECKER__
 #define __force    __attribute__((force))
 #define __bitwise__ __attribute__((bitwise))
@@ -233,8 +245,19 @@ static inline long IS_ERR(const void *ptr)
 #define kstrdup(x, y) strdup(x)
 #define kfree(x) free(x)
 
-#define BUG_ON(c) assert(!(c))
-#define WARN_ON(c) assert(!(c))
+#define BUG_ON(c)				\
+	do {					\
+		if((c)) {			\
+			show_trace();		\
+			assert(!(c));		\
+		}				\
+	} while(0)
+#define WARN_ON(c) do {				\
+		if((c)) {			\
+			show_trace();		\
+			assert(!(c));		\
+		}				\
+	} while(0)
 
 
 #define container_of(ptr, type, member) ({                      \
-- 
2.0.4

             reply	other threads:[~2014-08-21 12:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-21 12:04 Naohiro Aota [this message]
2014-09-02 11:57 ` [PATCH RFC] btrfs-progs: Show backtrace on BUGs David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zjey82x4.fsf@elisp.net \
    --to=naota@elisp.net \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.