diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index 020afab5..f2cc42c7 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -34,21 +34,16 @@ #define FIELD_BUF_LEN 80 -static struct extent_buffer *debug_corrupt_block(struct btrfs_root *root, - u64 bytenr, u32 blocksize, u64 copy) +static void debug_corrupt_block(struct extent_buffer *eb, + struct btrfs_root *root, u64 bytenr, u32 blocksize, u64 copy) { int ret; - struct extent_buffer *eb; u64 length; struct btrfs_multi_bio *multi = NULL; struct btrfs_device *device; int num_copies; int mirror_num = 1; - eb = btrfs_find_create_tree_block(root->fs_info, bytenr, blocksize); - if (!eb) - return NULL; - length = blocksize; while (1) { ret = btrfs_map_block(&root->fs_info->mapping_tree, READ, @@ -84,7 +79,6 @@ static struct extent_buffer *debug_corrupt_block(struct btrfs_root *root, if (mirror_num > num_copies) break; } - return eb; } static void print_usage(int ret) @@ -1018,7 +1012,6 @@ int main(int argc, char **argv) struct cache_tree root_cache; struct btrfs_key key; struct btrfs_root *root; - struct extent_buffer *eb; char *dev; /* chunk offset can be 0,so change to (u64)-1 */ u64 logical = (u64)-1; @@ -1295,8 +1288,20 @@ int main(int argc, char **argv) if (corrupt_block_keys) { corrupt_keys_in_block(root, logical); } else { - eb = debug_corrupt_block(root, logical, - root->sectorsize, copy); + struct extent_buffer *eb; + + eb = btrfs_find_create_tree_block(root->fs_info, + logical, root->sectorsize); + if (!eb) { + error( + "not enough memory to allocate extent buffer for bytenr %llu", + (unsigned long long)logical); + ret = 1; + goto out_close; + } + + debug_corrupt_block(eb, root, logical, root->sectorsize, + copy); free_extent_buffer(eb); } logical += root->sectorsize;