]> git.hungrycats.org Git - linux/commit
btrfs: do not write back a read repair after a transaction abort
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 22 Oct 2026 18:32:00 +0000 (14:32 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 2 Nov 2026 02:04:06 +0000 (21:04 -0500)
commit77b9ca4e66b1a406dad938ea21a7290e663fa7c6
treed03be81bae31f60d994e7235874b4f1c5023fb16
parente551322e429226b3474ee5e44ac9d2753a07b843
btrfs: do not write back a read repair after a transaction abort

btrfs_repair_io_failure() writes a repaired data sector or tree block
back to the bad copy unless the filesystem is read-only.  SB_RDONLY is
not the only state that must stop that write:

- A transaction abort sets BTRFS_FS_STATE_TRANS_ABORTED, reports the
  abort (with a stack dump for most errors), and then
  __btrfs_handle_fs_error() sets fs_info->fs_error and only after that
  SB_RDONLY.  A repair that runs in between still writes after the
  abort.
- An error during mount, before SB_BORN, sets fs_error without
  SB_RDONLY.

Nothing should be written after an abort.  Add
btrfs_can_submit_repair_write(), which also checks the error and the
abort bit, and use it in btrfs_repair_io_failure().  That covers data
read repair and tree block repair (btrfs_repair_eb_io_failure()).  The
read still gets the good copy's data.

Fixes: 8ceaad6cd6e7 ("btrfs: do not ASSERT() when the fs flips RO inside btrfs_repair_io_failure()")
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/bio.c
fs/btrfs/fs.h