Skip to content

Commit 2c49908

Browse files
adam900710kdave
authored andcommitted
btrfs: scrub: handle RST lookup error correctly
[BUG] When running btrfs/060 with forced RST feature, it would crash the following ASSERT() inside scrub_read_endio(): ASSERT(sector_nr < stripe->nr_sectors); Before that, we would have tree dump from btrfs_get_raid_extent_offset(), as we failed to find the RST entry for the range. [CAUSE] Inside scrub_submit_extent_sector_read() every time we allocated a new bbio we immediately called btrfs_map_block() to make sure there was some RST range covering the scrub target. But if btrfs_map_block() fails, we immediately call endio for the bbio, while the bbio is newly allocated, it's completely empty. Then inside scrub_read_endio(), we go through the bvecs to find the sector number (as bi_sector is no longer reliable if the bio is submitted to lower layers). And since the bio is empty, such bvecs iteration would not find any sector matching the sector, and return sector_nr == stripe->nr_sectors, triggering the ASSERT(). [FIX] Instead of calling btrfs_map_block() after allocating a new bbio, call btrfs_map_block() first. Since our only objective of calling btrfs_map_block() is only to update stripe_len, there is really no need to do that after btrfs_alloc_bio(). This new timing would avoid the problem of handling empty bbio completely, and in fact fixes a possible race window for the old code, where if the submission thread is the only owner of the pending_io, the scrub would never finish (since we didn't decrease the pending_io counter). Although the root cause of RST lookup failure still needs to be addressed. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent b9fd2af commit 2c49908

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

fs/btrfs/scrub.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -1688,20 +1688,24 @@ static void scrub_submit_extent_sector_read(struct scrub_ctx *sctx,
16881688
(i << fs_info->sectorsize_bits);
16891689
int err;
16901690

1691-
bbio = btrfs_bio_alloc(stripe->nr_sectors, REQ_OP_READ,
1692-
fs_info, scrub_read_endio, stripe);
1693-
bbio->bio.bi_iter.bi_sector = logical >> SECTOR_SHIFT;
1694-
16951691
io_stripe.is_scrub = true;
1692+
stripe_len = (nr_sectors - i) << fs_info->sectorsize_bits;
1693+
/*
1694+
* For RST cases, we need to manually split the bbio to
1695+
* follow the RST boundary.
1696+
*/
16961697
err = btrfs_map_block(fs_info, BTRFS_MAP_READ, logical,
1697-
&stripe_len, &bioc, &io_stripe,
1698-
&mirror);
1698+
&stripe_len, &bioc, &io_stripe, &mirror);
16991699
btrfs_put_bioc(bioc);
1700-
if (err) {
1701-
btrfs_bio_end_io(bbio,
1702-
errno_to_blk_status(err));
1703-
return;
1700+
if (err < 0) {
1701+
set_bit(i, &stripe->io_error_bitmap);
1702+
set_bit(i, &stripe->error_bitmap);
1703+
continue;
17041704
}
1705+
1706+
bbio = btrfs_bio_alloc(stripe->nr_sectors, REQ_OP_READ,
1707+
fs_info, scrub_read_endio, stripe);
1708+
bbio->bio.bi_iter.bi_sector = logical >> SECTOR_SHIFT;
17051709
}
17061710

17071711
__bio_add_page(&bbio->bio, page, fs_info->sectorsize, pgoff);

0 commit comments

Comments
 (0)