From: Qu Wenruo <wqu@suse.com>
To: Miroslav Cimerman <mc@raidlab.org>, linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>, Chris Mason <mason@kernel.org>,
Naohiro Aota <naohiro.aota@wdc.com>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: scrub: don't count zoned repairs as corrected on a degraded mount
Date: Thu, 19 Nov 2026 07:07:04 +1030 [thread overview]
Message-ID: <ee3cc2d0-6991-4d7a-bbd6-a84972d44b37@suse.com> (raw)
In-Reply-To: <20261118175637.60283-1-mc@raidlab.org>
在 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);
prev parent reply other threads:[~2026-11-18 20:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 17:56 Miroslav Cimerman
2026-11-18 20:37 ` Qu Wenruo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ee3cc2d0-6991-4d7a-bbd6-a84972d44b37@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.com \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=mc@raidlab.org \
--cc=naohiro.aota@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®