]> git.hungrycats.org Git - linux/commitdiff
btrfs: dev-replace: count write errors to the target again
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:14 +0000 (21:17 -0500)
btrfs_dev_replace::num_write_errors is reported by the dev-replace status
ioctl, and scrub_enumerate_chunks() stops a replace with -EIO once it is
non-zero, so that a target that fails writes does not silently end up as
the new device.  Since the dev-replace writeback moved to the
scrub_stripe infrastructure nothing increments it: status always shows 0
write errors, and the abort never happens.

After the replace writes of a stripe have completed, add the sectors
whose write failed.  The stripe's write_error_bitmap also collects failed
repair writes to the source device, so clear it before the replace
writes are submitted.

Fixes: e02ee89baa66c ("btrfs: scrub: switch scrub_simple_mirror() to scrub_stripe infrastructure")
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/scrub.c

index 0a84f309c1f7a178266691ed1cae389c4ed49572..5d3fa99743f47bb4ffe506b5bdbb1853f2f20a30 100644 (file)
@@ -1994,6 +1994,14 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
 
                        ASSERT(stripe->dev == fs_info->dev_replace.srcdev);
 
+                       /*
+                        * The bitmap may hold failed repair writes to the
+                        * source; only count the writes to the target below.
+                        */
+                       spin_lock_irq(&stripe->write_error_lock);
+                       bitmap_zero(&stripe->write_error_bitmap, stripe->nr_sectors);
+                       spin_unlock_irq(&stripe->write_error_lock);
+
                        has_extent = scrub_bitmap_read_has_extent(stripe);
                        error = scrub_bitmap_read_error(stripe);
                        bitmap_and(&error, &error, &has_extent, stripe->nr_sectors);
@@ -2007,6 +2015,17 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
                stripe = &sctx->stripes[i];
 
                wait_scrub_stripe_io(stripe);
+               if (sctx->is_dev_replace) {
+                       unsigned int nr_errors;
+
+                       spin_lock_irq(&stripe->write_error_lock);
+                       nr_errors = bitmap_weight(&stripe->write_error_bitmap,
+                                                 stripe->nr_sectors);
+                       spin_unlock_irq(&stripe->write_error_lock);
+                       if (nr_errors)
+                               atomic64_add(nr_errors,
+                                            &fs_info->dev_replace.num_write_errors);
+               }
                spin_lock(&sctx->stat_lock);
                sctx->stat.last_physical = stripe->physical + stripe_length(stripe);
                spin_unlock(&sctx->stat_lock);