]> git.hungrycats.org Git - linux/commitdiff
btrfs: scrub: do not write back repairs after a transaction abort 7.3/topics/read-repair-fixes
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 22 Oct 2026 18:31:49 +0000 (14:31 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 06:07:56 +0000 (01:07 -0500)
A scrub that is running when a transaction aborts outside the commit
path keeps going.  (An abort in the commit path cancels it in
cleanup_transaction(), unless relocation is running.)  Once the abort
has forced the filesystem read-only, btrfs_inc_block_group_ro() takes
its path for a read-only mount, which needs no transaction, so the
scrub goes on through every remaining block group.  For every bad
sector it finds, scrub_stripe_read_repair_worker() reads a good copy
and writes it back with scrub_write_sectors().  It does not look at the
filesystem state (sctx->readonly is fixed when the scrub starts), so
these writes go out after the abort, to a filesystem that was forced
read-only.

Skip the write-back when btrfs_can_submit_repair_write() says no.  The
scrub still reads, verifies and reports.  A running dev-replace still
copies to its target, which __btrfs_handle_fs_error() leaves running on
purpose.

read-repair-submit-fail-test.sh RR_ARM=scrubabort (raid56-wh-harness)
corrupts a sector of a raid1 data block group on one mirror, starts a
speed-limited scrub, and aborts a transaction (a log commit whose
superblock writes fail) while the scrub is in that block group but
before it reaches the sector.  Without this patch the scrub writes the
sector back after the abort; with it nothing is written to either
device after the abort and the bad copy stays as it was.

The parity scrub of raid56 checks the same: its parity write-back is
skipped too, and its copy to a dev-replace target still goes out.

Fixes: 54765392a1b9 ("btrfs: scrub: introduce helper to queue a stripe for scrub")
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/raid56.c
fs/btrfs/scrub.c

index 1ee52a9dcee36f90578363fb62990c44defda4fb..6da1cf856ea9ccae6e8291d148fedcf987002d22 100644 (file)
@@ -2760,6 +2760,14 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
                q_paddr = INVALID_PADDR;
        }
 
+       /*
+        * After a transaction abort or another filesystem error, write
+        * nothing back to the scrubbed device.  A running dev-replace still
+        * copies to its target.
+        */
+       if (!btrfs_can_submit_repair_write(rbio->bioc->fs_info))
+               goto replace;
+
        /*
         * time to start writing.  Make bios for everything from the
         * higher layers (the bio_list in our rbio) and our p/q.  Ignore
@@ -2775,6 +2783,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
                        goto cleanup;
        }
 
+replace:
        if (!is_replace)
                goto submit_write;
 
index d582c1c81599d2662492a90d97b8c5e1d133d9f9..8dea0b538c225a3a3cc981b8b7cbb60569e02344 100644 (file)
@@ -1213,10 +1213,14 @@ out:
        /*
         * Submit the repaired sectors.  For zoned case, we cannot do repair
         * in-place, but queue the bg to be relocated.
+        *
+        * Nothing is written back after a transaction abort or another
+        * filesystem error that happened while the scrub was running.
         */
        bitmap_andnot(&repaired, &errors.init_error_bitmap, &error,
                      stripe->nr_sectors);
-       if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors)) {
+       if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors) &&
+           btrfs_can_submit_repair_write(fs_info)) {
                if (btrfs_is_zoned(fs_info)) {
                        btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
                } else {