]> git.hungrycats.org Git - linux/commitdiff
btrfs: scrub: do not write back repairs after a transaction abort 6.18/topics/read-repair-fixes
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 22 Oct 2026 18:32:02 +0000 (14:32 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:04:06 +0000 (21:04 -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 4d4852f2ba7eb50dabc354f95dcf016f1cbf3784..e5a20295545398ce3d64d5a95338806a5c6e0af4 100644 (file)
@@ -2612,6 +2612,14 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
                q_sector.has_paddr = false;
        }
 
+       /*
+        * 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
@@ -2627,6 +2635,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
                        goto cleanup;
        }
 
+replace:
        if (!is_replace)
                goto submit_write;
 
index 86450cfd31685b845d71a8df87635e3babcf121f..2796fe8082ada4b5b0bcd9596a9ef411a68b0211 100644 (file)
@@ -1239,10 +1239,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 {