From: Qu Wenruo Date: Mon, 17 Nov 2025 03:27:55 +0000 (+1030) Subject: btrfs: raid56: prepare set_bio_pages_uptodate() to support bs > ps cases X-Git-Tag: v6.19-rc1~167^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05ddf35a5d3d8d58323d6353f2bad026e9838af8;p=thirdparty%2Flinux.git btrfs: raid56: prepare set_bio_pages_uptodate() to support bs > ps cases The function set_bio_pages_uptodate() assume each fs block can be mapped by one page, blocking bs > ps support for raid56. Prepare it for bs > ps cases by: - Update find_stripe_sector_nr() to check only the first step paddr We don't need to check each paddr, as the bios are still aligned to fs block size, thus checking the first step is enough. - Use step size to iterate the bio This means we only need to find the sector number for the first step of each fs block, and skip the remaining part. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c index 7bc43f1861e64..2b68383805441 100644 --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -1588,7 +1588,7 @@ static void set_rbio_range_error(struct btrfs_raid_bio *rbio, struct bio *bio) static int find_stripe_sector_nr(struct btrfs_raid_bio *rbio, phys_addr_t paddr) { for (int i = 0; i < rbio->nr_sectors; i++) { - if (rbio->stripe_paddrs[i] == paddr) + if (rbio->stripe_paddrs[i * rbio->sector_nsteps] == paddr) return i; } return -1; @@ -1600,17 +1600,23 @@ static int find_stripe_sector_nr(struct btrfs_raid_bio *rbio, phys_addr_t paddr) */ static void set_bio_pages_uptodate(struct btrfs_raid_bio *rbio, struct bio *bio) { - const u32 blocksize = rbio->bioc->fs_info->sectorsize; + const u32 sectorsize = rbio->bioc->fs_info->sectorsize; + const u32 step = min(sectorsize, PAGE_SIZE); + u32 offset = 0; phys_addr_t paddr; ASSERT(!bio_flagged(bio, BIO_CLONED)); - btrfs_bio_for_each_block_all(paddr, bio, blocksize) { - int sector_nr = find_stripe_sector_nr(rbio, paddr); + btrfs_bio_for_each_block_all(paddr, bio, step) { + /* Hitting the first step of a sector. */ + if (IS_ALIGNED(offset, sectorsize)) { + int sector_nr = find_stripe_sector_nr(rbio, paddr); - ASSERT(sector_nr >= 0); - if (sector_nr >= 0) - set_bit(sector_nr, rbio->stripe_uptodate_bitmap); + ASSERT(sector_nr >= 0); + if (sector_nr >= 0) + set_bit(sector_nr, rbio->stripe_uptodate_bitmap); + } + offset += step; } }