* [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* Re: [PATCH] btrfs: count failed RAID1 scrub repair writes as uncorrectable
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
0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2026-11-28 21:12 UTC (permalink / raw)
To: atwellwea, Qu Wenruo, David Sterba, Chris Mason; +Cc: linux-btrfs, linux-kernel
在 2026/11/29 07:21, Wesley Atwell via B4 Relay 写道:
> 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.
Duplicated unnecessary info. Delete the whole paragraph.
>
> 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.
Make the LLM word salad short, and no one cares which agent you use.
If you need to explicit show how to test, you shouldn't submit such patch.
To be honest, if you know nothing and fully rely on agents to do
everything, you should stop and just send out a bug report.
This will save everyone time.
>
> 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);
Why need to take this lock at all?
All IO should end before reaching this function.
In fact, if a lock is really needed, then the read_error_bitmap() read
is already racy.
> + 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);
Again, why?
> + 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,
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] btrfs: count failed RAID1 scrub repair writes as uncorrectable
2026-11-28 21:12 ` Qu Wenruo
@ 2026-11-28 23:31 ` Wesley Atwell
0 siblings, 0 replies; 3+ messages in thread
From: Wesley Atwell @ 2026-11-28 23:31 UTC (permalink / raw)
To: Qu Wenruo; +Cc: Qu Wenruo, David Sterba, Chris Mason, linux-btrfs, linux-kernel
Hi Qu,
Thanks for reviewing the patch and putting together your subsequent
two-patch series.
Moving the reset into scrub_stripe_reset_bitmaps() is a cleaner
approach, and I appreciate the additional handling of read-only
scrub. Your feedback regarding the unnecessary locking is also
helpful, and I will incorporate it into future contributions.
The AI disclosure and verification details were included in good
faith to follow the kernel's published guidelines:
https://docs.kernel.org/process/generated-content.html
https://docs.kernel.org/process/coding-assistants.html
I recognize that this information could have been presented more
concisely, and I will improve that going forward while maintaining
the transparency encouraged by the documentation.
I welcome technical criticism and recognize that I have more to
learn. I would, however, appreciate keeping future discussions
focused on the technical merits of the contribution rather than
assumptions about my knowledge or abilities.
Ultimately, my objective was to identify genuine defects and
contribute toward improving the kernel. I am glad that the
investigation uncovered two real issues and that your series
addresses both of them.
I have no objection to a better implementation replacing mine.
Getting the defects corrected is more important to me than whose
implementation is ultimately merged.
Since your series addresses both findings, I do not intend to
submit a competing revision.
Thank you for taking the time to address these issues.
Regards,
Wesley
^ 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®