[PATCH] btrfs: return an error for unrepaired RAID56 scrub sectors

From: Cheng Yongkang

Date: Sun Oct 25 2026 - 14:03:42 EST


scrub_raid56_parity_stripe() returns the leftover value of
scrub_find_fill_first_stripe() (0 or 1) when it detects unrepaired
sectors in a data stripe. Scrub callers only treat negative values as
errors, so the unrepaired state is masked as success and P/Q
regeneration is skipped; a device replace can then copy corrupted data.

Return -EIO so the unrepaired sectors are reported and the corrupt
stripe is not treated as healthy.

The masked-success behavior was reproduced 3/3 times: baseline scrub
returned 0 with "finished ... status: 0", left P/Q unregenerated, and a
device replace copied corruption. With this change scrub returns -EIO
and the replace is canceled; healthy RAID1/RAID5 scrub still succeeds.

Assisted-by: LLM
Signed-off-by: Cheng Yongkang <teel4res@xxxxxxxxx>
---
fs/btrfs/scrub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 479c0e0..ba2e27c 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -2250,7 +2250,7 @@ static int scrub_raid56_parity_stripe(struct scrub_ctx *sctx,
"scrub: unrepaired sectors detected, full stripe %llu data stripe %u errors %*pbl",
full_stripe_start, i, stripe->nr_sectors,
&error);
- return ret;
+ return -EIO;
}
bitmap_or(&extent_bitmap, &extent_bitmap, &has_extent,
stripe->nr_sectors);
--
2.34.1