btrfs: look up a repair read's csums in the same root as the failed read
A buffered read of an extent from a past transaction looks its checksums
up in the csum commit root: submit_one_bio() sets
bbio->csum_search_commit_root, and split bios and compressed reads
inherit it. repair_one_sector() leaves the flag clear on the repair
bbio, so the repair read looks the same checksums up in the running
transaction's csum tree.
Normally both lookups find the same checksums. After a transaction
abort they need not: the abort cleanup frees the running transaction's
dirty tree blocks without writing them, and a lookup that reaches one of
them once its folio is gone reads a location that was never written:
BTRFS error (device dm-6 state EA): bad tree block start, mirror 2 want
31490048 have
14842989077554535085
The original read finds its checksums in the commit root and detects
the bad copy, but every repair read then fails its csum lookup at
submission, so the read fails with -EIO although another copy is good.
Let the repair bbio inherit csum_search_commit_root from the failed
bbio, as btrfs_split_bio() does for split bios. The repair then finds
the checksums the failed read used, and after an abort read repair
returns the good copy's data again. It still does not write the
repaired sector back: the filesystem is read-only by then. The flag
survives the resubmission to the next mirror, because bio_reset() in
btrfs_end_repair_bio() does not touch the btrfs_bio fields.
Reproduced with read-repair-submit-fail-test.sh RR_ARM=abortgood
(raid56-wh-harness) on raid1: commit a file, make the running
transaction COW the csum leaf that holds the file's tail, corrupt the
tail on one mirror, abort the transaction by failing a log commit's
superblock write, drop the page cache and read the tail from the
corrupt mirror. Without this patch the read fails with -EIO; with it,
the read returns the file's data.
Fixes: f07b855c56b1 ("btrfs: try to search for data csums in commit root")
Cc: stable@vger.kernel.org # 6.18+
Assisted-by: Claude:claude-opus-5-5