Patch "btrfs: scrub: handle RST lookup error correctly" has been added to the 6.9-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    btrfs: scrub: handle RST lookup error correctly

to the 6.9-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     btrfs-scrub-handle-rst-lookup-error-correctly.patch
and it can be found in the queue-6.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 766cf62489693b6170aec74281d3e1aa52ba188a
Author: Qu Wenruo <wqu@xxxxxxxx>
Date:   Mon Jun 17 15:18:44 2024 +0930

    btrfs: scrub: handle RST lookup error correctly
    
    [ Upstream commit 2c49908634a2b97b1c3abe0589be2739ac5e7fd5 ]
    
    [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 <johannes.thumshirn@xxxxxxx>
    Signed-off-by: Qu Wenruo <wqu@xxxxxxxx>
    Signed-off-by: David Sterba <dsterba@xxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index afd6932f5e895..d7caa3732f074 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1688,20 +1688,24 @@ static void scrub_submit_extent_sector_read(struct scrub_ctx *sctx,
 					    (i << fs_info->sectorsize_bits);
 			int err;
 
-			bbio = btrfs_bio_alloc(stripe->nr_sectors, REQ_OP_READ,
-					       fs_info, scrub_read_endio, stripe);
-			bbio->bio.bi_iter.bi_sector = logical >> SECTOR_SHIFT;
-
 			io_stripe.is_scrub = true;
+			stripe_len = (nr_sectors - i) << fs_info->sectorsize_bits;
+			/*
+			 * For RST cases, we need to manually split the bbio to
+			 * follow the RST boundary.
+			 */
 			err = btrfs_map_block(fs_info, BTRFS_MAP_READ, logical,
-					      &stripe_len, &bioc, &io_stripe,
-					      &mirror);
+					      &stripe_len, &bioc, &io_stripe, &mirror);
 			btrfs_put_bioc(bioc);
-			if (err) {
-				btrfs_bio_end_io(bbio,
-						 errno_to_blk_status(err));
-				return;
+			if (err < 0) {
+				set_bit(i, &stripe->io_error_bitmap);
+				set_bit(i, &stripe->error_bitmap);
+				continue;
 			}
+
+			bbio = btrfs_bio_alloc(stripe->nr_sectors, REQ_OP_READ,
+					       fs_info, scrub_read_endio, stripe);
+			bbio->bio.bi_iter.bi_sector = logical >> SECTOR_SHIFT;
 		}
 
 		__bio_add_page(&bbio->bio, page, fs_info->sectorsize, pgoff);




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux