| | |
|---|---|
| base of every series | `0c48d26d46bd` ("btrfs: stop reading free space inodes from the commit root"), the misc-next lane base (`misc-next/testing^1`) |
-| integration branch | `misc-next/testing` `cd56f55e64cf` (octopus of all 17 topics) |
-| lane head | `zygo-misc-next-zb64` `923450976193`; its own commits on top of `testing` (kernel configs, `covers/`) are not exported |
+| integration branch | `misc-next/testing` `bbc86ab46e84` (octopus of all 17 topics) |
+| lane head | `zygo-misc-next-zb64` `3e1390a9de03`; its own commits on top of `testing` (kernel configs, `covers/`) are not exported |
The base is not a published commit: the lane rebuilds it from
btrfs/for-next plus David Sterba's queue. It lives in the
| `delalloc-fixes` | 1 | `7c23eb7ad5c9` | Zygo | from misc-next `covers/`, rewritten 2026-10-19 for 0/1 | patch 1 (delalloc leak) dropped 2026-10-19: fixed upstream by 095be159f3eb; 6.18 keeps it |
| `dev-extent-defrag` | 1 | `40c2fffa8348` | Zygo | new, 0/1 (drafted 2026-10-18) | |
| `prealloc-size` | 1 | `93d225865ab2` | Zygo | new, 0/1 (drafted 2026-10-18) | |
-| `raid56-fixes` | 11 | `8112c9e577e6` | Zygo | new; replaces `covers/raid56-rbio-fixes.txt` (2 of these patches) | **patch 11 is DO-NOT-UPSTREAM** (rbio cache size debug knob) |
+| `raid56-fixes` | 12 | `f7e693d10be2` | Zygo | new; replaces `covers/raid56-rbio-fixes.txt` (2 of these patches) | **patch 12 is DO-NOT-UPSTREAM** (rbio cache size debug knob) |
| `raid56-scrub-replace` | 10 | `2a30d9423f4e` | Filipe Manana, Zygo | new | patch 1 is Filipe's, already in btrfs/for-next (`ec0795c045c3`) |
| `stripe-alloc` | 112 | `52074eb4d12e` | Zygo | from misc-next `covers/`, **stale**: written for 65 patches, marked DO NOT SEND AS IS | RFC |
| `low-space` | 2 | `57034df182f0` | Zygo | from misc-next `covers/`, current | reserve off by default |
### What the fixup contains
-The fixup adds 455 lines and removes 18, in 10 files.
+The fixup adds 640 lines and removes 16, in 10 files.
1. **stripe-alloc merged after raid56-fixes** conflicts in `raid56.c`,
`raid56.h`, `block-group.c` and `sysfs.c`.
run has not finished").
- raid56-fixes' prune loop becomes stripe-alloc's
`rbio_cache_prune(table, rbio, limit)`.
+ - `rmw_rbio()` in `raid56.c`: raid56-fixes' write-back helpers
+ (patch 11) and stripe-alloc's RMW audit helpers are both inserted
+ before `rmw_rbio()`; keep both, write-back's hunks inside
+ `rmw_rbio()` unchanged.
- `sysfs.c`: the debug attribute list keeps stripe-alloc's
`stripe_rmw_audit` next to raid56-fixes' `rbio_cache_size`.
- The `block-group.c` conflict needs nothing beyond what `-X ours`
## Before sending
-- Drop `raid56-fixes` patch 11 and the whole `dm-stripfault` series.
+- Drop `raid56-fixes` patch 12 and the whole `dm-stripfault` series.
- `stripe-alloc`'s cover letter needs a rewrite.
- `balance-resume` patch 3 is offered for rejection, as its cover letter
says.
- Re-export with `scripts/export.sh` after any lane change. The
- directories reflect the lane at `misc-next/testing` `cd56f55e64cf`.
+ directories reflect the lane at `misc-next/testing` `bbc86ab46e84`.
Commit the result with the misc-next SHAs that the script prints.
ret = find_free_extent(root, ins, &ffe_ctl);
if (!ret && !is_data) {
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 0e1cd49ac44074a353adb6702e1b2bef5e514b21..3d5a6baae67e629a2d5a0e7846390f95bbefde0a 100644
+index b6fae5d9295ab887faab60bdf7b20f1bc96f5cd3..65a01492ab1ca8664e91ce1890575896e1bd0089 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -991,13 +991,15 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
spin_unlock(&table->cache_lock);
}
+@@ -4032,6 +4024,258 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+ return false;
+ }
+
++/*
++ * Read the header of the tree block at data-stripe sector @i, if there is
++ * one, from whichever copy of the sector this rbio is holding.
++ *
++ * @from_bio picks the source: the caller's pages (what this write is putting
++ * there) or the stripe pages (what an RMW read found on the disk). Returns
++ * false when the sector holds no tree block that belongs at this address --
++ * free space, or the remains of one from a previous life of the stripe.
++ */
++static bool rmw_peek_eb_generation(struct btrfs_raid_bio *rbio, u32 i,
++ bool from_bio, u64 *generation)
++{
++ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
++ const int stripe_nr = i / rbio->stripe_nsectors;
++ const int sectornr = i % rbio->stripe_nsectors;
++ const u64 logical = rbio->bioc->full_stripe_logical +
++ (u64)stripe_nr * BTRFS_STRIPE_LEN +
++ (u64)sectornr * fs_info->sectorsize;
++ const phys_addr_t *paddrs = from_bio ? rbio->bio_paddrs
++ : rbio->stripe_paddrs;
++ struct btrfs_header *hdr;
++ phys_addr_t paddr;
++ u64 found_bytenr;
++ bool bad_fsid;
++ void *kaddr;
++
++ paddr = paddrs[i * rbio->sector_nsteps];
++ if (paddr == INVALID_PADDR)
++ return false;
++ if (!from_bio && !test_bit(i, rbio->stripe_uptodate_bitmap))
++ return false;
++
++ kaddr = kmap_local_paddr(paddr);
++ hdr = kaddr;
++ found_bytenr = btrfs_stack_header_bytenr(hdr);
++ *generation = btrfs_stack_header_generation(hdr);
++ bad_fsid = memcmp(hdr->fsid, fs_info->fs_devices->metadata_uuid,
++ BTRFS_FSID_SIZE) != 0;
++ kunmap_local(kaddr);
++
++ return found_bytenr == logical && !bad_fsid;
++}
++
++/*
++ * Is @bytenr a tree block the committed extent tree still references? Read
++ * the commit root without locking, as the caching thread does, so this is
++ * safe from the raid56 worker with no transaction to join.
++ *
++ * Returns 1 if it is (or the lookup failed), 0 if not, and -EAGAIN if the
++ * answer needs a tree block that is not in memory. The caller holds the
++ * full stripe lock, so it must not read from disk: a read of a block in
++ * this stripe that needs reconstruction would wait for that lock.
++ */
++static int rmw_block_referenced(struct btrfs_fs_info *fs_info, u64 bytenr,
++ u64 header_gen, u64 *refs, u64 *extent_gen)
++{
++ struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bytenr);
++ struct btrfs_path *path;
++ struct btrfs_key key;
++ int live = 1;
++ int ret;
++
++ *refs = 0;
++ *extent_gen = 0;
++ path = btrfs_alloc_path();
++ if (!path)
++ return 1;
++ path->search_commit_root = 1;
++ path->skip_locking = 1;
++ path->nowait = 1;
++ key.objectid = bytenr;
++ key.type = BTRFS_METADATA_ITEM_KEY;
++ key.offset = (u64)-1;
++ if (!down_read_trylock(&fs_info->commit_root_sem)) {
++ btrfs_free_path(path);
++ return -EAGAIN;
++ }
++ ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
++ if (ret > 0)
++ ret = btrfs_previous_extent_item(extent_root, path, bytenr);
++ if (ret == 0) {
++ btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
++ if (key.objectid == bytenr &&
++ (key.type == BTRFS_METADATA_ITEM_KEY ||
++ key.type == BTRFS_EXTENT_ITEM_KEY)) {
++ struct btrfs_extent_item *ei;
++
++ ei = btrfs_item_ptr(path->nodes[0], path->slots[0],
++ struct btrfs_extent_item);
++ *refs = btrfs_extent_refs(path->nodes[0], ei);
++ *extent_gen = btrfs_extent_generation(path->nodes[0], ei);
++ /*
++ * An extent item at this bytenr from a LATER
++ * transaction than the header on disk belongs to a
++ * new block allocated here whose write has not landed
++ * yet; the header is the dead previous occupant.
++ * Only an item of the header's own generation makes
++ * the block on disk live.
++ */
++ live = (*refs != 0 && *extent_gen == header_gen);
++ } else {
++ live = 0;
++ }
++ } else if (ret > 0) {
++ live = 0;
++ } else if (ret == -EAGAIN) {
++ live = -EAGAIN;
++ }
++ up_read(&fs_info->commit_root_sem);
++ btrfs_free_path(path);
++ return live;
++}
++
++/*
++ * Decide whether an uncovered metadata read-modify-write is a write hole or
++ * only a cost, from the tree blocks it read: their parity is about to be
++ * rewritten while their own sectors stay put.
++ *
++ * - Same generation as the blocks this write carries (meta_rmw_cur): the
++ * block belongs to the running transaction, which a crash discards --
++ * except a log tree block, which is durable once its fsync returns.
++ * The audit does not tell log blocks apart, so it cannot see a write
++ * hole over fsynced log blocks; keeping them out of shared stripes is
++ * stripe_log_run's job.
++ * - Older, and still referenced by the committed extent tree: a write hole
++ * over committed metadata (meta_rmw_old).
++ *
++ * Comparing against this rbio's own blocks, not fs_info's committed
++ * generation, keeps a concurrent commit from skewing the verdict.
++ */
++static void audit_uncovered_rmw(struct btrfs_raid_bio *rbio)
++{
++ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
++ const u32 sectors_per_tree = fs_info->nodesize >> fs_info->sectorsize_bits;
++ const u32 nsectors = rbio->nr_data * rbio->stripe_nsectors;
++ u64 write_gen = 0;
++
++ /*
++ * Tree blocks only: metadata and system groups. A mixed group's
++ * sectors need not hold tree blocks.
++ */
++ if (rbio->bioc->map_type & BTRFS_BLOCK_GROUP_DATA)
++ return;
++ if (!(rbio->bioc->map_type & (BTRFS_BLOCK_GROUP_METADATA |
++ BTRFS_BLOCK_GROUP_SYSTEM)))
++ return;
++
++ /*
++ * Both loops read bio_paddrs to tell what this write covers, and the
++ * paths that reach here do not all populate it (a cached rbio that
++ * failed to pad never indexes). Idempotent, so just do it.
++ */
++ index_rbio_pages(rbio);
++
++ /* The generation this write is putting into the stripe. */
++ for (u32 i = 0; i < nsectors; i += sectors_per_tree) {
++ u64 gen;
++
++ if (rmw_peek_eb_generation(rbio, i, true, &gen))
++ write_gen = max(write_gen, gen);
++ }
++ if (!write_gen)
++ return;
++
++ for (u32 i = 0; i < nsectors; i += sectors_per_tree) {
++ u64 gen;
++
++ /* Covered by this write: it is what we are putting there. */
++ if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
++ continue;
++ if (!rmw_peek_eb_generation(rbio, i, false, &gen)) {
++ atomic64_inc(&fs_info->stripe_park_stats.meta_rmw_free);
++ continue;
++ }
++ if (gen >= write_gen) {
++ atomic64_inc(&fs_info->stripe_park_stats.meta_rmw_cur);
++ continue;
++ }
++ /*
++ * An older header is a write hole only if the committed extent
++ * tree still references the block: a reclaimed stripe keeps the
++ * headers of dead blocks, and tearing those harms nothing a
++ * reader can reach. The commit root is what a crash would see.
++ */
++ {
++ const int stripe_nr = i / rbio->stripe_nsectors;
++ const int sectornr = i % rbio->stripe_nsectors;
++ const u64 logical = rbio->bioc->full_stripe_logical +
++ (u64)stripe_nr * BTRFS_STRIPE_LEN +
++ (u64)sectornr * fs_info->sectorsize;
++ u64 refs;
++ u64 egen;
++ int ret;
++
++ ret = rmw_block_referenced(fs_info, logical, gen, &refs,
++ &egen);
++ if (ret == -EAGAIN) {
++ atomic64_inc(&fs_info->stripe_park_stats.meta_rmw_unknown);
++ continue;
++ }
++ if (!ret) {
++ atomic64_inc(&fs_info->stripe_park_stats.meta_rmw_ghost);
++ continue;
++ }
++ atomic64_inc(&fs_info->stripe_park_stats.meta_rmw_old);
++ btrfs_warn_rl(fs_info,
++"read-modify-write of stripe %llu rewrites parity over committed tree block %llu at generation %llu (refs %llu, extent generation %llu) while writing generation %llu: write hole",
++ rbio->bioc->full_stripe_logical, logical,
++ gen, refs, egen, write_gen);
++ }
++ }
++}
++
++/*
++ * Count and audit a metadata or system read-modify-write
++ * (audit_uncovered_rmw()), and warn if it lands in a raid56 group that
++ * stripe_meta does not cover. Silent when stripe_alloc is off.
++ */
++static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
++{
++ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
++ struct btrfs_block_group *bg;
++ bool covered = false;
++
++ if (!btrfs_test_opt(fs_info, STRIPE_ALLOC))
++ return;
++ /* Data groups are btrfs_is_stripe_alloc_bg()'s. */
++ if ((rbio->bioc->map_type & BTRFS_BLOCK_GROUP_DATA) &&
++ !(rbio->bioc->map_type & BTRFS_BLOCK_GROUP_METADATA))
++ return;
++
++ atomic64_inc(&fs_info->stripe_park_stats.meta_rmw);
++ audit_uncovered_rmw(rbio);
++ /*
++ * Every raid56 metadata and system group is a stripe_meta group while
++ * stripe_alloc is on, and stripe_alloc refuses to enable on mixed
++ * groups (btrfs_stripe_alloc_check_support()), so this warning is a
++ * defensive check: it fires only if a tree block group that should be
++ * covered is not.
++ */
++ bg = btrfs_lookup_block_group(fs_info, rbio->bioc->full_stripe_logical);
++ if (bg) {
++ covered = btrfs_is_stripe_meta_bg(bg);
++ btrfs_put_block_group(bg);
++ }
++ if (covered)
++ return;
++ btrfs_warn_rl(fs_info,
++"read-modify-write of full stripe %llu: this block group is not covered by stripe_alloc, the raid56 write hole applies to it",
++ rbio->bioc->full_stripe_logical);
++}
++
+ /*
+ * Return true if the rebuild of data sector @sector_nr of @stripe_nr can be
+ * trusted enough to write it back. It can when the sector has a csum: the
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
index b860e4e7bb03e5f4289230e07b0e6475cae16c92..4ce06b34b7b37eaaf59dc555805b76f6dc3e67e5 100644
--- a/fs/btrfs/raid56.h
-From 8112c9e577e6199e90529a850d86ad3c01e6e40e Mon Sep 17 00:00:00 2001
+From f7e693d10be20b7f83d5ba52569425bc68c36807 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Tue, 20 Oct 2026 22:14:03 -0400
-Subject: [PATCH 00/11] btrfs: raid56: rbio lifetime and cache fixes, error reporting
+Date: Tue, 20 Oct 2026 22:28:28 -0400
+Subject: [PATCH 00/12] 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
`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 11 is a test fixture and NOT for submission: a CONFIG_BTRFS_DEBUG
+Patch 11 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 9, 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
+a verified csummed sector of the same row are written back; a missing
+device never is, and a failed write-back does not count against the
+write's tolerance. Fixes: 7a3150723061.
+
+Patch 12 is a test fixture and NOT for submission: a CONFIG_BTRFS_DEBUG
sysfs knob for the rbio cache size, used by the dm-stripfault tests to
reach the RMW read path. Drop it before sending.
-Zygo Blaxell (11):
+Zygo Blaxell (12):
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
btrfs: raid56: rebuild from Q when a sector rebuilt from P fails its
csum
btrfs: raid56: count I/O errors in the device stats
+ btrfs: raid56: write back the sectors a sub-stripe write repaired
DO-NOT-UPSTREAM: btrfs: raid56: debug knob for the rbio stripe cache
size
fs/btrfs/extent-tree.c | 10 +
fs/btrfs/fs.h | 4 +
fs/btrfs/inode.c | 16 ++
- fs/btrfs/raid56.c | 481 +++++++++++++++++++++++++++++++++++++----
+ fs/btrfs/raid56.c | 633 ++++++++++++++++++++++++++++++++++++++---
fs/btrfs/raid56.h | 14 +-
- fs/btrfs/sysfs.c | 28 +++
- 8 files changed, 525 insertions(+), 43 deletions(-)
+ fs/btrfs/sysfs.c | 28 ++
+ 8 files changed, 677 insertions(+), 43 deletions(-)
base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
From 06db5c045ee4d05f55678163dc984793966b09af Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 5 Jul 2024 23:08:46 -0400
-Subject: [PATCH 01/11] btrfs: log a message when dropping an extent due to IO
+Subject: [PATCH 01/12] btrfs: log a message when dropping an extent due to IO
error
To: linux-btrfs@vger.kernel.org
From dec088fcc6e6b83401e437af76e1beac9f403bd1 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 25 Jul 2026 16:06:34 -0400
-Subject: [PATCH 02/11] btrfs: raid56: fix use-after-free of rbio in bio end_io
+Subject: [PATCH 02/12] btrfs: raid56: fix use-after-free of rbio in bio end_io
wakeups
To: linux-btrfs@vger.kernel.org
From c4ca7d88372eb775e03b9fb0ae3e080d171256c1 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 1 Aug 2026 01:31:24 -0400
-Subject: [PATCH 03/11] btrfs: propagate a split bio's error when the failing
+Subject: [PATCH 03/12] btrfs: propagate a split bio's error when the failing
split completes last
To: linux-btrfs@vger.kernel.org
From c05f4a996dc3d9f233e27e191e3bc8d1f92492bb Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Mon, 3 Aug 2026 03:24:38 -0400
-Subject: [PATCH 04/11] btrfs: raid56: drop cached rbios when their stripes'
+Subject: [PATCH 04/12] btrfs: raid56: drop cached rbios when their stripes'
extents are freed
To: linux-btrfs@vger.kernel.org
From 0fe89be282ee3d71b69555adab49dd43729aad45 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 5 Aug 2026 02:59:50 -0400
-Subject: [PATCH 05/11] btrfs: raid56: verify reconstructed tree blocks
+Subject: [PATCH 05/12] btrfs: raid56: verify reconstructed tree blocks
To: linux-btrfs@vger.kernel.org
Data sectors recovered from parity are checked against the csum tree
From b2c793a1845e5928abc500c6719aebf14e543c05 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 4 Sep 2026 22:14:19 -0400
-Subject: [PATCH 06/11] btrfs: raid56: keep a reference on a stolen cached rbio
+Subject: [PATCH 06/12] btrfs: raid56: keep a reference on a stolen cached rbio
until it is dropped
To: linux-btrfs@vger.kernel.org
From 3a80dae0c04b17fa72ef154d058a763334da4438 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 12 Sep 2026 07:17:54 -0400
-Subject: [PATCH 07/11] btrfs: raid56: do not unhash a cached rbio that has
+Subject: [PATCH 07/12] btrfs: raid56: do not unhash a cached rbio that has
rbios plugged on it
To: linux-btrfs@vger.kernel.org
From 773140d8d8973b91099623dedb025073a34b0974 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 01:19:22 -0400
-Subject: [PATCH 08/11] btrfs: raid56: do not let a failed write leave its
+Subject: [PATCH 08/12] btrfs: raid56: do not let a failed write leave its
pages for the next write
To: linux-btrfs@vger.kernel.org
From d507eefdb5832348bc728b963f3d7c8898ffb0a4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 13:04:12 -0400
-Subject: [PATCH 09/11] btrfs: raid56: rebuild from Q when a sector rebuilt
+Subject: [PATCH 09/12] btrfs: raid56: rebuild from Q when a sector rebuilt
from P fails its csum
To: linux-btrfs@vger.kernel.org
From 6dfdbfdffe7d7f18f1112740a6e3a9baa06dbb93 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 13:43:10 -0400
-Subject: [PATCH 10/11] btrfs: raid56: count I/O errors in the device stats
+Subject: [PATCH 10/12] btrfs: raid56: count I/O errors in the device stats
To: linux-btrfs@vger.kernel.org
raid56.c submits the reads and writes of a raid56 stripe itself, with its
+++ /dev/null
-From 8112c9e577e6199e90529a850d86ad3c01e6e40e Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Thu, 1 Oct 2026 03:54:55 -0400
-Subject: [PATCH 11/11] DO-NOT-UPSTREAM: btrfs: raid56: debug knob for the rbio
- stripe cache size
-To: linux-btrfs@vger.kernel.org
-
-Test fixture, not for submission. A read-modify-write whose stripe is
-still in the rbio stripe cache takes the other strips from memory instead
-of reading them, so a test that injects faults into reads (dm-stripfault)
-cannot reach the RMW read path for recently written stripes.
-
-With CONFIG_BTRFS_DEBUG, /sys/fs/btrfs/<uuid>/debug/rbio_cache_size
-replaces the RBIO_CACHE_SIZE limit (default unchanged, 1024); 0 disables
-the cache. Lowering it empties the cache, and the prune in cache_rbio()
-now loops so a lowered limit holds.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/fs.h | 4 ++++
- fs/btrfs/raid56.c | 41 ++++++++++++++++++++++++++++++++++++++---
- fs/btrfs/raid56.h | 3 +++
- fs/btrfs/sysfs.c | 28 ++++++++++++++++++++++++++++
- 4 files changed, 73 insertions(+), 3 deletions(-)
-
-diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
-index 2dd167c32d612..326a54601289c 100644
---- a/fs/btrfs/fs.h
-+++ b/fs/btrfs/fs.h
-@@ -635,6 +635,10 @@ struct btrfs_fs_info {
- * trying to mod the same stripe at the same time.
- */
- struct btrfs_stripe_hash_table *stripe_hash_table;
-+#ifdef CONFIG_BTRFS_DEBUG
-+ /* Size limit of the rbio stripe cache (debug/rbio_cache_size). */
-+ unsigned int rbio_cache_size;
-+#endif
-
- /*
- * This protects the ordered operations list only while we are
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 232cc91584ea2..f2df584b2e415 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -198,6 +198,9 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
- struct btrfs_stripe_hash *h;
- unsigned int num_entries = 1U << BTRFS_STRIPE_HASH_TABLE_BITS;
-
-+#ifdef CONFIG_BTRFS_DEBUG
-+ WRITE_ONCE(info->rbio_cache_size, RBIO_CACHE_SIZE);
-+#endif
- if (info->stripe_hash_table)
- return 0;
-
-@@ -601,6 +604,23 @@ static void btrfs_clear_rbio_cache(struct btrfs_fs_info *info)
- spin_unlock(&table->cache_lock);
- }
-
-+#ifdef CONFIG_BTRFS_DEBUG
-+/*
-+ * Test knob (debug/rbio_cache_size): with a small or zero limit, a
-+ * read-modify-write cannot take its stripe from the cache and must read it,
-+ * which is what a fault-injecting test needs to see. Lowering it empties the
-+ * cache, so the new limit holds from the next rbio on.
-+ */
-+void btrfs_set_rbio_cache_size(struct btrfs_fs_info *info, unsigned int size)
-+{
-+ unsigned int old = READ_ONCE(info->rbio_cache_size);
-+
-+ WRITE_ONCE(info->rbio_cache_size, size);
-+ if (size < old && info->stripe_hash_table)
-+ btrfs_clear_rbio_cache(info);
-+}
-+#endif
-+
- /*
- * remove all cached entries and free the hash table
- * used by unmount
-@@ -625,12 +645,25 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
- * If the size of the rbio cache is too big, we
- * prune an item.
- */
-+/* How many rbios the stripe cache keeps (0: none). */
-+static unsigned int rbio_cache_limit(const struct btrfs_fs_info *fs_info)
-+{
-+#ifdef CONFIG_BTRFS_DEBUG
-+ return READ_ONCE(fs_info->rbio_cache_size);
-+#else
-+ return RBIO_CACHE_SIZE;
-+#endif
-+}
-+
- static void cache_rbio(struct btrfs_raid_bio *rbio)
- {
- struct btrfs_stripe_hash_table *table;
-+ const unsigned int limit = rbio_cache_limit(rbio->bioc->fs_info);
-
- if (!test_bit(RBIO_CACHE_READY_BIT, &rbio->flags))
- return;
-+ if (!limit)
-+ return;
-
- table = rbio->bioc->fs_info->stripe_hash_table;
-
-@@ -650,15 +683,17 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
-
- spin_unlock(&rbio->bio_list_lock);
-
-- if (table->cache_size > RBIO_CACHE_SIZE) {
-+ /* A loop, not one eviction: the limit can have been lowered. */
-+ while (table->cache_size > limit) {
- struct btrfs_raid_bio *found;
-
- found = list_last_entry(&table->stripe_cache,
- struct btrfs_raid_bio,
- stripe_cache);
-
-- if (found != rbio)
-- __remove_rbio_from_cache(found);
-+ if (found == rbio)
-+ break;
-+ __remove_rbio_from_cache(found);
- }
-
- spin_unlock(&table->cache_lock);
-diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index c7c4b0db61f4c..8d28e2a77c62b 100644
---- a/fs/btrfs/raid56.h
-+++ b/fs/btrfs/raid56.h
-@@ -295,6 +295,9 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
-
- int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
- void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
-+#ifdef CONFIG_BTRFS_DEBUG
-+void btrfs_set_rbio_cache_size(struct btrfs_fs_info *info, unsigned int size);
-+#endif
- void btrfs_raid56_uncache_range(struct btrfs_fs_info *info, u64 start, u64 len);
-
- #endif
-diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
-index 3ac1fa608d3b5..78688c36f8b02 100644
---- a/fs/btrfs/sysfs.c
-+++ b/fs/btrfs/sysfs.c
-@@ -25,6 +25,7 @@
- #include "misc.h"
- #include "fs.h"
- #include "accessors.h"
-+#include "raid56.h"
-
- /*
- * Structure name Path
-@@ -520,12 +521,39 @@ static const struct attribute *discard_attrs[] = {
-
- #ifdef CONFIG_BTRFS_DEBUG
-
-+/* The raid56 stripe cache limit (raid56.c), 0 to disable the cache. */
-+static ssize_t btrfs_rbio_cache_size_show(struct kobject *kobj,
-+ struct kobj_attribute *a, char *buf)
-+{
-+ struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
-+
-+ return sysfs_emit(buf, "%u\n", READ_ONCE(fs_info->rbio_cache_size));
-+}
-+
-+static ssize_t btrfs_rbio_cache_size_store(struct kobject *kobj,
-+ struct kobj_attribute *a,
-+ const char *buf, size_t len)
-+{
-+ struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
-+ unsigned int val;
-+ int ret;
-+
-+ ret = kstrtouint(buf, 10, &val);
-+ if (ret)
-+ return ret;
-+ btrfs_set_rbio_cache_size(fs_info, val);
-+ return len;
-+}
-+BTRFS_ATTR_RW(debug_mount, rbio_cache_size, btrfs_rbio_cache_size_show,
-+ btrfs_rbio_cache_size_store);
-+
- /*
- * Per-filesystem runtime debugging exported via sysfs.
- *
- * Path: /sys/fs/btrfs/UUID/debug/
- */
- static const struct attribute *btrfs_debug_mount_attrs[] = {
-+ BTRFS_ATTR_PTR(debug_mount, rbio_cache_size),
- NULL,
- };
-
---
-2.47.3
-
--- /dev/null
+From 95d142c556b58d28b69c8c9aa579470eddce6d19 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 20 Oct 2026 15:52:51 -0400
+Subject: [PATCH 11/12] btrfs: raid56: write back the sectors a sub-stripe
+ write repaired
+To: linux-btrfs@vger.kernel.org
+
+A sub-stripe write reads the rest of its full stripe and verifies the data
+sectors that have csums. It rebuilds the sectors that failed their csum or
+their read, and the sectors of a missing device, and computes the new P and
+Q from the result. On RAID6 it also finds a stale P, or a stale data
+sector without a csum, by rebuilding again with one more stripe treated as
+failed. The write phase then writes only the new data, and P and Q of the
+vertical stripes the new data covers.
+
+The repaired sectors stay stale on disk until a read repair or a scrub
+finds them, even though the new parity was computed from their rebuilt
+contents. Until then the full stripe has one healthy member fewer than it
+seems, and one more lost device loses data that was recoverable.
+
+Write the repaired sectors back in the same write phase:
+
+- a data sector whose rebuild is verified. It has a csum, or it has none
+ but was rebuilt from P and Q together with a data sector of the same
+ vertical stripe that has one. The RAID6 retry finds a stale data sector
+ without a csum that way. A lone rebuild of a sector without a csum comes
+ from parity that nothing checked, and the copy on disk may be the right
+ one, so it is left alone;
+- P or Q that failed its read or was found stale, in the vertical stripes
+ the write does not cover (the others get new P and Q anyway);
+- nothing on a missing device. The replace target gets the same sectors as
+ its source, as with the other writes.
+
+The write-backs go out with the rest of the write. A write-back that fails
+leaves its sector as stale as it was before the write, so it does not count
+against the write's tolerance, and the write completes as it did before.
+
+The rbio repairs before it writes anything, so a write-back never retries a
+write that the same rbio just failed. A write that failed on a member
+within the tolerance leaves its pages in the stripe cache, and the next
+sub-stripe write into that full stripe takes them without reading, so it
+has nothing to repair either. A write-back can still go to a sector whose
+write by an earlier rbio failed, when that rbio's pages were not cached (a
+full stripe write) or were evicted: then it fails again, or heals the
+sector. A btrfs_debug line counts the write-backs and the failed ones.
+
+rmw-writeback-test.sh (raid56-wh-harness) puts strips of one full stripe
+back to stale contents, writes into the rest of the stripe, once with
+fsync and once with a plain write(), and reads the members back offline
+before anything else touches them. The stale strips are, on RAID5, a data
+strip with a csum, alone or also failing its reads; on RAID6, a data strip
+with P, with Q, with a second data strip with a csum, or with a strip of a
+nodatasum file, with the write covering all rows or only some of them.
+Without this patch every repaired strip, and P outside the written rows,
+is still stale after the write in all 18 runs; with it none is, and P and
+Q match the data in every row. With the stale member failing writes, the
+write-back fails, the write still completes and its data reads back,
+also on RAID5 when the write to P fails as well (counting the failed
+write-back against the tolerance fails that write with -EIO). A
+nodatasum strip rebuilt from P alone after a read error is not written
+back.
+
+Fixes: 7a3150723061 ("btrfs: raid56: do data csum verification during RMW cycle")
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/raid56.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 152 insertions(+)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 232cc91584ea2..5732c2d8ea359 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -2813,10 +2813,153 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+ return false;
+ }
+
++/*
++ * Return true if the rebuild of data sector @sector_nr of @stripe_nr can be
++ * trusted enough to write it back. It can when the sector has a csum: the
++ * rebuild was verified. Without a csum, it can only when another data sector
++ * of the same vertical stripe also failed and has a csum: the two were
++ * rebuilt together from P and Q (on RAID6 that is also how a stale sector
++ * without a csum is found, see recover_vertical_retry()), and the csum that
++ * verified one verifies the other. A lone rebuild without a csum came from
++ * parity that nothing checked, and the copy on the disk may still be right.
++ */
++static bool rmw_repair_verified(struct btrfs_raid_bio *rbio, int stripe_nr,
++ int sector_nr)
++{
++ if (!rbio->csum_bitmap)
++ return false;
++
++ for (int i = 0; i < rbio->nr_data; i++) {
++ const int index = rbio_sector_index(rbio, i, sector_nr);
++
++ if (!test_bit(index, rbio->csum_bitmap))
++ continue;
++ if (i == stripe_nr || test_bit(index, rbio->error_bitmap))
++ return true;
++ }
++ return false;
++}
++
++/*
++ * After the read phase of a sub-stripe write, return the sectors it repaired
++ * that the write phase should also write back, or NULL if there are none.
++ *
++ * recover_sectors() leaves the error bit set on every sector it rebuilt: a
++ * data sector that failed its csum or its read, every sector of a missing
++ * device, and the extra stripe that recover_vertical_retry() found stale.
++ * The rebuilt sectors are in the stripe pages and the new P and Q are
++ * generated from them, so without a write-back the disk copies stay stale
++ * until read repair or scrub finds them.
++ *
++ * Nothing is written to a missing device. A data sector is written back only
++ * if its rebuild is verified (rmw_repair_verified()). P and Q are generated
++ * from the data either way, so a failed or stale one is always written back.
++ *
++ * This rbio has not written anything yet, so none of these is a retry of a
++ * write that just failed here.
++ */
++static unsigned long *rmw_repaired_sectors(struct btrfs_raid_bio *rbio)
++{
++ unsigned long *repaired = NULL;
++ int total_sector_nr;
++
++ for_each_set_bit(total_sector_nr, rbio->error_bitmap, rbio->nr_sectors) {
++ const int stripe = total_sector_nr / rbio->stripe_nsectors;
++ const int sectornr = total_sector_nr % rbio->stripe_nsectors;
++
++ if (!rbio->bioc->stripes[stripe].dev->bdev)
++ continue;
++ if (stripe < rbio->nr_data &&
++ !rmw_repair_verified(rbio, stripe, sectornr))
++ continue;
++
++ if (!repaired) {
++ /* Without memory the sectors just stay stale on disk. */
++ repaired = bitmap_zalloc(rbio->nr_sectors, GFP_NOFS);
++ if (!repaired)
++ return NULL;
++ }
++ set_bit(total_sector_nr, repaired);
++ }
++ return repaired;
++}
++
++/*
++ * Add write bios for the repaired sectors that the write phase does not write
++ * anyway: data sectors no bio of this rbio covers, and P/Q outside the
++ * vertical stripes being written. The others are dropped from @repaired.
++ * The replace target gets the same sectors as its source.
++ */
++static int rmw_assemble_repair_bios(struct btrfs_raid_bio *rbio,
++ struct bio_list *bio_list,
++ unsigned long *repaired)
++{
++ int total_sector_nr;
++ int ret;
++
++ for_each_set_bit(total_sector_nr, repaired, rbio->nr_sectors) {
++ const int stripe = total_sector_nr / rbio->stripe_nsectors;
++ const int sectornr = total_sector_nr % rbio->stripe_nsectors;
++ phys_addr_t *paddrs;
++ bool written;
++
++ if (stripe < rbio->nr_data)
++ written = sector_paddrs_in_rbio(rbio, stripe, sectornr, 1);
++ else
++ written = test_bit(sectornr, &rbio->dbitmap);
++ if (written) {
++ clear_bit(total_sector_nr, repaired);
++ continue;
++ }
++
++ paddrs = rbio_stripe_paddrs(rbio, stripe, sectornr);
++ ret = rbio_add_io_paddrs(rbio, bio_list, paddrs, stripe,
++ sectornr, REQ_OP_WRITE);
++ if (ret)
++ goto error;
++
++ if (likely(!rbio->bioc->replace_nr_stripes) ||
++ stripe != rbio->bioc->replace_stripe_src)
++ continue;
++ ret = rbio_add_io_paddrs(rbio, bio_list, paddrs,
++ rbio->real_stripes, sectornr,
++ REQ_OP_WRITE);
++ if (ret)
++ goto error;
++ }
++ return 0;
++error:
++ bio_list_put(bio_list);
++ return -EIO;
++}
++
++/*
++ * A write-back that fails leaves the sector as stale as it was before this
++ * write, so it does not count against the tolerance of the write itself.
++ */
++static void rmw_finish_repair_bios(struct btrfs_raid_bio *rbio,
++ unsigned long *repaired)
++{
++ int written = 0;
++ int failed = 0;
++ int total_sector_nr;
++
++ for_each_set_bit(total_sector_nr, repaired, rbio->nr_sectors) {
++ written++;
++ if (test_and_clear_bit(total_sector_nr, rbio->error_bitmap))
++ failed++;
++ }
++ if (written)
++ btrfs_debug_rl(rbio->bioc->fs_info,
++ "sub-stripe write for full stripe %llu wrote back %d repaired sectors, %d failed",
++ rbio->bioc->full_stripe_logical, written, failed);
++}
++
+ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+ {
+ struct bio_list bio_list;
+ int sectornr;
++ unsigned long *repaired = NULL;
+ int ret = 0;
+
+ /*
+@@ -2845,6 +2988,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+ ret = rmw_read_wait_recover(rbio);
+ if (ret < 0)
+ goto out;
++ repaired = rmw_repaired_sectors(rbio);
+ }
+
+ /*
+@@ -2878,11 +3022,18 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+ ret = rmw_assemble_write_bios(rbio, &bio_list);
+ if (ret < 0)
+ goto out;
++ if (repaired) {
++ ret = rmw_assemble_repair_bios(rbio, &bio_list, repaired);
++ if (ret < 0)
++ goto out;
++ }
+
+ /* We should have at least one bio assembled. */
+ ASSERT(bio_list_size(&bio_list));
+ submit_write_bios(rbio, &bio_list);
+ rbio_wait_io(rbio);
++ if (repaired)
++ rmw_finish_repair_bios(rbio, repaired);
+
+ /* We may have more errors than our tolerance during the read. */
+ for (sectornr = 0; sectornr < rbio->stripe_nsectors; sectornr++) {
+@@ -2895,6 +3046,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+ }
+ }
+ out:
++ bitmap_free(repaired);
+ rbio_orig_end_io(rbio, errno_to_blk_status(ret));
+ }
+
+--
+2.47.3
+
--- /dev/null
+From f7e693d10be20b7f83d5ba52569425bc68c36807 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Thu, 1 Oct 2026 03:54:55 -0400
+Subject: [PATCH 12/12] DO-NOT-UPSTREAM: btrfs: raid56: debug knob for the rbio
+ stripe cache size
+To: linux-btrfs@vger.kernel.org
+
+Test fixture, not for submission. A read-modify-write whose stripe is
+still in the rbio stripe cache takes the other strips from memory instead
+of reading them, so a test that injects faults into reads (dm-stripfault)
+cannot reach the RMW read path for recently written stripes.
+
+With CONFIG_BTRFS_DEBUG, /sys/fs/btrfs/<uuid>/debug/rbio_cache_size
+replaces the RBIO_CACHE_SIZE limit (default unchanged, 1024); 0 disables
+the cache. Lowering it empties the cache, and the prune in cache_rbio()
+now loops so a lowered limit holds.
+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/fs.h | 4 ++++
+ fs/btrfs/raid56.c | 41 ++++++++++++++++++++++++++++++++++++++---
+ fs/btrfs/raid56.h | 3 +++
+ fs/btrfs/sysfs.c | 28 ++++++++++++++++++++++++++++
+ 4 files changed, 73 insertions(+), 3 deletions(-)
+
+diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
+index 2dd167c32d612..326a54601289c 100644
+--- a/fs/btrfs/fs.h
++++ b/fs/btrfs/fs.h
+@@ -635,6 +635,10 @@ struct btrfs_fs_info {
+ * trying to mod the same stripe at the same time.
+ */
+ struct btrfs_stripe_hash_table *stripe_hash_table;
++#ifdef CONFIG_BTRFS_DEBUG
++ /* Size limit of the rbio stripe cache (debug/rbio_cache_size). */
++ unsigned int rbio_cache_size;
++#endif
+
+ /*
+ * This protects the ordered operations list only while we are
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 5732c2d8ea359..c44e447b7c4a5 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -198,6 +198,9 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
+ struct btrfs_stripe_hash *h;
+ unsigned int num_entries = 1U << BTRFS_STRIPE_HASH_TABLE_BITS;
+
++#ifdef CONFIG_BTRFS_DEBUG
++ WRITE_ONCE(info->rbio_cache_size, RBIO_CACHE_SIZE);
++#endif
+ if (info->stripe_hash_table)
+ return 0;
+
+@@ -601,6 +604,23 @@ static void btrfs_clear_rbio_cache(struct btrfs_fs_info *info)
+ spin_unlock(&table->cache_lock);
+ }
+
++#ifdef CONFIG_BTRFS_DEBUG
++/*
++ * Test knob (debug/rbio_cache_size): with a small or zero limit, a
++ * read-modify-write cannot take its stripe from the cache and must read it,
++ * which is what a fault-injecting test needs to see. Lowering it empties the
++ * cache, so the new limit holds from the next rbio on.
++ */
++void btrfs_set_rbio_cache_size(struct btrfs_fs_info *info, unsigned int size)
++{
++ unsigned int old = READ_ONCE(info->rbio_cache_size);
++
++ WRITE_ONCE(info->rbio_cache_size, size);
++ if (size < old && info->stripe_hash_table)
++ btrfs_clear_rbio_cache(info);
++}
++#endif
++
+ /*
+ * remove all cached entries and free the hash table
+ * used by unmount
+@@ -625,12 +645,25 @@ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info)
+ * If the size of the rbio cache is too big, we
+ * prune an item.
+ */
++/* How many rbios the stripe cache keeps (0: none). */
++static unsigned int rbio_cache_limit(const struct btrfs_fs_info *fs_info)
++{
++#ifdef CONFIG_BTRFS_DEBUG
++ return READ_ONCE(fs_info->rbio_cache_size);
++#else
++ return RBIO_CACHE_SIZE;
++#endif
++}
++
+ static void cache_rbio(struct btrfs_raid_bio *rbio)
+ {
+ struct btrfs_stripe_hash_table *table;
++ const unsigned int limit = rbio_cache_limit(rbio->bioc->fs_info);
+
+ if (!test_bit(RBIO_CACHE_READY_BIT, &rbio->flags))
+ return;
++ if (!limit)
++ return;
+
+ table = rbio->bioc->fs_info->stripe_hash_table;
+
+@@ -650,15 +683,17 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
+
+ spin_unlock(&rbio->bio_list_lock);
+
+- if (table->cache_size > RBIO_CACHE_SIZE) {
++ /* A loop, not one eviction: the limit can have been lowered. */
++ while (table->cache_size > limit) {
+ struct btrfs_raid_bio *found;
+
+ found = list_last_entry(&table->stripe_cache,
+ struct btrfs_raid_bio,
+ stripe_cache);
+
+- if (found != rbio)
+- __remove_rbio_from_cache(found);
++ if (found == rbio)
++ break;
++ __remove_rbio_from_cache(found);
+ }
+
+ spin_unlock(&table->cache_lock);
+diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
+index c7c4b0db61f4c..8d28e2a77c62b 100644
+--- a/fs/btrfs/raid56.h
++++ b/fs/btrfs/raid56.h
+@@ -295,6 +295,9 @@ void raid56_parity_cache_data_folios(struct btrfs_raid_bio *rbio,
+
+ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info);
+ void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info);
++#ifdef CONFIG_BTRFS_DEBUG
++void btrfs_set_rbio_cache_size(struct btrfs_fs_info *info, unsigned int size);
++#endif
+ void btrfs_raid56_uncache_range(struct btrfs_fs_info *info, u64 start, u64 len);
+
+ #endif
+diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
+index 3ac1fa608d3b5..78688c36f8b02 100644
+--- a/fs/btrfs/sysfs.c
++++ b/fs/btrfs/sysfs.c
+@@ -25,6 +25,7 @@
+ #include "misc.h"
+ #include "fs.h"
+ #include "accessors.h"
++#include "raid56.h"
+
+ /*
+ * Structure name Path
+@@ -520,12 +521,39 @@ static const struct attribute *discard_attrs[] = {
+
+ #ifdef CONFIG_BTRFS_DEBUG
+
++/* The raid56 stripe cache limit (raid56.c), 0 to disable the cache. */
++static ssize_t btrfs_rbio_cache_size_show(struct kobject *kobj,
++ struct kobj_attribute *a, char *buf)
++{
++ struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
++
++ return sysfs_emit(buf, "%u\n", READ_ONCE(fs_info->rbio_cache_size));
++}
++
++static ssize_t btrfs_rbio_cache_size_store(struct kobject *kobj,
++ struct kobj_attribute *a,
++ const char *buf, size_t len)
++{
++ struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
++ unsigned int val;
++ int ret;
++
++ ret = kstrtouint(buf, 10, &val);
++ if (ret)
++ return ret;
++ btrfs_set_rbio_cache_size(fs_info, val);
++ return len;
++}
++BTRFS_ATTR_RW(debug_mount, rbio_cache_size, btrfs_rbio_cache_size_show,
++ btrfs_rbio_cache_size_store);
++
+ /*
+ * Per-filesystem runtime debugging exported via sysfs.
+ *
+ * Path: /sys/fs/btrfs/UUID/debug/
+ */
+ static const struct attribute *btrfs_debug_mount_attrs[] = {
++ BTRFS_ATTR_PTR(debug_mount, rbio_cache_size),
+ NULL,
+ };
+
+--
+2.47.3
+