Skip to content

Commit 7f2d219

Browse files
adam900710kdave
authored andcommitted
btrfs: scrub: limit RST scrub to chunk boundary
[BUG] If there is an extent beyond chunk boundary, currently RST scrub would error out. [CAUSE] In scrub_submit_extent_sector_read(), we completely rely on extent_sector_bitmap, which is populated using extent tree. The extent tree can be corrupted that there is an extent item beyond a chunk. In that case, RST scrub would fail and error out. [FIX] Despite the extent_sector_bitmap usage, also limit the read to chunk boundary. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent f546c42 commit 7f2d219

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/btrfs/scrub.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,9 @@ static void scrub_submit_extent_sector_read(struct scrub_ctx *sctx,
16461646
{
16471647
struct btrfs_fs_info *fs_info = stripe->bg->fs_info;
16481648
struct btrfs_bio *bbio = NULL;
1649+
unsigned int nr_sectors = min(BTRFS_STRIPE_LEN, stripe->bg->start +
1650+
stripe->bg->length - stripe->logical) >>
1651+
fs_info->sectorsize_bits;
16491652
u64 stripe_len = BTRFS_STRIPE_LEN;
16501653
int mirror = stripe->mirror_num;
16511654
int i;
@@ -1656,6 +1659,10 @@ static void scrub_submit_extent_sector_read(struct scrub_ctx *sctx,
16561659
struct page *page = scrub_stripe_get_page(stripe, i);
16571660
unsigned int pgoff = scrub_stripe_get_page_offset(stripe, i);
16581661

1662+
/* We're beyond the chunk boundary, no need to read anymore. */
1663+
if (i >= nr_sectors)
1664+
break;
1665+
16591666
/* The current sector cannot be merged, submit the bio. */
16601667
if (bbio &&
16611668
((i > 0 &&

0 commit comments

Comments
 (0)