btrfs: do not return errors from raid56_parity_recover

Always consume the bio and call the end_io handler on error instead of
returning an error and letting the caller handle it.  This matches what
the block layer submission does and avoids any confusion on who
needs to handle errors.

Also use the proper bool type for the generic_io argument.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Tested-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Christoph Hellwig 2022-06-17 12:04:09 +02:00 committed by David Sterba
parent 31683f4aae
commit 6065fd95da
4 changed files with 21 additions and 34 deletions

View File

@ -2199,12 +2199,11 @@ cleanup:
* so we assume the bio they send down corresponds to a failed part * so we assume the bio they send down corresponds to a failed part
* of the drive. * of the drive.
*/ */
int raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc, void raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
int mirror_num, int generic_io) int mirror_num, bool generic_io)
{ {
struct btrfs_fs_info *fs_info = bioc->fs_info; struct btrfs_fs_info *fs_info = bioc->fs_info;
struct btrfs_raid_bio *rbio; struct btrfs_raid_bio *rbio;
int ret;
if (generic_io) { if (generic_io) {
ASSERT(bioc->mirror_num == mirror_num); ASSERT(bioc->mirror_num == mirror_num);
@ -2213,9 +2212,8 @@ int raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
rbio = alloc_rbio(fs_info, bioc); rbio = alloc_rbio(fs_info, bioc);
if (IS_ERR(rbio)) { if (IS_ERR(rbio)) {
if (generic_io) bio->bi_status = errno_to_blk_status(PTR_ERR(rbio));
btrfs_put_bioc(bioc); goto out_end_bio;
return PTR_ERR(rbio);
} }
rbio->operation = BTRFS_RBIO_READ_REBUILD; rbio->operation = BTRFS_RBIO_READ_REBUILD;
@ -2227,10 +2225,9 @@ int raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
"%s could not find the bad stripe in raid56 so that we cannot recover any more (bio has logical %llu len %llu, bioc has map_type %llu)", "%s could not find the bad stripe in raid56 so that we cannot recover any more (bio has logical %llu len %llu, bioc has map_type %llu)",
__func__, bio->bi_iter.bi_sector << 9, __func__, bio->bi_iter.bi_sector << 9,
(u64)bio->bi_iter.bi_size, bioc->map_type); (u64)bio->bi_iter.bi_size, bioc->map_type);
if (generic_io)
btrfs_put_bioc(bioc);
kfree(rbio); kfree(rbio);
return -EIO; bio->bi_status = BLK_STS_IOERR;
goto out_end_bio;
} }
if (generic_io) { if (generic_io) {
@ -2257,24 +2254,20 @@ int raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
rbio->failb--; rbio->failb--;
} }
ret = lock_stripe_add(rbio); if (lock_stripe_add(rbio))
return;
/* /*
* __raid56_parity_recover will end the bio with * This adds our rbio to the list of rbios that will be handled after
* any errors it hits. We don't want to return * the current lock owner is done.
* its error value up the stack because our caller
* will end up calling bio_endio with any nonzero
* return
*/ */
if (ret == 0) __raid56_parity_recover(rbio);
__raid56_parity_recover(rbio); return;
/*
* our rbio has been added to the list of
* rbios that will be handled after the
* currently lock owner is done
*/
return 0;
out_end_bio:
if (generic_io)
btrfs_put_bioc(bioc);
bio_endio(bio);
} }
static void rmw_work(struct work_struct *work) static void rmw_work(struct work_struct *work)

View File

@ -165,8 +165,8 @@ static inline int nr_data_stripes(const struct map_lookup *map)
struct btrfs_device; struct btrfs_device;
int raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc, void raid56_parity_recover(struct bio *bio, struct btrfs_io_context *bioc,
int mirror_num, int generic_io); int mirror_num, bool generic_io);
void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc); void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc);
void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page, void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page,

View File

@ -1376,18 +1376,12 @@ static int scrub_submit_raid56_bio_wait(struct btrfs_fs_info *fs_info,
struct scrub_sector *sector) struct scrub_sector *sector)
{ {
DECLARE_COMPLETION_ONSTACK(done); DECLARE_COMPLETION_ONSTACK(done);
int ret;
int mirror_num;
bio->bi_iter.bi_sector = sector->logical >> 9; bio->bi_iter.bi_sector = sector->logical >> 9;
bio->bi_private = &done; bio->bi_private = &done;
bio->bi_end_io = scrub_bio_wait_endio; bio->bi_end_io = scrub_bio_wait_endio;
raid56_parity_recover(bio, sector->recover->bioc,
mirror_num = sector->sblock->sectors[0]->mirror_num; sector->sblock->sectors[0]->mirror_num, false);
ret = raid56_parity_recover(bio, sector->recover->bioc,
mirror_num, 0);
if (ret)
return ret;
wait_for_completion_io(&done); wait_for_completion_io(&done);
return blk_status_to_errno(bio->bi_status); return blk_status_to_errno(bio->bi_status);

View File

@ -6764,7 +6764,7 @@ void btrfs_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio, int mirror
if (btrfs_op(bio) == BTRFS_MAP_WRITE) if (btrfs_op(bio) == BTRFS_MAP_WRITE)
raid56_parity_write(bio, bioc); raid56_parity_write(bio, bioc);
else else
ret = raid56_parity_recover(bio, bioc, mirror_num, 1); raid56_parity_recover(bio, bioc, mirror_num, true);
goto out_dec; goto out_dec;
} }