]> git.hungrycats.org Git - linux/commitdiff
btrfs: look up a repair read's csums in the same root as the failed read
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 22 Oct 2026 18:31:46 +0000 (14:31 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 06:07:56 +0000 (01:07 -0500)
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
fs/btrfs/bio.c

index 212a46af0a2db2ab55a853082f3cf690e0bc912e..7521e37e516659b2faa9c46d107c5c95e9a813fe 100644 (file)
@@ -311,6 +311,13 @@ static struct btrfs_failed_bio *repair_one_sector(struct btrfs_bio *failed_bbio,
        repair_bbio = btrfs_bio(repair_bio);
        btrfs_bio_init(repair_bbio, failed_bbio->inode, failed_bbio->file_offset + bio_offset,
                       btrfs_repair_bio_submit_failed, fbio);
+       /*
+        * Look the checksum up in the same csum root as the failed read did.
+        * After a transaction abort the running transaction's csum tree can
+        * have freed blocks that were never written, while the commit root
+        * is intact.
+        */
+       repair_bbio->csum_search_commit_root = failed_bbio->csum_search_commit_root;
 
        mirror = next_repair_mirror(fbio, failed_bbio->mirror_num);
        btrfs_debug(fs_info, "submitting repair read to mirror %d", mirror);