btrfs-progs: corrupt block: pass eb as argument to debug_corrupt_block

Allocate the eb externally so we can handle the easy errors in advance.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2016-07-15 16:38:07 +02:00
parent 3652782c3b
commit e4a2d99dfe
1 changed files with 16 additions and 11 deletions

View File

@ -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;