]> git.hungrycats.org Git - linux/commit
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)
commitd3cffd499e378afb6266d6c4672f170aed93df5f
treef6813bc422df4274dcbd0901933a51c679ddb874
parent77b9ca4e66b1a406dad938ea21a7290e663fa7c6
btrfs: scrub: do not write back repairs after a transaction abort

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