Commit 150e4b05 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: submit read time repair only for each corrupted sector

Currently btrfs_submit_read_repair() has some extra check on whether the
failed bio needs extra validation for repair.  But we can avoid all
these extra mechanisms if we submit the repair for each sector.

By this, each read repair can be easily handled without the need to
verify which sector is corrupted.

This will also benefit subpage, as one subpage bvec can contain several
sectors, making the extra verification more complex.

So this patch will:

- Introduce repair_one_sector()
  The main code submitting repair, which is more or less the same as old
  btrfs_submit_read_repair().
  But this time, it only repairs one sector.

- Make btrfs_submit_read_repair() to handle sectors differently
  There are 3 different cases:

  * Good sector
    We need to release the page and extent, set the range uptodate.

  * Bad sector and failed to submit repair bio
    We need to release the page and extent, but not set the range
    uptodate.

  * Bad sector but repair bio submitted
    The page and extent release will be handled by the submitted repair
    bio. Nothing needs to be done.

  Since btrfs_submit_read_repair() will handle the page and extent
  release now, we need to skip to next bvec even we hit some error.

- Change the lifespan of @uptodate in end_bio_extent_readpage()
  Since now btrfs_submit_read_repair() will handle the full bvec
  which contains any corruption, we don't need to bother updating
  @uptodate bit anymore.
  Just let @uptodate to be local variable inside the main loop,
  so that any error from one bvec won't affect later bvec.

- Only export btrfs_repair_one_sector(), unexport
  btrfs_submit_read_repair()
  The only outside caller for read repair is DIO, which already submits
  its repair for just one sector.
  Only export btrfs_repair_one_sector() for DIO.

This patch will focus on the change on the repair path, the extra
validation code is still kept as is, and will be cleaned up later.
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 08508fea
This diff is collapsed.
...@@ -296,12 +296,11 @@ struct io_failure_record { ...@@ -296,12 +296,11 @@ struct io_failure_record {
int in_validation; int in_validation;
}; };
int btrfs_repair_one_sector(struct inode *inode,
blk_status_t btrfs_submit_read_repair(struct inode *inode, struct bio *failed_bio, u32 bio_offset,
struct bio *failed_bio, u32 bio_offset, struct page *page, unsigned int pgoff,
struct page *page, unsigned int pgoff, u64 start, int failed_mirror,
u64 start, u64 end, int failed_mirror, submit_bio_hook_t *submit_bio_hook);
submit_bio_hook_t *submit_bio_hook);
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
bool find_lock_delalloc_range(struct inode *inode, bool find_lock_delalloc_range(struct inode *inode,
......
...@@ -7945,19 +7945,17 @@ static blk_status_t btrfs_check_read_dio_bio(struct inode *inode, ...@@ -7945,19 +7945,17 @@ static blk_status_t btrfs_check_read_dio_bio(struct inode *inode,
btrfs_ino(BTRFS_I(inode)), btrfs_ino(BTRFS_I(inode)),
pgoff); pgoff);
} else { } else {
blk_status_t status; int ret;
ASSERT((start - io_bio->logical) < UINT_MAX); ASSERT((start - io_bio->logical) < UINT_MAX);
status = btrfs_submit_read_repair(inode, ret = btrfs_repair_one_sector(inode,
&io_bio->bio, &io_bio->bio,
start - io_bio->logical, start - io_bio->logical,
bvec.bv_page, pgoff, bvec.bv_page, pgoff,
start, start, io_bio->mirror_num,
start + sectorsize - 1, submit_dio_repair_bio);
io_bio->mirror_num, if (ret)
submit_dio_repair_bio); err = errno_to_blk_status(ret);
if (status)
err = status;
} }
start += sectorsize; start += sectorsize;
ASSERT(bio_offset + sectorsize > bio_offset); ASSERT(bio_offset + sectorsize > bio_offset);
......
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