All of lore.kernel.org
 help / color / mirror / Atom feed
From: mwilck@arcor.de
To: linux-btrfs@vger.kernel.org
Cc: mwilck@arcor.de
Subject: [PATCH 04/18] btrfs-progs: btrfs-debug-tree: handle corruption more gracefully
Date: Wed, 10 Dec 2014 21:51:34 +0100	[thread overview]
Message-ID: <1418244708-7087-5-git-send-email-mwilck@arcor.de> (raw)
In-Reply-To: <1418244708-7087-1-git-send-email-mwilck@arcor.de>

From: Martin Wilck <mwilck@arcor.de>

This patch fixes the same thing in two different places. First,
the first of the two BUG() tests is just a special case of the
second one and can therefore be omitted. Second, instead of bailing
out with BUG(), just print a reasonable error message and check the
next child.

Signed-off-by: Martin Wilck <mwilck@arcor.de>
---
 btrfs-debug-tree.c |   22 ++++++++++++++++------
 print-tree.c       |   22 ++++++++++++++++------
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c
index 4c1e835..d7c1155 100644
--- a/btrfs-debug-tree.c
+++ b/btrfs-debug-tree.c
@@ -73,13 +73,23 @@ static void print_extents(struct btrfs_root *root, struct extent_buffer *eb)
 					     btrfs_node_blockptr(eb, i),
 					     size,
 					     btrfs_node_ptr_generation(eb, i));
-		if (btrfs_is_leaf(next) &&
-		    btrfs_header_level(eb) != 1)
-			BUG();
 		if (btrfs_header_level(next) !=
-			btrfs_header_level(eb) - 1)
-			BUG();
-		print_extents(root, next);
+		    btrfs_header_level(eb) - 1) {
+			fprintf(stderr, "EXTENT TREE CORRUPTION detected at %llu, "
+				"slot %d pointing at %llu.\n"
+				"\tExpected child level: %d, found %d\n"
+				"\tExpected tree/transid: %llu/%llu,"
+				" found %llu/%llu\n",
+				eb->start, i, next->start,
+				btrfs_header_level(eb) - 1,
+				btrfs_header_level(next),
+				(unsigned long long)btrfs_header_owner(eb),
+				(unsigned long long)btrfs_header_generation(eb),
+				(unsigned long long)btrfs_header_owner(next),
+				(unsigned long long)
+				btrfs_header_generation(next));
+		} else
+			print_extents(root, next);
 		free_extent_buffer(next);
 	}
 }
diff --git a/print-tree.c b/print-tree.c
index 70a7acc..6769e20 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -1066,13 +1066,23 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
 				(unsigned long long)btrfs_header_owner(eb));
 			continue;
 		}
-		if (btrfs_is_leaf(next) &&
-		    btrfs_header_level(eb) != 1)
-			BUG();
 		if (btrfs_header_level(next) !=
-			btrfs_header_level(eb) - 1)
-			BUG();
-		btrfs_print_tree(root, next, 1);
+		    btrfs_header_level(eb) - 1) {
+			fprintf(stderr, "TREE CORRUPTION detected at %llu, "
+				"slot %d pointing at %llu.\n"
+				"\tExpected child level: %d, found %d\n"
+				"\tExpected tree/transid: %llu/%llu,"
+				" found %llu/%llu\n",
+				eb->start, i, next->start,
+				btrfs_header_level(eb) - 1,
+				btrfs_header_level(next),
+				(unsigned long long)btrfs_header_owner(eb),
+				(unsigned long long)btrfs_header_generation(eb),
+				(unsigned long long)btrfs_header_owner(next),
+				(unsigned long long)
+				btrfs_header_generation(next));
+		} else
+			btrfs_print_tree(root, next, 1);
 		free_extent_buffer(next);
 	}
 }
-- 
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-

  parent reply	other threads:[~2014-12-10 21:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-10 20:51 [PATCH 00/18] Patch series related to my btrfs recovery mwilck
2014-12-10 20:51 ` [PATCH 01/18] btrfs-progs: btrfs-debug-tree: add option -f for "block only" mwilck
2014-12-11  7:42   ` Qu Wenruo
2014-12-10 20:51 ` [PATCH 02/18] btrfs-progs: btrfs-debug-tree: add option -B (backup root) mwilck
2014-12-10 20:51 ` [PATCH 03/18] btrfs-progs: btrfs-debug-tree: fix usage message mwilck
2014-12-10 20:51 ` mwilck [this message]
2014-12-10 20:51 ` [PATCH 05/18] btrfs-progs: ctree.h: fix btrfs_inode_[amc]time mwilck
2014-12-11  7:59   ` Qu Wenruo
2014-12-11  8:16     ` Qu Wenruo
2014-12-10 20:51 ` [PATCH 06/18] btrfs restore: set uid/gid/mode/times mwilck
2014-12-10 20:51 ` [PATCH 07/18] btrfs restore: better output readability mwilck
2014-12-10 20:51 ` [PATCH 08/18] btrfs restore: track number of bytes restored mwilck
2014-12-10 20:51 ` [PATCH 09/18] btrfs restore: more graceful error handling in copy_file mwilck
2014-12-11  8:37   ` Qu Wenruo
2014-12-10 20:51 ` [PATCH 10/18] btrfs restore: hide "offset is X" messages mwilck
2014-12-10 20:51 ` [PATCH 11/18] btrfs restore: print progress marks for big files mwilck
2014-12-10 20:51 ` [PATCH 12/18] btrfs restore: check progress of file restoration mwilck
2014-12-11  8:44   ` Qu Wenruo
2014-12-10 20:51 ` [PATCH 13/18] btrfs restore: improve user-asking logic for files with many extents mwilck
2014-12-10 20:51 ` [PATCH 14/18] btrfs restore: report mismatch in file size mwilck
2014-12-10 20:51 ` [PATCH 15/18] btrfs-progs: NEW: btrfs-raw mwilck
2014-12-10 20:51 ` [PATCH 16/18] btrfs-progs: NEW: brtfs-search-metadata mwilck
2014-12-10 20:51 ` [PATCH 17/18] btrfs-progs: ctree.c: make bin_search non-static mwilck
2014-12-10 20:51 ` [PATCH 18/18] btrfs-progs: documentation for btrfs-raw and btrfs-search-metadata mwilck

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=1418244708-7087-5-git-send-email-mwilck@arcor.de \
    --to=mwilck@arcor.de \
    --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.