From 27d4ee60145a6faab24e46be95e8d81a6f6e3127 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Mon, 25 Jan 2021 11:24:32 +0100 Subject: [PATCH] btrfs: cleanup repair_io_failure Keep the bio initialization together and use goto labels to streamline the error unwinding. Signed-off-by: Christoph Hellwig --- fs/btrfs/extent_io.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index c9cee458e001..721f8de71f67 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2256,8 +2256,6 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, ASSERT(!(fs_info->sb->s_flags & SB_RDONLY)); BUG_ON(!mirror_num); - bio = btrfs_io_bio_alloc(1); - bio->bi_iter.bi_size = 0; map_length = length; /* @@ -2275,43 +2273,34 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, */ ret = btrfs_map_block(fs_info, BTRFS_MAP_READ, logical, &map_length, &bbio, 0); - if (ret) { - btrfs_bio_counter_dec(fs_info); - bio_put(bio); - return -EIO; - } + if (ret) + goto out_bio_counter_dec; ASSERT(bbio->mirror_num == 1); } else { ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, logical, &map_length, &bbio, mirror_num); - if (ret) { - btrfs_bio_counter_dec(fs_info); - bio_put(bio); - return -EIO; - } + if (ret) + goto out_bio_counter_dec; BUG_ON(mirror_num != bbio->mirror_num); } sector = bbio->stripes[bbio->mirror_num - 1].physical >> 9; - bio->bi_iter.bi_sector = sector; dev = bbio->stripes[bbio->mirror_num - 1].dev; btrfs_put_bbio(bbio); if (!dev || !dev->bdev || - !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) { - btrfs_bio_counter_dec(fs_info); - bio_put(bio); - return -EIO; - } + !test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) + goto out_bio_counter_dec; + + bio = btrfs_io_bio_alloc(1); + bio->bi_iter.bi_size = 0; + bio->bi_iter.bi_sector = sector; bio_set_dev(bio, dev->bdev); bio->bi_opf = REQ_OP_WRITE | REQ_SYNC; bio_add_page(bio, page, length, pg_offset); - if (btrfsic_submit_bio_wait(bio)) { /* 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); - return -EIO; + goto out_bio_put; } btrfs_info_rl_in_rcu(fs_info, @@ -2321,6 +2310,12 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, btrfs_bio_counter_dec(fs_info); bio_put(bio); return 0; + +out_bio_put: + bio_put(bio); +out_bio_counter_dec: + btrfs_bio_counter_dec(fs_info); + return -EIO; } int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num) -- 2.50.1