* [PATCH] btrfs: scrub: don't count zoned repairs as corrected on a degraded mount
@ 2026-11-18 17:56 Miroslav Cimerman
2026-11-18 20:37 ` Qu Wenruo
0 siblings, 1 reply; 2+ messages in thread
From: Miroslav Cimerman @ 2026-11-18 17:56 UTC (permalink / raw)
To: linux-btrfs
Cc: David Sterba, Chris Mason, Qu Wenruo, Naohiro Aota,
Johannes Thumshirn, linux-kernel
On zoned devices scrub can't rewrite a bad copy in place. It calls
btrfs_repair_one_zone() to relocate the block group instead, and counts
the repaired blocks as corrected.
On a degraded mount btrfs_repair_one_zone() relocates nothing ("Do not
attempt to repair in degraded state"), but scrub still counts the
blocks as corrected and logs "fixed up error" for each. The bad copies
stay, and the next scrub finds and "fixes" the same errors again. With
zoned RAID1 mounted -o degraded with both devices present and read
errors in one device's metadata zone, two scrubs in a row both report:
Error summary: read=96
Corrected: 36
Uncorrectable: 60
Count such errors as uncorrectable, which the uapi header defines as
"no intact copy was found or the writeback failed". Dev-replace, which
writes the repaired blocks to the target device, and read-only scrub
are not changed.
Fixes: 54765392a1b9 ("btrfs: scrub: introduce helper to queue a stripe for scrub")
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
Keeping these errors as corrected and only logging that the repair was
skipped would leave a false positive: the counters would still report
the bad copies as fixed, and the next scrub finds them again. A new
counter for errors with an intact copy that were not written back would
be another option, but it changes the uapi. A read-only scrub, which
also counts errors with an intact copy as corrected without writing
anything, is not changed here.
Found with FuzzyRAID, a fault-injection tester for RAID that is not
public at the moment. The analysis, the fix and the commit message
were prepared with the help of an LLM, which also tested it. I reviewed
everything.
It also applies on top of "btrfs: scrub: fix several races which can
lead to UAF" (v2), with offsets.
fs/btrfs/scrub.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 98362c91bce4..9dcb0e7e3d0b 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -323,6 +323,12 @@ struct scrub_error_records {
*/
unsigned long init_error_bitmap;
+ /*
+ * Set if the repaired blocks could not be written back, thus all the
+ * initial errors are still on disk.
+ */
+ bool repair_skipped;
+
unsigned int nr_io_errors;
unsigned int nr_csum_errors;
unsigned int nr_meta_errors;
@@ -992,7 +998,7 @@ 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 = scrub_bitmap_read_error(stripe);
u64 physical = 0;
int nr_data_sectors = 0;
int nr_meta_sectors = 0;
@@ -1003,6 +1009,11 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
if (test_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state))
return;
+ /* Not written back, the repaired blocks are still bad on disk. */
+ if (errors->repair_skipped)
+ bitmap_or(&error_bitmap, &error_bitmap,
+ &errors->init_error_bitmap, stripe->nr_sectors);
+
/*
* Init needed infos for error reporting.
*
@@ -1227,6 +1238,15 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors)) {
if (btrfs_is_zoned(fs_info)) {
btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
+ /*
+ * On a degraded mount btrfs_repair_one_zone() does not
+ * relocate the block group and the bad copies stay,
+ * unless dev-replace writes the repaired blocks to the
+ * target device.
+ */
+ if (btrfs_test_opt(fs_info, DEGRADED) &&
+ !sctx->is_dev_replace)
+ errors.repair_skipped = true;
} else {
scrub_write_sectors(sctx, stripe, repaired, false);
wait_scrub_stripe_io(stripe);
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] btrfs: scrub: don't count zoned repairs as corrected on a degraded mount
2026-11-18 17:56 [PATCH] btrfs: scrub: don't count zoned repairs as corrected on a degraded mount Miroslav Cimerman
@ 2026-11-18 20:37 ` Qu Wenruo
0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2026-11-18 20:37 UTC (permalink / raw)
To: Miroslav Cimerman, linux-btrfs
Cc: David Sterba, Chris Mason, Naohiro Aota, Johannes Thumshirn,
linux-kernel
在 2026/11/19 04:26, Miroslav Cimerman 写道:
> On zoned devices scrub can't rewrite a bad copy in place. It calls
> btrfs_repair_one_zone() to relocate the block group instead, and counts
> the repaired blocks as corrected.
>
> On a degraded mount btrfs_repair_one_zone() relocates nothing ("Do not
> attempt to repair in degraded state"),
I think this is a little weird, any special reason for this in the first
place?
> but scrub still counts the
> blocks as corrected and logs "fixed up error" for each. The bad copies
> stay, and the next scrub finds and "fixes" the same errors again. With
> zoned RAID1 mounted -o degraded with both devices present and read
> errors in one device's metadata zone, two scrubs in a row both report:
>
> Error summary: read=96
> Corrected: 36
> Uncorrectable: 60
>
> Count such errors as uncorrectable, which the uapi header defines as
> "no intact copy was found or the writeback failed". Dev-replace, which
> writes the repaired blocks to the target device, and read-only scrub
> are not changed.
>
> Fixes: 54765392a1b9 ("btrfs: scrub: introduce helper to queue a stripe for scrub")
I do not think this is the correct fixes tag, that commit is just
calling btrfs_repair_one_zone(), and btrfs is already calling that before.
> Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
> ---
> Keeping these errors as corrected and only logging that the repair was
> skipped would leave a false positive: the counters would still report
> the bad copies as fixed, and the next scrub finds them again. A new
> counter for errors with an intact copy that were not written back would
> be another option, but it changes the uapi. A read-only scrub, which
> also counts errors with an intact copy as corrected without writing
> anything, is not changed here.
>
> Found with FuzzyRAID, a fault-injection tester for RAID that is not
> public at the moment. The analysis, the fix and the commit message
> were prepared with the help of an LLM, which also tested it. I reviewed
> everything.
>
> It also applies on top of "btrfs: scrub: fix several races which can
> lead to UAF" (v2), with offsets.
>
> fs/btrfs/scrub.c | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 98362c91bce4..9dcb0e7e3d0b 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -323,6 +323,12 @@ struct scrub_error_records {
> */
> unsigned long init_error_bitmap;
>
> + /*
> + * Set if the repaired blocks could not be written back, thus all the
> + * initial errors are still on disk.
> + */
> + bool repair_skipped;
> +
> unsigned int nr_io_errors;
> unsigned int nr_csum_errors;
> unsigned int nr_meta_errors;
> @@ -992,7 +998,7 @@ 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 = scrub_bitmap_read_error(stripe);
> u64 physical = 0;
> int nr_data_sectors = 0;
> int nr_meta_sectors = 0;
> @@ -1003,6 +1009,11 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
> if (test_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state))
> return;
>
> + /* Not written back, the repaired blocks are still bad on disk. */
> + if (errors->repair_skipped)
> + bitmap_or(&error_bitmap, &error_bitmap,
> + &errors->init_error_bitmap, stripe->nr_sectors);
> +
> /*
> * Init needed infos for error reporting.
> *
> @@ -1227,6 +1238,15 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
> if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors)) {
> if (btrfs_is_zoned(fs_info)) {
> btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
> + /*
> + * On a degraded mount btrfs_repair_one_zone() does not
> + * relocate the block group and the bad copies stay,
> + * unless dev-replace writes the repaired blocks to the
> + * target device.
> + */
> + if (btrfs_test_opt(fs_info, DEGRADED) &&
> + !sctx->is_dev_replace)
> + errors.repair_skipped = true;
> } else {
> scrub_write_sectors(sctx, stripe, repaired, false);
> wait_scrub_stripe_io(stripe);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 20:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 17:56 [PATCH] btrfs: scrub: don't count zoned repairs as corrected on a degraded mount Miroslav Cimerman
2026-11-18 20:37 ` Qu Wenruo
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®