Commit e9458bfe authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: use on-stack bio in repair_io_failure

The I/O in repair_io_failue is synchronous and doesn't need a btrfs_bio,
so just use an on-stack bio.  Also cleanup the error handling to use goto
labels and not discard the actual return values.
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 91e3b5f1
...@@ -2305,12 +2305,13 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, ...@@ -2305,12 +2305,13 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
u64 length, u64 logical, struct page *page, u64 length, u64 logical, struct page *page,
unsigned int pg_offset, int mirror_num) unsigned int pg_offset, int mirror_num)
{ {
struct bio *bio;
struct btrfs_device *dev; struct btrfs_device *dev;
struct bio_vec bvec;
struct bio bio;
u64 map_length = 0; u64 map_length = 0;
u64 sector; u64 sector;
struct btrfs_io_context *bioc = NULL; struct btrfs_io_context *bioc = NULL;
int ret; int ret = 0;
ASSERT(!(fs_info->sb->s_flags & SB_RDONLY)); ASSERT(!(fs_info->sb->s_flags & SB_RDONLY));
BUG_ON(!mirror_num); BUG_ON(!mirror_num);
...@@ -2318,8 +2319,6 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, ...@@ -2318,8 +2319,6 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
if (btrfs_repair_one_zone(fs_info, logical)) if (btrfs_repair_one_zone(fs_info, logical))
return 0; return 0;
bio = btrfs_bio_alloc(1);
bio->bi_iter.bi_size = 0;
map_length = length; map_length = length;
/* /*
...@@ -2337,53 +2336,50 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, ...@@ -2337,53 +2336,50 @@ static int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
*/ */
ret = btrfs_map_block(fs_info, BTRFS_MAP_READ, logical, ret = btrfs_map_block(fs_info, BTRFS_MAP_READ, logical,
&map_length, &bioc, 0); &map_length, &bioc, 0);
if (ret) { if (ret)
btrfs_bio_counter_dec(fs_info); goto out_counter_dec;
bio_put(bio);
return -EIO;
}
ASSERT(bioc->mirror_num == 1); ASSERT(bioc->mirror_num == 1);
} else { } else {
ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, logical, ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, logical,
&map_length, &bioc, mirror_num); &map_length, &bioc, mirror_num);
if (ret) { if (ret)
btrfs_bio_counter_dec(fs_info); goto out_counter_dec;
bio_put(bio);
return -EIO;
}
BUG_ON(mirror_num != bioc->mirror_num); BUG_ON(mirror_num != bioc->mirror_num);
} }
sector = bioc->stripes[bioc->mirror_num - 1].physical >> 9; sector = bioc->stripes[bioc->mirror_num - 1].physical >> 9;
bio->bi_iter.bi_sector = sector;
dev = bioc->stripes[bioc->mirror_num - 1].dev; dev = bioc->stripes[bioc->mirror_num - 1].dev;
btrfs_put_bioc(bioc); btrfs_put_bioc(bioc);
if (!dev || !dev->bdev || if (!dev || !dev->bdev ||
!test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) { !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) {
btrfs_bio_counter_dec(fs_info); ret = -EIO;
bio_put(bio); goto out_counter_dec;
return -EIO;
} }
bio_set_dev(bio, dev->bdev);
bio->bi_opf = REQ_OP_WRITE | REQ_SYNC;
bio_add_page(bio, page, length, pg_offset);
btrfsic_check_bio(bio); bio_init(&bio, dev->bdev, &bvec, 1, REQ_OP_WRITE | REQ_SYNC);
if (submit_bio_wait(bio)) { bio.bi_iter.bi_sector = sector;
__bio_add_page(&bio, page, length, pg_offset);
btrfsic_check_bio(&bio);
ret = submit_bio_wait(&bio);
if (ret) {
/* try to remap that extent elsewhere? */ /* try to remap that extent elsewhere? */
btrfs_bio_counter_dec(fs_info);
bio_put(bio);
btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS); btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
return -EIO; goto out_bio_uninit;
} }
btrfs_info_rl_in_rcu(fs_info, btrfs_info_rl_in_rcu(fs_info,
"read error corrected: ino %llu off %llu (dev %s sector %llu)", "read error corrected: ino %llu off %llu (dev %s sector %llu)",
ino, start, ino, start,
rcu_str_deref(dev->name), sector); rcu_str_deref(dev->name), sector);
ret = 0;
out_bio_uninit:
bio_uninit(&bio);
out_counter_dec:
btrfs_bio_counter_dec(fs_info); btrfs_bio_counter_dec(fs_info);
bio_put(bio); return ret;
return 0;
} }
int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num) int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment