Skip to contentSkip to conversation

btrfs: return an error for unrepaired RAID56 scrub sectors

PATCH In review Cheng Yongkang 3 participants 4 messages Oct 25 – Oct 26 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: return an error for unrepaired RAID56 scrub sectors

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
---
 fs/btrfs/scrub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/scrub.c +1 -1
index 479c0e0..ba2e27c 100644
@@ -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);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Cheng Yongkang

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.

Quoted 7 lines

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
Quoted 17 lines
---
  fs/btrfs/scrub.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/scrub.c +1 -1
index 479c0e0..ba2e27c 100644
@@ -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 lore raw
In reply to Cheng Yongkang
Quoted 7 lines · Cheng Yongkang

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.

Quoted 7 lines

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.

This information in the last paragraph is rather useless. Rather than state the obvious, just check why we were not returning an error when we should have. If you checked the git history, you would see this is a regression.
Also, add a Fixes tag identifying the commit, as this is a bug and should be backported to stable kernels.

You should also check the for-next branches (in kernel.org and on
https://github.com/btrfs/linux/commits/for-next/) before sending patches, as this issue was already fixed:

https://github.com/btrfs/linux/commits/for-next/

Quoted 24 lines
Assisted-by LLM
---
 fs/btrfs/scrub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/scrub.c +1 -2
index 479c0e0..ba2e27c 100644
@@ -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

#3 lore raw

Hi Filipe,

Thanks for the review and the pointer. You are right: the fix is already in for-next as

ec0795c045c3 ("btrfs: scrub: fix lost error return value when scrubbing raid56 parity stripe")

with the same one-line return -EIO change and the Fixes: fab0c0f03cfd tag. I missed it because I checked lore and mainline but not the for-next branch. I withdraw this patch; please drop it.

I will check the for-next branches before sending the remaining patches and add Fixes tags where they are missing.

Best regards,
Cheng Yongkang