]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: raid56: prepare set_bio_pages_uptodate() to support bs > ps cases
authorQu Wenruo <wqu@suse.com>
Mon, 17 Nov 2025 03:27:55 +0000 (13:57 +1030)
committerDavid Sterba <dsterba@suse.com>
Tue, 25 Nov 2025 00:47:31 +0000 (01:47 +0100)
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 <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid56.c

index 7bc43f1861e644f7c8273f906d2ecf2d0c2bdef1..2b6838380544118835246d10f0093f54d1188b83 100644 (file)
@@ -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;
        }
 }