btrfs-progs: Print error on invalid extent item format during check
authorNikolay Borisov <nborisov@suse.com>
Fri, 29 Dec 2017 09:01:44 +0000 (11:01 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 31 Jan 2018 14:13:55 +0000 (15:13 +0100)
While performing normal mode check if the code comes across an invalid
extent format it will just BUG() and exit without printing any useful
information for debugging. Improve the situation by outputting the
key/leaf bytenr/slot which will enable to quickly inspect the tree and
see what the corruption is.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c

index a874c9e..5fc0ea9 100644 (file)
@@ -8366,7 +8366,13 @@ static int process_extent_item(struct btrfs_root *root,
        if (item_size < sizeof(*ei)) {
 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
                struct btrfs_extent_item_v0 *ei0;
-               BUG_ON(item_size != sizeof(*ei0));
+               if (item_size != sizeof(*ei0)) {
+                       error(
+       "invalid extent item format: ITEM[%llu %u %llu] leaf: %llu slot: %d",
+                               key.objectid, key.type, key.offset,
+                               btrfs_header_bytenr(eb), slot);
+                       BUG();
+               }
                ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
                refs = btrfs_extent_refs_v0(eb, ei0);
 #else