mirror of
https://github.com/kdave/btrfs-progs
synced 2025-05-04 17:07:55 +00:00
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:
parent
3652782c3b
commit
e4a2d99dfe
@ -34,21 +34,16 @@
|
|||||||
|
|
||||||
#define FIELD_BUF_LEN 80
|
#define FIELD_BUF_LEN 80
|
||||||
|
|
||||||
static struct extent_buffer *debug_corrupt_block(struct btrfs_root *root,
|
static void debug_corrupt_block(struct extent_buffer *eb,
|
||||||
u64 bytenr, u32 blocksize, u64 copy)
|
struct btrfs_root *root, u64 bytenr, u32 blocksize, u64 copy)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct extent_buffer *eb;
|
|
||||||
u64 length;
|
u64 length;
|
||||||
struct btrfs_multi_bio *multi = NULL;
|
struct btrfs_multi_bio *multi = NULL;
|
||||||
struct btrfs_device *device;
|
struct btrfs_device *device;
|
||||||
int num_copies;
|
int num_copies;
|
||||||
int mirror_num = 1;
|
int mirror_num = 1;
|
||||||
|
|
||||||
eb = btrfs_find_create_tree_block(root->fs_info, bytenr, blocksize);
|
|
||||||
if (!eb)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
length = blocksize;
|
length = blocksize;
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = btrfs_map_block(&root->fs_info->mapping_tree, READ,
|
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)
|
if (mirror_num > num_copies)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return eb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_usage(int ret)
|
static void print_usage(int ret)
|
||||||
@ -1018,7 +1012,6 @@ int main(int argc, char **argv)
|
|||||||
struct cache_tree root_cache;
|
struct cache_tree root_cache;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct btrfs_root *root;
|
struct btrfs_root *root;
|
||||||
struct extent_buffer *eb;
|
|
||||||
char *dev;
|
char *dev;
|
||||||
/* chunk offset can be 0,so change to (u64)-1 */
|
/* chunk offset can be 0,so change to (u64)-1 */
|
||||||
u64 logical = (u64)-1;
|
u64 logical = (u64)-1;
|
||||||
@ -1295,8 +1288,20 @@ int main(int argc, char **argv)
|
|||||||
if (corrupt_block_keys) {
|
if (corrupt_block_keys) {
|
||||||
corrupt_keys_in_block(root, logical);
|
corrupt_keys_in_block(root, logical);
|
||||||
} else {
|
} else {
|
||||||
eb = debug_corrupt_block(root, logical,
|
struct extent_buffer *eb;
|
||||||
root->sectorsize, copy);
|
|
||||||
|
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);
|
free_extent_buffer(eb);
|
||||||
}
|
}
|
||||||
logical += root->sectorsize;
|
logical += root->sectorsize;
|
||||||
|
Loading…
Reference in New Issue
Block a user