]> git.hungrycats.org Git - linux/commitdiff
btrfs: dev-replace: count uncorrectable read errors
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 16 Oct 2026 08:07:34 +0000 (04:07 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:17:13 +0000 (21:17 -0500)
btrfs_dev_replace::num_uncorrectable_read_errors is reported by the
dev-replace status ioctl ("uncorr. read errs" in btrfs replace status)
and stored in the dev_replace item, but nothing increments it.

Even before v4.19 only two replace paths counted it: the nodatasum fixup
worker, when it could not repair a sector through the page cache, and
the nocow copy worker, when it could not write a range to the target.
Uncorrectable sectors with checksums, data or metadata, went through
scrub_handle_errored_block(), which counted them in the scrub stats but
not here.  Both paths were removed in v4.19, by commits 9bebe665c3e4
("btrfs: scrub: Remove unused copy_nocow_pages and its callchain") and
8b9b6f255485 ("btrfs: scrub: cleanup the remaining nodatasum fixup
code"), and the scrub_stripe based scrub never counted it either.  Status
always shows 0, however many sectors could not be copied.

Count the sectors that flush_scrub_stripes() does not write to the
replace target because they are covered by an extent but could not be
read or repaired from any copy.  This covers every uncorrectable sector
the replace skips, checksummed or not.

The count is taken before the check for a metadata error, which aborts
the replace, so that the sectors of the batch that aborts it are counted
as well.

Assisted-by: Claude:claude-opus-5-5
fs/btrfs/scrub.c

index 5128e2989016bf14fbe2b7e7def3048148425621..0a84f309c1f7a178266691ed1cae389c4ed49572 100644 (file)
@@ -1965,14 +1965,26 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
        if (sctx->is_dev_replace) {
                /*
                 * For dev-replace, if we know there is something wrong with
-                * metadata, we should immediately abort.
+                * metadata, we should immediately abort.  Count every
+                * uncorrectable sector of the batch first, those of an
+                * aborting batch included.
                 */
                for (int i = 0; i < nr_stripes; i++) {
-                       if (unlikely(stripe_has_metadata_error(&sctx->stripes[i]))) {
+                       unsigned long has_extent;
+                       unsigned long error;
+
+                       stripe = &sctx->stripes[i];
+                       has_extent = scrub_bitmap_read_has_extent(stripe);
+                       error = scrub_bitmap_read_error(stripe);
+                       bitmap_and(&error, &error, &has_extent, stripe->nr_sectors);
+                       if (!bitmap_empty(&error, stripe->nr_sectors))
+                               atomic64_add(bitmap_weight(&error, stripe->nr_sectors),
+                                            &fs_info->dev_replace.num_uncorrectable_read_errors);
+                       if (unlikely(stripe_has_metadata_error(stripe)))
                                ret = -EIO;
-                               goto out;
-                       }
                }
+               if (ret)
+                       goto out;
                for (int i = 0; i < nr_stripes; i++) {
                        unsigned long good;
                        unsigned long has_extent;
@@ -1984,6 +1996,7 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
 
                        has_extent = scrub_bitmap_read_has_extent(stripe);
                        error = scrub_bitmap_read_error(stripe);
+                       bitmap_and(&error, &error, &has_extent, stripe->nr_sectors);
                        bitmap_andnot(&good, &has_extent, &error, stripe->nr_sectors);
                        scrub_write_sectors(sctx, stripe, good, true);
                }