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
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
goto cleanup;
}
+replace:
if (!is_replace)
goto submit_write;
/*
* 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 {