| | |
|---|---|
| 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` `9c8c8bde702a` (octopus of all 20 topics) |
-| lane head | `zygo-misc-next-zb64` `0d1010a882d3`; its own commits on top of `testing` (kernel configs, `covers/`) are not exported |
+| integration branch | `misc-next/testing` `26986baa3476` (octopus of all 20 topics) |
+| lane head | `zygo-misc-next-zb64` `aee0ffb1fba5`; 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` | 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-fixes` | 13 | `a3629b15df87` | Zygo | new; replaces `covers/raid56-rbio-fixes.txt` (2 of these patches) | **patch 13 is DO-NOT-UPSTREAM** (rbio cache size debug knob); patch 12 (no write-back after abort) to be folded into 11 |
| `raid56-scrub-replace` | 13 | `9970d7e44abf` | Filipe Manana, Zygo | new | patch 1 is Filipe's, already in btrfs/for-next (`ec0795c045c3`) |
| `stripe-alloc` | 116 | `a23064467620` | Zygo | rewritten 2026-10-22 by subtopic (rebuild planned, REORDER-PLAN.md) | RFC; subtopic 6 (debug) not for merging; stripe_meta may be dropped (STRIPE-META-CLAIMS.md) |
| `low-space` | 3 | `4f26c7c44896` | Zygo | from misc-next `covers/`, patch 3 paragraph added 2026-10-22 | reserve off by default; patch 3 fixes an upstream relocation abort (FLUSH_LIMIT merge refill) |
| `replace-fixes` | 7 | `43c8a1e60a5a` | Zygo | new | patch 7 has a btrfs-progs counterpart (`topics/replace-abort-uncorrectable`) |
| `dev-stats` | 1 | `55ade1cf195c` | Zygo | new, 0/1 (2026-10-21) | behaviour change, offered for rejection; independent of every other series |
| `resize-missing` | 1 | `8763f9e2126d` | Qu Wenruo, rewritten by Zygo | new, 0/1 (2026-10-21) | Qu's 2019 patch reworked: grow checks now return, absolute sizes checked; Zygo's Signed-off-by to be added before sending |
-| `read-repair-fixes` | 1 | `a0d12f2d99a3` | Zygo | new, 0/1 (2026-10-22) | upstream bug since v6.3 (Fixes: 7609afac6775, Cc: stable # 6.6+): NULL end_io when a repair bio fails to submit |
+| `read-repair-fixes` | 5 | `c2a23411b4c7` | Zygo | new 2026-10-22; rewritten for 0/5 | read repair and scrub after an abort: NULL end_io (v6.3+), same csum root, no repair writes after abort; stable tags on 1-4, none on 5 (raid56) |
## Applying one series
- `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` `9c8c8bde702a`.
+ directories reflect the lane at `misc-next/testing` `26986baa3476`.
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 bcf8dbc7fdf8dc3455b08855149f351046850b1c..c10f75587c2310196a13faf797c868d294cc276d 100644
+index 38b645a1e6131b407a4dd122cb164bd6659a9010..ce47e10d6bc020a5bc7ababadf24ca08b8aa4b15 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -991,13 +991,15 @@ static void cache_rbio(struct btrfs_raid_bio *rbio)
/*
* 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
+@@ -4731,6 +4975,14 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ if (rbio->scrub_readonly)
+ goto submit_write;
+
++ /*
++ * No data or parity is repaired after a transaction abort or another
++ * filesystem error. A running replace still gets the parity copied
++ * to its target.
++ */
++ if (unlikely(!btrfs_can_submit_repair_write(rbio->bioc->fs_info)))
++ goto replace;
++
+ /* Write the data sectors rebuilt from P and Q. */
+ for_each_set_bit(sectornr, &rebuilt, rbio->stripe_nsectors) {
+ const int stripe = rebuilt_stripe[sectornr];
+@@ -4755,13 +5007,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ * time to start writing. Make bios for everything from the
+ * higher layers (the bio_list in our rbio) and our p/q. Ignore
+ * everything else.
+- *
+- * No parity is repaired after a transaction abort or another
+- * filesystem error. A running replace still gets the parity copied
+- * to its target.
+ */
+- if (unlikely(!btrfs_can_submit_repair_write(rbio->bioc->fs_info)))
+- goto replace;
+ for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors) {
+ phys_addr_t *paddrs;
+
diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
index d71c5c5f4b2ed8f930cb1c2991f98fbafba35261..cfcd9bce4652f861774763844076ef755cc70475 100644
--- a/fs/btrfs/raid56.h
+void btrfs_rbio_unpin_stale(struct btrfs_fs_info *fs_info);
#endif
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 34998749fc548fc6f3a730a1064d60fa1b4cf931..82ab5fbf983e2e58e2e8cd43924d5614a0a857cf 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -1289,7 +1289,8 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
+ bitmap_andnot(&repaired, &errors.init_error_bitmap, &error,
+ stripe->nr_sectors);
+ if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors) &&
+- !test_bit(SCRUB_STRIPE_FLAG_OWN_SCRUB, &stripe->state)) {
++ !test_bit(SCRUB_STRIPE_FLAG_OWN_SCRUB, &stripe->state) &&
++ btrfs_can_submit_repair_write(fs_info)) {
+ if (btrfs_is_zoned(fs_info)) {
+ btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
+ } else {
diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index 72c6b4c4c2772ec75bf3e0645aed5d8546da4576..08ecac160dfc0e4e9734c1fc72528ecc3e08d854 100644
--- a/fs/btrfs/space-info.c
-From f7e693d10be20b7f83d5ba52569425bc68c36807 Mon Sep 17 00:00:00 2001
+From a3629b15df8728a96adce866b6411d73000db1fb Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Tue, 20 Oct 2026 22:28:28 -0400
-Subject: [PATCH 00/12] btrfs: raid56: rbio lifetime and cache fixes, error reporting
+Date: Thu, 22 Oct 2026 18:47:39 -0400
+Subject: [PATCH 00/13] 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
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
+Patch 12 keeps patch 11's write-back from running after a transaction
+abort. A repair write after an abort is a write the filesystem has
+promised not to make; the same rule now applies to read repair and scrub
+(see the read-repair-fixes series). It belongs folded into patch 11
+before sending, since patch 11 is not upstream yet. It has been
+build- and boot-tested only.
+
+Patch 13 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 (12):
+Zygo Blaxell (13):
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
csum
btrfs: raid56: count I/O errors in the device stats
btrfs: raid56: write back the sectors a sub-stripe write repaired
+ btrfs: raid56: no RMW write-back of repaired sectors after an abort
DO-NOT-UPSTREAM: btrfs: raid56: debug knob for the rbio stripe cache
size
fs/btrfs/bio.h | 2 +
fs/btrfs/extent-tree.c | 10 +
fs/btrfs/fs.h | 4 +
- fs/btrfs/inode.c | 16 ++
- fs/btrfs/raid56.c | 633 ++++++++++++++++++++++++++++++++++++++---
+ fs/btrfs/inode.c | 16 +
+ fs/btrfs/raid56.c | 642 ++++++++++++++++++++++++++++++++++++++---
fs/btrfs/raid56.h | 14 +-
fs/btrfs/sysfs.c | 28 ++
- 8 files changed, 677 insertions(+), 43 deletions(-)
+ 8 files changed, 686 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/12] btrfs: log a message when dropping an extent due to IO
+Subject: [PATCH 01/13] 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/12] btrfs: raid56: fix use-after-free of rbio in bio end_io
+Subject: [PATCH 02/13] 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/12] btrfs: propagate a split bio's error when the failing
+Subject: [PATCH 03/13] 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/12] btrfs: raid56: drop cached rbios when their stripes'
+Subject: [PATCH 04/13] 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/12] btrfs: raid56: verify reconstructed tree blocks
+Subject: [PATCH 05/13] 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/12] btrfs: raid56: keep a reference on a stolen cached rbio
+Subject: [PATCH 06/13] 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/12] btrfs: raid56: do not unhash a cached rbio that has
+Subject: [PATCH 07/13] 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/12] btrfs: raid56: do not let a failed write leave its
+Subject: [PATCH 08/13] 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/12] btrfs: raid56: rebuild from Q when a sector rebuilt
+Subject: [PATCH 09/13] 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/12] btrfs: raid56: count I/O errors in the device stats
+Subject: [PATCH 10/13] 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
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
+Subject: [PATCH 11/13] btrfs: raid56: write back the sectors a sub-stripe
write repaired
To: linux-btrfs@vger.kernel.org
+++ /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
-
--- /dev/null
+From a5de3170c464978f18f53af4f66d4f5f31594596 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Thu, 22 Oct 2026 14:32:16 -0400
+Subject: [PATCH 12/13] btrfs: raid56: no RMW write-back of repaired sectors
+ after an abort
+To: linux-btrfs@vger.kernel.org
+
+A sub-stripe write writes back the sectors its read phase repaired
+("btrfs: raid56: write back the sectors a sub-stripe write repaired").
+Data writeback can still reach the RAID56 layer after a transaction
+abort, and the write-back would then repair other sectors of the full
+stripe on disk after the abort. Read repair does not write back on a
+read-only filesystem or after an abort or another filesystem error;
+do the same here. The sub-stripe write itself is unchanged, and the
+repaired sectors stay stale on disk as they were before the write-back
+existed.
+
+Fixes: 95d142c556b5 ("btrfs: raid56: write back the sectors a sub-stripe write repaired")
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/raid56.c | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 5732c2d8ea359..be0addae72928 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -2860,9 +2860,18 @@ static bool rmw_repair_verified(struct btrfs_raid_bio *rbio, int stripe_nr,
+ */
+ static unsigned long *rmw_repaired_sectors(struct btrfs_raid_bio *rbio)
+ {
++ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
+ unsigned long *repaired = NULL;
+ int total_sector_nr;
+
++ /*
++ * No repair writes on a read-only filesystem, nor after a transaction
++ * abort or another filesystem error, as for read repair.
++ */
++ if (unlikely(sb_rdonly(fs_info->sb) || BTRFS_FS_ERROR(fs_info) ||
++ test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)))
++ return NULL;
++
+ 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;
+--
+2.47.3
+
--- /dev/null
+From a3629b15df8728a96adce866b6411d73000db1fb 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 13/13] 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 be0addae72928..2fd869dd50495 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
+
-From a0d12f2d99a3c84f17228e42e6b0c0c99a798711 Mon Sep 17 00:00:00 2001
+From c2a23411b4c71e3359639de7b8af9e2e502e40d7 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Thu, 22 Oct 2026 14:05:56 -0400
-Subject: [PATCH 0/1] btrfs: fix a NULL end_io call when a read repair bio fails to submit
+Date: Thu, 22 Oct 2026 18:47:42 -0400
+Subject: [PATCH 0/5] btrfs: read repair and scrub after a transaction abort
To: linux-btrfs@vger.kernel.org
-Since read repair moved to the storage layer in v6.3, the repair bio has
-a NULL end_io. Its normal completion goes through btrfs_check_read_bio()
-and never calls end_io. But btrfs_submit_chunk() can fail a bio before
-it reaches a device: when the block mapping, the bio split or the
-checksum lookup fails. It then calls end_io, and a btrfs-endio worker
-jumps to address 0. The original read never completes, and a later
-unmount hangs on it.
-
-The checksum lookup is the failure seen in practice. A buffered read of
-an old extent searches the csum commit root, but the repair bio searches
-the running transaction's csum tree. After a transaction abort, the
-cleanup frees that transaction's dirty tree blocks, and a lookup that
-reaches one reads never-written disk and fails with -EIO. It was found
-when a relocation at a full filesystem forced the filesystem read-only:
-six btrfs-endio workers oopsed within 1.5 seconds.
-
-The patch gives the repair bio an end_io that only this failure
-reaches. It fails the sector the way an exhausted repair does, so the
-read returns -EIO. It does not try another mirror, because the mapping
-and the checksum lookup fail the same way for every copy.
-
-Tested on misc-next and 6.18, KASAN kernels, raid1:
-- A deterministic abort trigger (fail a log commit's superblock write,
- drop the page cache, read a corrupted tail) oopses both lanes.
- With the patch the read fails with -EIO in under
- half a second, and the filesystem unmounts.
-- fail_function on btrfs_search_slot, limited to the repair lookup:
- the lanes oops; with the patch, 3 of 3 runs per lane return -EIO, with
- every injection confirmed inside a repair lookup.
-- Ordinary read repair (raid1 corrupt mirror, raid6 and raid1c3
- corrupt-recovery) still returns correct data with the patch.
-
-Not addressed here: the repair bio could search the same csum root as
-the original read, so that repair still works after an abort.
-
-Zygo Blaxell (1):
+After a transaction abort, read repair crashes, returns -EIO although a
+good copy exists, or writes to the disks. This series makes it return
+the good copy and write nothing. The rule it applies: after an abort the
+filesystem makes no more writes, repair writes included, but it may
+still repair in memory to satisfy a read.
+
+Patch 1 fixes a NULL pointer call. Since read repair moved to the
+storage layer in v6.3, the repair bio has a NULL end_io. If
+btrfs_submit_chunk() fails it before it reaches a device (block mapping,
+bio split or checksum lookup), end_io is called and a btrfs-endio worker
+jumps to address 0; the read never completes and unmount hangs. It was
+found when a relocation at a full filesystem forced it read-only: six
+workers oopsed within 1.5 seconds. The new end_io fails the sector the
+way an exhausted repair does.
+
+Patch 2 is why the lookup failed. A buffered read of an old extent
+searches the csum commit root, but its repair bio searched the running
+transaction's csum tree. After an abort the cleanup frees that tree's
+dirty blocks, and the lookup reads never-written disk. The repair bio
+now searches the same root as the read it repairs, so after an abort the
+reader gets the good copy.
+
+Patch 3 stops read repair from writing the good copy back after an
+abort. btrfs_repair_io_failure() only checked sb_rdonly(), but an abort
+sets TRANS_ABORTED and the fs error before SB_RDONLY, the emergency
+shutdown never sets SB_RDONLY, and neither do mount-time errors. A new
+helper also checks the error and abort states; it covers data and tree
+block repair.
+
+Patches 4 and 5 do the same for scrub's read-repair write-back and for
+raid56 parity scrub, which never checked the filesystem state: after an
+abort that is not a commit, a running scrub went on repairing through
+every remaining block group. The dev-replace target copy is unchanged.
+Patch 5 is raid56 and so carries no stable tag.
+
+Tested on misc-next and 6.18, KASAN kernels. A write detector counts
+every write, discard and flush to the member devices from the abort to
+after unmount; a known write inside that window is counted in every
+valid run.
+- Read after an abort, one mirror corrupt: the lanes return -EIO; with
+ the series, correct data and no writes (3 of 3 per lane).
+- Emergency shutdown (misc-next): the lane rewrites the bad copy (16
+ writes); with the series, none.
+- Scrub after an abort: the lanes write a "fixed up" sector 13.8 s after
+ the forced read-only; with the series, none (3 of 3 per lane).
+- The patch 1 trigger (fail_function on the repair's csum lookup): the
+ lanes oops; with the series, -EIO, 3 of 3 per lane.
+- Ordinary read repair and raid6/raid1c3 corrupt recovery still return
+ correct data.
+
+Not addressed: data writeback of pages dirtied before an abort still
+reaches the disks (2-4 writes on every kernel tested). A shutdown blocks
+it; an abort does not.
+
+Zygo Blaxell (5):
btrfs: give the read repair bio an end_io for submit failures
+ btrfs: look up a repair read's csums in the same root as the failed
+ read
+ btrfs: do not write back a read repair after a transaction abort
+ btrfs: scrub: do not write back repairs after a transaction abort
+ btrfs: raid56: do not write back parity scrub repairs after a
+ transaction abort
- fs/btrfs/bio.c | 22 +++++++++++++++++++++-
- 1 file changed, 21 insertions(+), 1 deletion(-)
+ fs/btrfs/bio.c | 31 +++++++++++++++++++++++++++++--
+ fs/btrfs/fs.h | 13 +++++++++++++
+ fs/btrfs/raid56.c | 7 +++++++
+ fs/btrfs/scrub.c | 6 +++++-
+ 4 files changed, 54 insertions(+), 3 deletions(-)
base-commit: 0c48d26d46bdd6422bb91ba7f1c519a2993116dc
From a0d12f2d99a3c84f17228e42e6b0c0c99a798711 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 02:16:13 -0400
-Subject: [PATCH 1/1] btrfs: give the read repair bio an end_io for submit
+Subject: [PATCH 1/5] btrfs: give the read repair bio an end_io for submit
failures
To: linux-btrfs@vger.kernel.org
--- /dev/null
+From 49af9ece472850eaf172378e92763600c4792be9 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Thu, 22 Oct 2026 14:31:46 -0400
+Subject: [PATCH 2/5] btrfs: look up a repair read's csums in the same root as
+ the failed read
+To: linux-btrfs@vger.kernel.org
+
+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 | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
+index 5002fb69c0f03..e9c07762089db 100644
+--- a/fs/btrfs/bio.c
++++ b/fs/btrfs/bio.c
+@@ -285,6 +285,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);
+--
+2.47.3
+
--- /dev/null
+From 96c712193047ea097b1270e9fdea7685966a49d4 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Thu, 22 Oct 2026 14:31:48 -0400
+Subject: [PATCH 3/5] btrfs: do not write back a read repair after a
+ transaction abort
+To: linux-btrfs@vger.kernel.org
+
+btrfs_repair_bbio_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 emergency shutdown (btrfs_force_shutdown()) sets fs_error but
+ deliberately leaves SB_RDONLY clear. A read that still reaches the
+ filesystem after the shutdown, such as a page fault on a mapping made
+ before it or a tree block read, repairs a bad copy and writes it
+ back.
+- An error during mount, before SB_BORN, sets fs_error without
+ SB_RDONLY.
+
+Nothing should be written after an abort or a shutdown. Add
+btrfs_can_submit_repair_write(), which also checks the error and the
+abort bit, and use it in btrfs_repair_bbio_failure(). That covers data
+read repair and tree block repair (btrfs_repair_eb_io_failure()). The
+read still gets the good copy's data.
+
+read-repair-submit-fail-test.sh RR_ARM=shutdown (raid56-wh-harness)
+maps a raid1 file whose tail is corrupt on one mirror, shuts the
+filesystem down, drops the tail from the page cache and touches it
+through the mapping. Without this patch the read repair writes the
+tail back to the corrupt mirror after the shutdown; with it the read
+returns the file's data, nothing is written to either device and the
+corrupt copy stays as it was.
+
+Fixes: 8ceaad6cd6e7 ("btrfs: do not ASSERT() when the fs flips RO inside btrfs_repair_io_failure()")
+Fixes: 9b2839451dfc ("btrfs: introduce a new shutdown state")
+Cc: stable@vger.kernel.org # 6.18+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/bio.c | 2 +-
+ fs/btrfs/fs.h | 13 +++++++++++++
+ 2 files changed, 14 insertions(+), 1 deletion(-)
+
+diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
+index e9c07762089db..be7e16851cbb4 100644
+--- a/fs/btrfs/bio.c
++++ b/fs/btrfs/bio.c
+@@ -951,7 +951,7 @@ int btrfs_repair_bbio_failure(struct btrfs_bio *bbio, const struct bvec_iter *or
+ * The fs either mounted RO or hit critical errors, no need
+ * to continue repairing.
+ */
+- if (unlikely(sb_rdonly(fs_info->sb)))
++ if (unlikely(!btrfs_can_submit_repair_write(fs_info)))
+ return 0;
+
+ if (btrfs_repair_one_zone(fs_info, logical))
+diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
+index 2dd167c32d612..4ab5770150cf1 100644
+--- a/fs/btrfs/fs.h
++++ b/fs/btrfs/fs.h
+@@ -1215,6 +1215,19 @@ static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info)
+ (unlikely(test_bit(BTRFS_FS_STATE_LOG_CLEANUP_ERROR, \
+ &(fs_info)->fs_state)))
+
++/*
++ * Return true if a repair write (read repair, scrub) may be submitted: never on
++ * a read-only filesystem, nor after a transaction abort or another
++ * filesystem error. A transaction abort sets BTRFS_FS_STATE_TRANS_ABORTED,
++ * then the error, and only then SB_RDONLY, and an emergency shutdown sets the
++ * error without SB_RDONLY, so checking SB_RDONLY alone is not enough.
++ */
++static inline bool btrfs_can_submit_repair_write(const struct btrfs_fs_info *fs_info)
++{
++ return !sb_rdonly(fs_info->sb) && !BTRFS_FS_ERROR(fs_info) &&
++ !test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state);
++}
++
+ static inline bool btrfs_is_shutdown(const struct btrfs_fs_info *fs_info)
+ {
+ return unlikely(test_bit(BTRFS_FS_STATE_EMERGENCY_SHUTDOWN, &fs_info->fs_state));
+--
+2.47.3
+
--- /dev/null
+From 9736ec0710971ca14f5204fe604a209766fb9466 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Thu, 22 Oct 2026 14:31:49 -0400
+Subject: [PATCH 4/5] btrfs: scrub: do not write back repairs after a
+ transaction abort
+To: linux-btrfs@vger.kernel.org
+
+A scrub that is running when a transaction aborts outside the commit
+path keeps going. (An abort in the commit path cancels it in
+cleanup_transaction(), unless relocation is running.) Once the abort
+has forced the filesystem read-only, btrfs_inc_block_group_ro() takes
+its path for a read-only mount, which needs no transaction, so the
+scrub goes on through every remaining block group. For every bad
+sector it finds, scrub_stripe_read_repair_worker() reads a good copy
+and writes it back with scrub_write_sectors(). It does not look at the
+filesystem state (sctx->readonly is fixed when the scrub starts), so
+these writes go out after the abort, to a filesystem that was forced
+read-only.
+
+Skip the write-back when btrfs_can_submit_repair_write() says no. The
+scrub still reads, verifies and reports. A running dev-replace still
+copies to its target, which __btrfs_handle_fs_error() leaves running on
+purpose.
+
+read-repair-submit-fail-test.sh RR_ARM=scrubabort (raid56-wh-harness)
+corrupts a sector of a raid1 data block group on one mirror, starts a
+speed-limited scrub, and aborts a transaction (a log commit whose
+superblock writes fail) while the scrub is in that block group but
+before it reaches the sector. Without this patch the scrub writes the
+sector back after the abort; with it nothing is written to either
+device after the abort and the bad copy stays as it was.
+
+Fixes: 54765392a1b9 ("btrfs: scrub: introduce helper to queue a stripe for scrub")
+Cc: stable@vger.kernel.org # 6.6+
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/scrub.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
+index 479c0e037015a..6f27040d03eb2 100644
+--- a/fs/btrfs/scrub.c
++++ b/fs/btrfs/scrub.c
+@@ -1213,10 +1213,14 @@ static void scrub_stripe_read_repair_worker(struct work_struct *work)
+ /*
+ * Submit the repaired sectors. For zoned case, we cannot do repair
+ * in-place, but queue the bg to be relocated.
++ *
++ * Nothing is written back after a transaction abort or another
++ * filesystem error that happened while the scrub was running.
+ */
+ bitmap_andnot(&repaired, &errors.init_error_bitmap, &error,
+ stripe->nr_sectors);
+- if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors)) {
++ if (!sctx->readonly && !bitmap_empty(&repaired, stripe->nr_sectors) &&
++ btrfs_can_submit_repair_write(fs_info)) {
+ if (btrfs_is_zoned(fs_info)) {
+ btrfs_repair_one_zone(fs_info, sctx->stripes[0].bg->start);
+ } else {
+--
+2.47.3
+
--- /dev/null
+From c2a23411b4c71e3359639de7b8af9e2e502e40d7 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Thu, 22 Oct 2026 14:31:49 -0400
+Subject: [PATCH 5/5] btrfs: raid56: do not write back parity scrub repairs
+ after a transaction abort
+To: linux-btrfs@vger.kernel.org
+
+A RAID56 parity scrub writes the parity it finds wrong back to the
+device in finish_parity_scrub(), without looking at the filesystem
+state. A scrub keeps running after a transaction abort outside the
+commit path (see the previous patch), so these writes can go out after
+the abort, to a filesystem that was forced read-only.
+
+Skip the writes to the scrubbed stripe when
+btrfs_can_submit_repair_write() says no. A running dev-replace still
+gets the parity copied to its target, which __btrfs_handle_fs_error()
+leaves running on purpose.
+
+Not covered by a dedicated test: read-repair-submit-fail-test.sh
+RR_ARM=scrubabort exercises the non-parity scrub repair on raid1.
+
+Fixes: 5a6ac9eacb49 ("Btrfs, raid56: support parity scrub on raid56")
+Assisted-by: Claude:claude-opus-5-5
+---
+ fs/btrfs/raid56.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 5ec31299f1c30..c5a2d12956aeb 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -2774,7 +2774,13 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ * time to start writing. Make bios for everything from the
+ * higher layers (the bio_list in our rbio) and our p/q. Ignore
+ * everything else.
++ *
++ * No parity is repaired after a transaction abort or another
++ * filesystem error. A running replace still gets the parity copied
++ * to its target.
+ */
++ if (unlikely(!btrfs_can_submit_repair_write(rbio->bioc->fs_info)))
++ goto replace;
+ for_each_set_bit(sectornr, &rbio->dbitmap, rbio->stripe_nsectors) {
+ phys_addr_t *paddrs;
+
+@@ -2785,6 +2791,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+ goto cleanup;
+ }
+
++replace:
+ if (!is_replace)
+ goto submit_write;
+
+--
+2.47.3
+
| `corrupt-recovery-test.sh` (defaults: raid6 data + raid1c3 metadata, STOCK and STRIPE_ALLOC, 1-2 corrupt devices, corrupt + missing) | read repair (raid6 rebuild, raid1c3 mirror) still recovers, detects and repairs within-tolerance corruption | 1 | ~10 min | PASS on all four (mn lane/cand, 6.18 lane/cand): bad=0 on every case, detectors moved, scrub uncorrectable 0, post-scrub re-read clean | 2026-10-22 | ehive -fi kernels | ddd893f | harness `forensics/q-repair-20261022/*-corrupt-recovery.log` |
| W=1 `fs/btrfs/bio.o` | no new warnings | 1 | - | none on either lane, before or after the patch; bzImage links on all four kernels | 2026-10-22 | mn 2550544f9c6e / c5dc301213ee; 6.18 7626a4a10198 / c3dbf52a35a8 | - | `build-{mn,618}/w1-*.txt` |
| W=1 `make fs/btrfs/` (lane), bio.o (candidate), -fi configs | no new warnings | 1 | - | mn lane 2 pre-existing (stripe_whole_bytes unused, tree-log.c frame size), candidate bio.o 0; 6.18 lane 3 pre-existing, candidate bio.o 0; all four bzImages link | 2026-10-22 | as above (ehive) | - | harness `forensics/q-repair-20261022/build/` |
-| `read-repair-submit-fail-test.sh` RR_ARM=abortgood (**candidate, not promoted**) | after an abort, a read of a sector corrupt on one mirror returns the good copy's data; nothing is written to any member after the abort; the bad copy stays bad | P2 (P3) | ~1 min | lane FAIL as expected on mn lane 0d1010a882d3 (`7.3.0-rc7+ #1`) 3/3 and 6.18 lane 19a5204c6cda (`6.18.57+ #1`) 3/3: EIO, 17 repair lookups failed, 0 writes. Candidate PASS on mn 3e3c635885e4 (`#2`) 3/3: data correct in 0.06-0.10 s, 16 repair lookups, 0 failed, 0 writes, bad copy unchanged; 6.18 176448c38243 (`#2`) 3/3: data correct in 0.07-0.13 s, 0 writes, bad copy unchanged | 2026-10-22 | ehive, KASAN, -fi configs | 96cec4a (4c343a3) | harness `forensics/s-repair-20261022/` |
-| same, RR_ARM=shutdown (**candidate, not promoted**; misc-next only, FS_IOC_SHUTDOWN) | after an emergency shutdown (fs error set, SB_RDONLY clear), a read through an existing mapping is repaired in memory and nothing is written | P3 | ~1 min | lane FAIL as expected on #5 (568c45b64012) 1/1 and mn lane (`#1`) 3/3: 16 write requests after the shutdown, bad copy rewritten. Candidate PASS mn (`#2`) 3/3: data correct, 0 writes. 6.18: SKIP (no shutdown ioctl) | 2026-10-22 | as above | 96cec4a | as above |
-| same, RR_ARM=scrubabort (**candidate, not promoted**) | a scrub running when a log-commit abort forces RO writes no repair after the abort | P4a (P4b not exercised: raid1) | ~1.5 min | lane FAIL as expected on #5 1/1 (+1 INVALID, window missed), mn lane (`#1`) 3/3 and 6.18 lane (`#1`) 3/3: 1 write request, the bad sector "fixed up" ~14 s after "forced readonly", the scrub ran to the device end. Candidate PASS mn (`#2`) 3/3: the scrub found the bad sector after the abort and wrote nothing; 6.18 (`#2`) 3/3: the same | 2026-10-22 | as above | 96cec4a | as above |
+| `read-repair-submit-fail-test.sh` RR_ARM=abortgood (promoted 2026-10-22) | after an abort, a read of a sector corrupt on one mirror returns the good copy's data; nothing is written to any member after the abort; the bad copy stays bad | P2 (P3) | ~1 min | lane FAIL as expected on mn lane 0d1010a882d3 (`7.3.0-rc7+ #1`) 3/3 and 6.18 lane 19a5204c6cda (`6.18.57+ #1`) 3/3: EIO, 17 repair lookups failed, 0 writes. Candidate PASS on mn 3e3c635885e4 (`#2`) 3/3: data correct in 0.06-0.10 s, 16 repair lookups, 0 failed, 0 writes, bad copy unchanged; 6.18 176448c38243 (`#2`) 3/3: data correct in 0.07-0.13 s, 0 writes, bad copy unchanged | 2026-10-22 | ehive, KASAN, -fi configs | 96cec4a (4c343a3) | harness `forensics/s-repair-20261022/` |
+| same, RR_ARM=shutdown (promoted 2026-10-22; misc-next only, FS_IOC_SHUTDOWN) | after an emergency shutdown (fs error set, SB_RDONLY clear), a read through an existing mapping is repaired in memory and nothing is written | P3 | ~1 min | lane FAIL as expected on #5 (568c45b64012) 1/1 and mn lane (`#1`) 3/3: 16 write requests after the shutdown, bad copy rewritten. Candidate PASS mn (`#2`) 3/3: data correct, 0 writes. 6.18: SKIP (no shutdown ioctl) | 2026-10-22 | as above | 96cec4a | as above |
+| same, RR_ARM=scrubabort (promoted 2026-10-22) | a scrub running when a log-commit abort forces RO writes no repair after the abort | P4a (P4b not exercised: raid1) | ~1.5 min | lane FAIL as expected on #5 1/1 (+1 INVALID, window missed), mn lane (`#1`) 3/3 and 6.18 lane (`#1`) 3/3: 1 write request, the bad sector "fixed up" ~14 s after "forced readonly", the scrub ran to the device end. Candidate PASS mn (`#2`) 3/3: the scrub found the bad sector after the abort and wrote nothing; 6.18 (`#2`) 3/3: the same | 2026-10-22 | as above | 96cec4a | as above |
| same, RR_ARM=dirtyabort (probe; **not fixed by the candidate**) | data pages dirtied before an abort are not written back after it | none | ~1.5 min | FAIL on every kernel: #5, mn lane, mn cand: 4 write requests after the abort; 6.18 lane: 2; 6.18 cand: 4. See Open | 2026-10-22 | as above | 0b766f2 | as above |
-| regression on the candidates: inject x3, repair x2, corrupt-recovery-test.sh (**candidate, not promoted**) | the existing patch's coverage still holds with P2-P4b | 1-P4b | ~45 min | mn cand (`#2`): inject PASS 3/3 (EIO in 1.07-1.15 s, no oops, unmounted), repair PASS 2/2, corrupt-recovery PASS. 6.18 cand (`#2`): inject PASS 3/3 (EIO in 1.61-1.71 s, no oops, unmounted), repair PASS 2/2, corrupt-recovery PASS. The abort arm is INVALID on both candidates by design (2/2 each): P2 removes its trigger (the repair lookup no longer fails); the inject arm still covers the end_io | 2026-10-22 | as above | 0b766f2 | as above |
-| W=1 `make fs/btrfs/` at every candidate commit (**candidate, not promoted**) | no new warnings | P2-P4b, R56 | - | none new on either lane at any commit (P4a alone, mn topic dcf1d86516b3: 0 warnings, only scrub.o rebuilt; P4b 26372901233e: 0, only raid56.o); only the pre-existing frame-size and stripe_whole_bytes warnings, which reappear when fs.h changes rebuild their objects; all four bzImages link | 2026-10-22 | ehive | - | harness `forensics/s-repair-20261022/build/` |
+| regression on the candidates: inject x3, repair x2, corrupt-recovery-test.sh (promoted 2026-10-22) | the existing patch's coverage still holds with P2-P4b | 1-P4b | ~45 min | mn cand (`#2`): inject PASS 3/3 (EIO in 1.07-1.15 s, no oops, unmounted), repair PASS 2/2, corrupt-recovery PASS. 6.18 cand (`#2`): inject PASS 3/3 (EIO in 1.61-1.71 s, no oops, unmounted), repair PASS 2/2, corrupt-recovery PASS. The abort arm is INVALID on both candidates by design (2/2 each): P2 removes its trigger (the repair lookup no longer fails); the inject arm still covers the end_io | 2026-10-22 | as above | 0b766f2 | as above |
+| W=1 `make fs/btrfs/` at every candidate commit (promoted 2026-10-22) | no new warnings | P2-P4b, R56 | - | none new on either lane at any commit (P4a alone, mn topic dcf1d86516b3: 0 warnings, only scrub.o rebuilt; P4b 26372901233e: 0, only raid56.o); only the pre-existing frame-size and stripe_whole_bytes warnings, which reappear when fs.h changes rebuild their objects; all four bzImages link | 2026-10-22 | ehive | - | harness `forensics/s-repair-20261022/build/` |
**read-repair-submit-fail-test.sh, abort arm.**
intact, detected, and repaired by scrub. It covers the normal repair path
the patch touches (repair bios that submit cleanly), not the failure path.
-## Candidate follow-up (s-repair, candidate, not promoted)
+## Follow-up patches 2-5 (s-repair; promoted 2026-10-22: misc-next topic c2a23411b4c7, zb64 aee0ffb1fba5; 6.18 topic a9fe36da2539, zb64 8fcf012e67b0. The raid56 RMW write-back guard is raid56-fixes patch 12.)
Zygo's rule (2026-10-22): no writes after an abort, repair writes
included; a read may use the commit root to repair in memory but must not