btrfs-progs: print-tree: Enhance warning on tree block level mismatch and error handling
authorQu Wenruo <wqu@suse.com>
Thu, 15 Mar 2018 04:48:15 +0000 (12:48 +0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Mar 2018 20:15:54 +0000 (22:15 +0200)
This patch enhances the tree block level mismatch by the following
methods:

1) Merge same warning branches into one
   We had two branches showing the same message, and their condition
   is also the same. Merge them

2) Only skip bad slot
   The old code skipped all the remaining slots, here we just skip one
   slot to output as many correct tree blocks as possible.

3) Enhance warning message
   Output the parent bytenr and expected and wrong level, so we don't
   need to refer to stdout to get which tree block is corrupted.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
print-tree.c

index 2dbed72..d59f900 100644 (file)
@@ -1398,19 +1398,16 @@ 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) {
-                       warning(
-       "eb corrupted: item %d eb level %d next level %d, skipping the rest",
-                               i, btrfs_header_level(next),
-                               btrfs_header_level(eb));
-                       goto out;
-               }
                if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
                        warning(
-       "eb corrupted: item %d eb level %d next level %d, skipping the rest",
-                               i, btrfs_header_level(next),
-                               btrfs_header_level(eb));
-                       goto out;
+"eb corrupted: parent bytenr %llu slot %d level %d child bytenr %llu level has %d expect %d, skipping the slot",
+                               btrfs_header_bytenr(eb), i,
+                               btrfs_header_level(eb),
+                               btrfs_header_bytenr(next),
+                               btrfs_header_level(next),
+                               btrfs_header_level(eb) - 1);
+                       free_extent_buffer(next);
+                       continue;
                }
                btrfs_print_tree(root, next, 1);
                free_extent_buffer(next);
@@ -1418,6 +1415,5 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
 
        return;
 
-out:
        free_extent_buffer(next);
 }