]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: raid56: fix an incorrect csum skip during scrub
authorQu Wenruo <wqu@suse.com>
Sun, 12 Jul 2026 03:42:51 +0000 (13:12 +0930)
committerDavid Sterba <dsterba@suse.com>
Tue, 21 Jul 2026 04:41:18 +0000 (06:41 +0200)
Commit 7425a2894019 ("btrfs: introduce btrfs_bio_for_each_block_all()
helper") uses the new helper to replace the nested loop inside
verify_bio_data_sectors(), which simplifies the code.

However that also changed the behavior of "continue" when a block has no
data checksum.

Previously the "continue" would skip the old for() loop, which would also
increase @total_sector_nr.

Now the "continue" will skip the new btrfs_bio_for_each_block_all()
loop, which doesn't update @total_sector_nr.

This means if we hit a block that has no data checksum, we will skip all
the remaining blocks no matter if they have data checksum.
As @total_sector_nr will never be updated, and that test_bit() will
always return false.

Fix it by increasing @total_sector_nr before calling "continue".

Fixes: 7425a2894019 ("btrfs: introduce btrfs_bio_for_each_block_all() helper")
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid56.c

index f7f7db40994cca29d285c2791fc86c27b5de555e..3f2896e793e3a4bfba4d7a2a40cc9ca59514a83c 100644 (file)
@@ -1679,8 +1679,10 @@ static void verify_bio_data_sectors(struct btrfs_raid_bio *rbio,
                        continue;
 
                /* No csum for this sector, skip to the next sector. */
-               if (!test_bit(total_sector_nr, rbio->csum_bitmap))
+               if (!test_bit(total_sector_nr, rbio->csum_bitmap)) {
+                       total_sector_nr++;
                        continue;
+               }
 
                expected_csum = rbio->csum_buf + total_sector_nr * fs_info->csum_size;
                btrfs_calculate_block_csum_pages(fs_info, paddrs, csum_buf);