btrfs-progs: improved error handling in btrfs_print_tree

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2016-09-06 15:55:59 +02:00
parent 26fbf0546d
commit ad44d1eb17

View file

@ -1148,6 +1148,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
u32 size; u32 size;
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
struct btrfs_key key; struct btrfs_key key;
struct extent_buffer *next;
if (!eb) if (!eb)
return; return;
@ -1181,23 +1182,34 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol
return; return;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct extent_buffer *next = read_tree_block(root, next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
btrfs_node_blockptr(eb, i), btrfs_node_ptr_generation(eb, i));
size,
btrfs_node_ptr_generation(eb, i));
if (!extent_buffer_uptodate(next)) { if (!extent_buffer_uptodate(next)) {
fprintf(stderr, "failed to read %llu in tree %llu\n", fprintf(stderr, "failed to read %llu in tree %llu\n",
(unsigned long long)btrfs_node_blockptr(eb, i), (unsigned long long)btrfs_node_blockptr(eb, i),
(unsigned long long)btrfs_header_owner(eb)); (unsigned long long)btrfs_header_owner(eb));
continue; continue;
} }
if (btrfs_is_leaf(next) && if (btrfs_is_leaf(next) && btrfs_header_level(eb) != 1) {
btrfs_header_level(eb) != 1) warning(
BUG(); "eb corrupted: item %d eb level %d next level %d, skipping the rest",
if (btrfs_header_level(next) != i, btrfs_header_level(next),
btrfs_header_level(eb) - 1) btrfs_header_level(eb));
BUG(); 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;
}
btrfs_print_tree(root, next, 1); btrfs_print_tree(root, next, 1);
free_extent_buffer(next); free_extent_buffer(next);
} }
return;
out:
free_extent_buffer(next);
} }