From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=174.142.148.226 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796281743; b=ZKOd2Y6JCueyCn1hHob6jT0Z/ozypLDgRT8T9wzp8OfxbOmdbVNWhOnamnhOzdRuXO07 1vLMHeGdbJ5jXriJmRh5yPGrljQsjfvDdPbDQh6agsMNvuGFXIG4vIfCC4t1+RmvKfrA9 BNGomGcu98WjwyBb7uRj6qVAEQGlHphzoxwRTwqus/Ql4DO9FL6wybhSaOr5KzDeZeW8Y 3gpduht6hubWi7TRAF5xIm306vIDQDyr2Ner0kkwpXYYXknNI4w0ytJDGtZIsQYhInE0l O14UFRqcBYf0OF4Dqt9J1u7JKSt3gSskgiBjI/kjNPibXh06kWZPihcSicNl1SGbu+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796281743; h=DMARC-Filter:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=rUCpRHuAL1pQqek8B1fnxfDGA4tIUKWlKWfQWuq+F7Y=; b=jVIGvFMsXdmwoB/Q8drKEIW2WBnoRcw1RT0347Ky3vhe5v9XXFSKY8jItS+uk4AOns4V r/l5l3DryEr55hXkUqAH32kJpki4Q2byR9qfkjOM4xNDidj7lfLohejN3UQkavsk7pSGh 0dZ1aJMTyUMvwlm257GIED4yXOJxarv/QBZvZDE9sFGtIF4RpguV3G0fE7gxhcF6eEv1T jB6he0evURWIKKFsHVSj6HNHr4BhfPY+sgu8KjFgv05ZoFjFtEwUVtt8hlLXThFIxlA1N tEapgDZwyQLYmKnh6yvUlYQ8f6THvjzN8tV48JCFrU8VuiU+NdLQpYMETyeEROHczgg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=umail.furryterror.org; spf=pass smtp.mailfrom=drax.hungrycats.org; arc=none smtp.remote-ip=174.142.148.226 Received: from drax.kayaks.hungrycats.org (drax.kayaks.hungrycats.org [174.142.148.226]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5E81606A32C for ; Thu, 3 Dec 2026 07:09:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C5E81606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=umail.furryterror.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=drax.hungrycats.org Received: by drax.kayaks.hungrycats.org (Postfix, from userid 1002) id B5D9F1D30FEB; Thu, 03 Dec 2026 02:08:55 -0500 (EST) Date: Thu, 3 Dec 2026 02:08:55 -0500 From: Zygo Blaxell To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, Wesley Atwell Subject: Re: [PATCH 2/2] btrfs: scrub: report read-only and failed write correctly Message-ID: References: <273c73599265203d74dda885dec9f5645609dd97.1795905947.git.wqu@suse.com> X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <273c73599265203d74dda885dec9f5645609dd97.1795905947.git.wqu@suse.com> On Sun, Nov 29, 2026 at 09:16:07AM +1030, Qu Wenruo wrote: > As long as there is a good copy, scrub will report a corrupted block as > repaired. But this can be wrong in the following cases: > > - Read-only scrub > The corruption is repairable but no write is submitted, so the > corruption is still there. > > - Write failure > Write is submitted but failed, so the corruption is still there. > > Fix the mismatch and strictly follow the UABI by: > > - Add is_sector_corrected() helper to report the repairbility > This also changes the error message, now we put the repairbility > report at the end. > > This will affect scripts parsing the kernel dmesg for scrub errors, > but those messages can be rate limited in the first place, so it's not > a reliable tool for monitoring. > > Please note that, for zoned btrfs the corrupted block will be reported > as "fixed up", as long as there is a good copy, no matter if the > relocation succeeded or not. > This is the existing behavior, this patch is not making it worse or > better. > > - Treat read-only and failed write as uncorrectable errors > The UABI only mentioned write failure. So read-only scrub behavior is > undefined. It's defined in include/uapi/linux/btrfs.h as: __u64 uncorrectable_errors; /* # of errors where either no intact * copy was found or the writeback * failed */ __u64 corrected_errors; /* # of errors corrected */ uncorrectable_errors clearly excludes errors where any intact copy is found. "Writeback failed" can't occur on a read-only scrub since there is no writeback attempted. An argument could be made that corrected_errors should always be exactly zero on a read-only scrub according to its definition, but that would give read-only scrub nowhere to report correctable errors at all. That's much less useful than the current behavior. Instead, I'd prefer to define corrected_errors as the complement of uncorrectable_errors, which already says what it excludes: an error is corrected if an intact copy was found and no writeback of it failed. On a read-write scrub that means it was repaired. On a read-only scrub, where no writeback is attempted, it means it could have been. That keeps the read-only behavior from 6.4, and it agrees with the half of this patch that counts a failed repair write as uncorrectable. > Here I treat read-only the same as write failure. As a user, that's really unexpected. With this change, if I have a device with correctable errors, a read-only scrub will tell me they are all uncorrectable, which doesn't reflect reality at all. If my device management workflow has used read-only scrub since 6.4, then after this change I might abandon a degraded but still healthy filesystem, believing its data to be permanently lost, because I didn't know about the change in uncorrectable_errors meaning. To me, "uncorrectable" means "correction is not possible," not "correction was possible, but we have chosen not to do it." The kernel has behaved this way since the 6.4 scrub rewrite. e02ee89baa66 ("btrfs: scrub: switch scrub_simple_mirror() to scrub_stripe infrastructure") started counting corrected and uncorrectable errors in read-only scrub, and 1f2030ff6e49 ("btrfs: scrub: respect the read-only flag during repair") kept reporting repairable sectors as corrected on a read-only scrub, noting the compromise. That behavior has been much more useful in practice. I expect that a read-only scrub would report the same number of errors that could or could not have been corrected as if I had done a read-write scrub (assuming the device would accept all repair writes, which a read-only scrub has no business trying to predict). Knowing that I had requested a read-only scrub, I would know that the counts are advisory, and are a prediction of what is possible, instead of a report of work actually done. > The current limit is that btrfs_scrub_progress has no way to tell if a > block can be repairable but not repaired. > > In the long run we should expand btrfs_scrub_progress, but that will be > a UABI change, and require a dedicated series. If the UAPI is redesigned, then we can get these counters separated, and we can have unambiguous counts of attempted and successful reads, and possible and completed repair writes. Four fields, no mode-specific meaning. Until then, the historical meanings of the legacy counters should not change too drastically, especially by removing already useful behavior. A UAPI redesign would also be a chance to fix the units of data_bytes_scrubbed and tree_bytes_scrubbed. They count only sectors that hold extents on the device being scrubbed, without RAID56 parity, while the only per-device size userspace can get is the space allocated to chunks, including their free space and parity. Userspace can't calculate a correct percentage done for a running scrub. A counter of bytes read from the device, or a total to scrub reported by the kernel, would fix that. > Reported-by: Wesley Atwell > Link: https://lore.kernel.org/linux-btrfs/20261128-btrfs-scrub-write-error-revalidated-v1-1-be9f21eede17@gmail.com/ > Signed-off-by: Qu Wenruo > --- > fs/btrfs/scrub.c | 60 +++++++++++++++++++++++++++++++++++------------- > 1 file changed, 44 insertions(+), 16 deletions(-) > > diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c > index 9ce22c069a96..5c633d7c8e1e 100644 > --- a/fs/btrfs/scrub.c > +++ b/fs/btrfs/scrub.c > @@ -1014,6 +1014,23 @@ static void scrub_stripe_submit_repair_read(struct scrub_stripe *stripe, > scrub_stripe_put_io(stripe); > } > > +static bool is_sector_corrected(const struct scrub_ctx *sctx, > + const struct scrub_stripe *stripe, > + unsigned int sector_nr, > + const char **desc_ret) > +{ > + if (sctx->readonly) { > + *desc_ret = "repairable but read-only scrub"; > + return false; > + } > + if (test_bit(sector_nr, &stripe->write_error_bitmap)) { > + *desc_ret = "repairable but write failed"; > + return false; > + } > + *desc_ret = "fixed up"; > + return true; > +} > + > static void scrub_stripe_report_errors(struct scrub_ctx *sctx, > struct scrub_stripe *stripe, > const struct scrub_error_records *errors) > @@ -1023,7 +1040,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; > @@ -1068,7 +1085,7 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx, > ((u64)sector_nr << fs_info->sectorsize_bits); > const u64 sector_physical = physical + > ((u64)sector_nr << fs_info->sectorsize_bits); > - bool repaired = false; > + bool has_good_copy = false; > > if (scrub_bitmap_test_bit_is_metadata(stripe, sector_nr)) { > nr_meta_sectors++; > @@ -1079,30 +1096,41 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx, > } > > if (test_bit(sector_nr, &errors->init_error_bitmap) && > - !test_bit(sector_nr, &error_bitmap)) { > - nr_repaired_sectors++; > - repaired = true; > - } > + !test_bit(sector_nr, &error_bitmap)) > + has_good_copy = true; > > /* Good sector from the beginning, nothing need to be done. */ > if (!test_bit(sector_nr, &errors->init_error_bitmap)) > continue; > > /* > - * Report error for the corrupted sectors. If repaired, just > - * output the message of repaired message. > + * Report error for the corrupted sectors. If repairable, just > + * output the message. > */ > - if (repaired) { > - if (dev) { > + if (has_good_copy) { > + const char *desc; > + const bool corrected = is_sector_corrected(sctx, stripe, > + sector_nr, &desc); > + > + if (dev) > btrfs_err_rl(fs_info, > - "scrub: fixed up error at logical %llu on dev %s physical %llu", Do we _need_ to change this? I have regression tests and monitoring scripts that look for this message, and I suspect I'm not the only one. Rate limiting doesn't matter, as a single instance of this message starts a triage response. Please consider appending to the end of the message to indicate failed writes or read-only scrub. > + "scrub: error at logical %llu on dev %s physical %llu, %s", > sector_logical, btrfs_dev_name(dev), > - sector_physical); > - } else { > + sector_physical, desc); > + else > btrfs_err_rl(fs_info, > - "scrub: fixed up error at logical %llu on mirror %u", > - sector_logical, stripe->mirror_num); > - } > + "scrub: error at logical %llu on mirror %u, %s", > + sector_logical, stripe->mirror_num, > + desc); > + > + /* > + * If not repaired, the block should be reported as > + * uncorrectable. > + */ > + if (!corrected) > + set_bit(sector_nr, &error_bitmap); > + else > + nr_repaired_sectors++; > continue; > } > > -- > 2.56.1 > >