mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] btrfs: count failed RAID1 scrub repair writes as uncorrectable
@ 2026-11-28 20:51 Wesley Atwell via B4 Relay
  2026-11-28 21:12 ` Qu Wenruo
  0 siblings, 1 reply; 3+ messages in thread
From: Wesley Atwell via B4 Relay @ 2026-11-28 20:51 UTC (permalink / raw)
  To: Qu Wenruo, David Sterba, Chris Mason
  Cc: linux-btrfs, linux-kernel, Wesley Atwell

From: Wesley Atwell <atwellwea@gmail.com>

When scrub reads a damaged sector from one RAID1 mirror, it can recover
that sector from the other mirror and attempt to write it back. If the
repair write fails, scrub currently reports the sector as corrected:
the final read-error bitmap is clear, while the separate write-error
bitmap is ignored by the ordinary stripe reporter.

In a QEMU guest on the Btrfs for-next tree, btrfs scrub start -B on a
local RAID1 filesystem returned success and reported 16 corrected,
zero uncorrectable sectors after targeted read and repair-write EIO.
The damaged mirror sector remained unchanged on disk, even though the
file was still readable from its good copy. A healthy scrub reported no
errors, and a writable-repair control restored the damaged sector.

Include failed repair writes in the reporter's final error bitmap and
clear the write-error bitmap when a scrub stripe is reused. With the
same failed-write workload, scrub now exits 3, reports 16
uncorrectable and zero corrected sectors, and no longer logs those
sectors as fixed up. The healthy and successful-repair controls still
pass. This change addresses the tested mirror-based reporting path;
RAID56 parity scrub aggregates errors separately.

OpenAI Codex identified the reporting omission, drafted this change
and changelog, and prepared the QEMU scrub workload. The task asked it
to find software-only crypto and filesystem defects, prove a failure
during a legitimate Linux workload on an unmodified kernel, and fix
only findings that passed the real-user evidence gate. The unmodified
and changed kernels were tested on the Btrfs for-next base with healthy,
failed-write and successful-repair cases; an independent review checked
the source paths and raw on-disk result.

Fixes: 0096580713ff ("btrfs: scrub: introduce error reporting functionality for scrub_stripe")
Cc: stable@vger.kernel.org
Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
---
The patch makes ordinary mirror scrub accounting include sectors whose
repair writes fail after a successful read from another mirror.

The task asked Codex to investigate filesystem defects, prove real-user
impact on an unmodified kernel, and fix only findings that passed that gate.
---
 fs/btrfs/scrub.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index c8da03e14094..b6dc7b5ec763 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1023,7 +1023,9 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
 	struct btrfs_fs_info *fs_info = sctx->fs_info;
 	struct btrfs_device *dev = NULL;
 	const unsigned long extent_bitmap = scrub_bitmap_read_has_extent(stripe);
-	const unsigned long error_bitmap = scrub_bitmap_read_error(stripe);
+	unsigned long error_bitmap;
+	unsigned long read_error_bitmap;
+	unsigned long flags;
 	u64 physical = 0;
 	int nr_data_sectors = 0;
 	int nr_meta_sectors = 0;
@@ -1063,6 +1065,12 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
 	}
 
 skip:
+	read_error_bitmap = scrub_bitmap_read_error(stripe);
+	spin_lock_irqsave(&stripe->write_error_lock, flags);
+	bitmap_or(&error_bitmap, &read_error_bitmap, &stripe->write_error_bitmap,
+		  stripe->nr_sectors);
+	spin_unlock_irqrestore(&stripe->write_error_lock, flags);
+
 	for_each_set_bit(sector_nr, &extent_bitmap, stripe->nr_sectors) {
 		const u64 sector_logical = stripe->logical +
 					   ((u64)sector_nr << fs_info->sectorsize_bits);
@@ -1796,6 +1804,12 @@ static int scrub_find_fill_first_stripe(struct btrfs_block_group *bg,
 
 static void scrub_reset_stripe(struct scrub_stripe *stripe)
 {
+	unsigned long flags;
+
+	spin_lock_irqsave(&stripe->write_error_lock, flags);
+	stripe->write_error_bitmap = 0;
+	spin_unlock_irqrestore(&stripe->write_error_lock, flags);
+
 	scrub_stripe_reset_bitmaps(stripe);
 
 	stripe->nr_meta_extents = 0;

---
base-commit: 14bf1d1d36414abf5f7f5b8e69a1810617c5f22f
change-id: 20261128-btrfs-scrub-write-error-revalidated-c00a17629d27

Best regards,
-- 
Wesley Atwell <atwellwea@gmail.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-28 23:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 20:51 [PATCH] btrfs: count failed RAID1 scrub repair writes as uncorrectable Wesley Atwell via B4 Relay
2026-11-28 21:12 ` Qu Wenruo
2026-11-28 23:31   ` Wesley Atwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®