* [PATCH 2/2] btrfs: scrub: report read-only and failed write correctly
2026-11-28 22:46 [PATCH 0/2] btrfs: scrub: improving read-only and write failure report Qu Wenruo
2026-11-28 22:46 ` [PATCH 1/2] btrfs: scrub: reset write_error_bitmap for a new stripe Qu Wenruo
@ 2026-11-28 22:46 ` Qu Wenruo
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2026-11-28 22:46 UTC (permalink / raw)
To: linux-btrfs; +Cc: Wesley Atwell
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.
Here I treat read-only the same as write failure.
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.
Reported-by: Wesley Atwell <atwellwea@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/20261128-btrfs-scrub-write-error-revalidated-v1-1-be9f21eede17@gmail.com/
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
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",
+ "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
^ permalink raw reply related [flat|nested] 3+ messages in thread