btrfs-progs: improved error handling in btrfs_print_tree
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
26fbf0546d
commit
ad44d1eb17
1 changed files with 22 additions and 10 deletions
32
print-tree.c
32
print-tree.c
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue