From a4b35a2e9704dbbb331f8931774d6d433c4bffeb Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 31 Oct 2026 01:04:01 -0400
-Subject: [PATCH 00/12] btrfs: raid56: rbio lifetime and cache fixes, error reporting
+Subject: [PATCH 00/10] btrfs: raid56: rbio lifetime and cache fixes, error reporting
To: linux-btrfs@vger.kernel.org
Fixes found running raid56 filesystems to ENOSPC under fsstress with a
dead or silently corrupting member. The patches are independent of
each other unless noted.
-Patches 1 and 2 are Qu Wenruo's "btrfs: raid56: minor fixes to
-rmw_rbio()", as posted (Reviewed-by: Filipe Manana, Link: tags in the
-patches). They are included because patch 12 applies on top of patch
-2; if they are merged first, "git am --skip" drops them here. Patch 1
-closes a race in which a bio merged into an rbio that failed early was
-never ended. Patch 2 stops an rbio whose write failed from being cached
-for page stealing: a later sub-stripe write to the same full stripe
-would otherwise take those pages instead of reading the disk and compute
-parity over data the failed members never got. It replaces a fix of
-our own for the same bug.
-
-Patch 3 logs a message when an extent is dropped because its write
+Qu Wenruo's "btrfs: raid56: minor fixes to rmw_rbio()" (2 patches,
+Reviewed-by: Filipe Manana), which this series used to carry at its
+head, is in btrfs/for-next (2976d37925785, f750b1dd48985) and in the
+base; patch 10 applies on top of it.
+
+Patch 1 logs a message when an extent is dropped because its write
failed. The error reaches userspace only through fsync or syncfs, and a
process that wrote a file and exited with its data still in dirty pages
is never told. The message carries both the logical address (which
refused the write), since the mapping between them is gone by the time
the error is handled.
-Patch 4 fixes a use-after-free of the rbio in the bio end_io wakeups.
+Patch 2 fixes a use-after-free of the rbio in the bio end_io wakeups.
The submission rounds count in-flight bios with an atomic and wait with
wait_event(); the waiter can see the counter reach zero and free the
rbio while the last end_io is still inside wake_up() on the rbio's
"pvqspinlock: lock ... has corrupted value" warnings; on bare metal it
is silent. The pair becomes a completion.
-Patch 5 propagates a split bio's error when the split that failed is
-not the last to complete; the error was dropped when the last split
-succeeded. Not raid56-specific. Fixes: d48e1dea3931.
+Patch 3 is Josef Bacik's "btrfs: don't drop the error of the last split
+bio" (1/5 of his "btrfs: data integrity fixes", 2026-10-30, Reviewed-by:
+Qu Wenruo), as posted. A split bio's error was dropped when the split
+that failed was not the last to complete and the last one succeeded.
+Not raid56-specific. Fixes: d48e1dea3931. It replaces our own patch
+for the same bug (identical code, different comment); it is carried
+here until upstream takes it, and "git am --skip" drops it then.
-Patch 6 drops cached rbios when their stripes' extents are freed. A
+Patch 4 drops cached rbios when their stripes' extents are freed. A
cached rbio's pages can be stolen by a later sub-stripe write to the
same full stripe after the space was freed and reallocated, so parity
is generated from the cache's memory of the stripe's previous contents
read and scrub passes, and reconstruction after a device failure
returns garbage. Proven byte-exactly on a raid5 test array.
-Patch 7 verifies reconstructed tree blocks. Data sectors rebuilt from
+Patch 5 verifies reconstructed tree blocks. Data sectors rebuilt from
parity are checked against their csums; metadata was handed back
unverified, and on raid6 the right one of several candidate
reconstructions could not be chosen. The tree block's own header csum
reads are left out: they cover free space too, and scrub verifies the
sectors that hold extents itself.
-Patches 8 and 9 fix two races around the rbio cache, both seen as
+Patches 6 and 7 fix two races around the rbio cache, both seen as
crashes on a degraded raid5 array under fsstress and made frequent by
-patch 6's trimming, but reachable with the in-tree cache shrink:
+patch 4's trimming, but reachable with the in-tree cache shrink:
lock_stripe_add()'s steal path drops the hash reference before removing
the rbio from the cache, so a concurrent removal frees it under the
-stealing thread (patch 8); and a cache removal can unhash an rbio that
+stealing thread (patch 6); and a cache removal can unhash an rbio that
has rbios plugged on it and hit BUG_ON(!list_empty(&rbio->plug_list))
-(patch 9).
+(patch 7).
-Patch 10 makes a RAID6 RMW rebuild from Q when a sector rebuilt from P
+Patch 8 makes a RAID6 RMW rebuild from Q when a sector rebuilt from P
fails its csum. The RMW read phase verifies data sectors and rebuilds a
failed one once, from P; P has no csum, so a stale P (left by a write
that failed within tolerance on a data member and the P member) makes
walks P, Q and P+Q; the RMW now retries in the same order.
Fixes: 7a3150723061.
-Patch 11 counts raid56 member I/O errors in the device stats. raid56
+Patch 9 counts raid56 member I/O errors in the device stats. raid56
submits its stripe bios itself and their end_io only marked the rbio's
error bitmap, so a raid56 write or read that failed on a member (within
tolerance, so the operation succeeded) was never counted in
`btrfs device stats`. The device is found by the bio's bdev, so writes
to a replace target are charged to the target. Fixes: 53b381b3abeb.
-Patch 12 makes a sub-stripe write write back the sectors its RMW read
+Patch 10 makes a sub-stripe write write back the sectors its RMW read
repaired. The read phase verifies data sectors against their csums and
-rebuilds bad ones (and, with patch 10, a stale P or Q), but only the new
+rebuilds bad ones (and, with patch 8, a stale P or Q), but only the new
data and parity were written, so the repaired strip stayed stale on
disk until read repair or scrub found it. Csummed data sectors, P/Q
with an error bit, and nodatasum sectors rebuilt from P+Q together with
device never is, and a failed write-back does not count against the
write's tolerance. Fixes: 7a3150723061.
-Qu Wenruo (2):
- btrfs: fix racy bio_list changes for failed RMW rbio
- btrfs: don't cache rbio if an error is hit
+Josef Bacik (1):
+ btrfs: don't drop the error of the last split bio
-Zygo Blaxell (10):
+Zygo Blaxell (9):
btrfs: log a message when dropping an extent due to IO error
btrfs: raid56: fix use-after-free of rbio in bio end_io wakeups
- btrfs: propagate a split bio's error when the failing split completes
- last
btrfs: raid56: drop cached rbios when their stripes' extents are freed
btrfs: raid56: verify reconstructed tree blocks
btrfs: raid56: keep a reference on a stolen cached rbio until it is
btrfs: raid56: count I/O errors in the device stats
btrfs: raid56: write back the sectors a sub-stripe write repaired
- fs/btrfs/bio.c | 13 +-
+ fs/btrfs/bio.c | 11 +-
fs/btrfs/bio.h | 2 +
fs/btrfs/extent-tree.c | 10 +
fs/btrfs/inode.c | 16 ++
- fs/btrfs/raid56.c | 626 +++++++++++++++++++++++++++++++++++++----
+ fs/btrfs/raid56.c | 591 ++++++++++++++++++++++++++++++++++++++---
fs/btrfs/raid56.h | 11 +-
- 6 files changed, 626 insertions(+), 52 deletions(-)
+ 6 files changed, 601 insertions(+), 40 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
+base-commit: 83cd81353093be02aa7e60874c413ec340e55bce
--
2.47.3