* Information about one device.
*
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index c1eb4f95ce7b9811c24d8ded80e3a0387ee900ce..9b09e06dd7587301f14706684721046e8800ca51 100644
+index 068dd5d168b4e02b2e2fe136ea4a018d32ed95c0..a067b76455eef3cdb5004e7592c0efe02ae8c66e 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6967,7 +6967,293 @@ bool btrfs_chunk_raid56_mirrored(struct btrfs_fs_info *fs_info, u64 logical)
+@@ -7055,7 +7055,293 @@ bool btrfs_chunk_raid56_mirrored(struct btrfs_fs_info *fs_info, u64 logical)
return ret;
}
# raid56 rbio cache size knob, into this test-only topic. Both commits
# carry the marker; listed so the topic directory never appears.
topic test-knobs
+
+# 2026-11-06: patches by others that the covers name as posted separately
+# (Josef Bacik's "btrfs: data integrity fixes" v2 2/5-5/5, 2026-11-03;
+# Cheng Yongkang's v2, 2026-10-26). The lanes carry them at the head of
+# the topic that needs them; the mails do not re-send them.
+subject btrfs: clear dirty blocks after a delalloc failure
+subject btrfs: wait for ordered extent IO in fast fsync
+subject btrfs: don't report success for a skipped log sync
+subject btrfs: don't trim the target of a device replace
+subject btrfs: remove devid kobject when deleting a missing device
-From b3af80d4e58b937314a4840129845611db1b825e Mon Sep 17 00:00:00 2001
+From df0e45e0fe79ddc8c332cba8ab8678b37e55c160 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:05 -0400
+Date: Fri, 6 Nov 2026 05:48:16 -0500
Subject: [PATCH 00/12] btrfs: allocator hints (Kai Krakow's series)
To: linux-btrfs@vger.kernel.org
8 files changed, 496 insertions(+), 21 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From af409ce5aeba16510d02a8c344f94001beabe239 Mon Sep 17 00:00:00 2001
+From 70b8869bdde1abe1cda61a670281adccd8644b11 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Fri, 10 Jul 2026 23:49:05 +0200
Subject: [PATCH 01/12] btrfs: add new Kconfig option for btrfs allocator hints
-From 87fc4b5c2c1974db3f65fb1efc730af62045eeb2 Mon Sep 17 00:00:00 2001
+From 025e6cb878674de3e63be998690d8f91cedc8e86 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:51:17 +0200
Subject: [PATCH 02/12] btrfs: add flags to give a hint to the chunk allocator
-From 91e0e6d3c504d907e3884bda1192d6ccb934fef8 Mon Sep 17 00:00:00 2001
+From 19e88b66354301a0a91ea82fef201b32b6dd343a Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:22:50 +0200
Subject: [PATCH 03/12] btrfs: export dev_item.type in
-From d908265472c1ecc2ec5422d102772c8d1a8b892d Mon Sep 17 00:00:00 2001
+From fa8f8e9aa28a809cf539c833e4c0b8e3e8445abb Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:25:21 +0200
Subject: [PATCH 04/12] btrfs: change the DEV_ITEM 'type' field via sysfs
-From 6c61b29687de931f3b71949d973babca0bfc6c7c Mon Sep 17 00:00:00 2001
+From e69b32add2614ea47fb1b77cb9e73d1b103146a5 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:18:02 +0200
Subject: [PATCH 05/12] btrfs: add allocator_hint mode
instead of relying on df only.
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index ce78a9441c64f..7af7af717c9ba 100644
+index 3d4ef6725de0e..ab2c610cd24fa 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -185,6 +185,21 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
const char *btrfs_bg_type_to_raid_name(u64 flags)
{
const int index = btrfs_bg_flags_to_raid_index(flags);
-@@ -5576,13 +5591,20 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info,
+@@ -5588,13 +5603,20 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info,
}
/*
if (di_a->max_avail > di_b->max_avail)
return -1;
if (di_a->max_avail < di_b->max_avail)
-@@ -5953,16 +5975,97 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -5965,16 +5987,97 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
devices_info[ndevs].max_avail = max_avail;
devices_info[ndevs].total_avail = total_avail;
devices_info[ndevs].dev = device;
}
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 75b1179776c80..3cd7d94554151 100644
+index 891bc2432870a..da7c03871b838 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -603,6 +603,9 @@ struct btrfs_device_info {
-From e6522b0e9a45322c222d5498159e533a775a3107 Mon Sep 17 00:00:00 2001
+From 0e062c9666d8bdf4036bb08f1014deca2eacb770 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:09:55 +0200
Subject: [PATCH 06/12] btrfs: add allocator_hint for no allocation preferred
default:
return false;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 7af7af717c9ba..c1fc62270289d 100644
+index ab2c610cd24fa..b8ef5f66ec982 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -196,6 +196,7 @@ static const int alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
/* the other values are set to 0 */
};
#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
-@@ -6012,7 +6013,10 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6024,7 +6025,10 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
* sort also by hint (metadata hint
* higher priority)
*/
-From 957e128e0135432355d6d9f352d2ab6556f1d456 Mon Sep 17 00:00:00 2001
+From 15e8021ae885879813111e630ededa70628175f7 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Fri, 10 Jul 2026 23:51:46 +0200
Subject: [PATCH 07/12] btrfs: add allocator_hint to disable allocation
default:
return false;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index c1fc62270289d..00ecf2b1b30f4 100644
+index b8ef5f66ec982..586fb9edb19b3 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -192,6 +192,7 @@ enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags
[BTRFS_DEV_ALLOCATION_DATA_ONLY] = -1,
[BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0,
[BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 1,
-@@ -5994,6 +5995,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6006,6 +6007,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
*/
if (BTRFS_DEV_ALLOCATION_METADATA_ONLY == hint)
continue;
/*
* if a data chunk must be allocated,
* sort also by hint (data disk
-@@ -6008,6 +6014,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6020,6 +6026,11 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
*/
if (BTRFS_DEV_ALLOCATION_DATA_ONLY == hint)
continue;
-From ea8ce1d15132db90dc7067e3fbd4bdb5bebf77d9 Mon Sep 17 00:00:00 2001
+From 6ef13f21e247ac4d1ad203cfbfc58826646f66e7 Mon Sep 17 00:00:00 2001
From: KeinNiemand <18308201+KeinNiemand@users.noreply.github.com>
Date: Sun, 30 Aug 2026 14:50:54 +0200
Subject: [PATCH 08/12] btrfs: honor allocator hints for fixed-width mirrors
1 file changed, 13 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 00ecf2b1b30f4..eba473441b55a 100644
+index 586fb9edb19b3..3bde22ffbd7c0 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6064,6 +6064,19 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6076,6 +6076,19 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
break;
}
-From fa99f98d377069191545f2d42062ad5c1c3aad65 Mon Sep 17 00:00:00 2001
+From 7fbece5a12d5b4477bd520ac74756a3b3b0aa12a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 00:44:02 -0400
Subject: [PATCH 09/12] btrfs: allocator hints: move the hint values out of the
under the Kconfig guard. That keeps them out of userspace, which was the
intent, without the leak.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/volumes.h | 21 +++++++++++++++++++++
include/uapi/linux/btrfs_tree.h | 25 -------------------------
2 files changed, 21 insertions(+), 25 deletions(-)
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 3cd7d94554151..ae48bcec15a94 100644
+index da7c03871b838..91efbea27d04c 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -598,6 +598,27 @@ struct btrfs_io_context {
-From 57b6931d10a94b5031d8e352a07386f48b1dde10 Mon Sep 17 00:00:00 2001
+From 1e8e85d87b5bea59f545e977e229199963980318 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 00:44:58 -0400
Subject: [PATCH 10/12] btrfs: allocator hints: keep the hint across device
that still gets past these checks (remove, or a replace that finishes
after them) ends the transaction without aborting it and returns -ENODEV.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/Kconfig | 9 +++++----
fs/btrfs/dev-replace.c | 6 ++++++
You are advised to watch your free space closely with btrfs tools
instead of relying on df only.
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
-index cdfe093e5c5c4..ac0e3e99ac653 100644
+index 3c48cc714fef2..903501370cbb1 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
-@@ -990,6 +990,12 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
+@@ -989,6 +989,12 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
btrfs_dev_name(tgt_device));
clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &tgt_device->dev_state);
tgt_device->devid = src_device->devid;
-From 6bf6a73de3e2ea08417c5094587ac931b29fed85 Mon Sep 17 00:00:00 2001
+From 719bd5945ed892368c908d1fd3e5e5f04d8083c2 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 10:55:00 -0400
Subject: [PATCH 11/12] btrfs: allocator hints: don't run a transaction from
commit cannot write the old type and clear the bit on a weakly ordered
machine.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/Kconfig | 9 ++---
fs/btrfs/dev-replace.c | 3 ++
You are advised to watch your free space closely with btrfs tools
instead of relying on df only.
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
-index ac0e3e99ac653..8c6f156524332 100644
+index 903501370cbb1..062fd114f5088 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
-@@ -996,6 +996,9 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
+@@ -995,6 +995,9 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
* on the target writes type 0 over it.
*/
tgt_device->type = src_device->type;
BTRFS_ATTR_RW(devid, type, btrfs_devinfo_type_show, btrfs_devinfo_type_store);
#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index d265fac023e58..39d2718256019 100644
+index cd7dff5ba59b6..4171a5200bede 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
-@@ -2285,6 +2285,9 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2280,6 +2280,9 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
goto lockdep_trans_commit_start_release;
}
if (!test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &cur_trans->flags)) {
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index eba473441b55a..4017a4c07ce0c 100644
+index 3bde22ffbd7c0..34ef420d35ce8 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -3267,7 +3267,7 @@ int btrfs_update_device(struct btrfs_trans_handle *trans, struct btrfs_device *d
+@@ -3279,7 +3279,7 @@ int btrfs_update_device(struct btrfs_trans_handle *trans, struct btrfs_device *d
dev_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_item);
btrfs_set_device_id(leaf, dev_item, device->devid);
btrfs_set_device_io_align(leaf, dev_item, device->io_align);
btrfs_set_device_io_width(leaf, dev_item, device->io_width);
btrfs_set_device_sector_size(leaf, dev_item, device->sector_size);
-@@ -8730,6 +8730,61 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
+@@ -8742,6 +8742,61 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
return ret;
}
{
btrfs_dev_stat_inc(dev, index);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index ae48bcec15a94..f4dd7fd5e4d97 100644
+index 91efbea27d04c..df5c6db129869 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -110,6 +110,8 @@ static_assert(BTRFS_RAID_RAID1C4 == 8);
/* Special value encoding failure to write primary super block. */
#define BTRFS_SUPER_PRIMARY_WRITE_ERROR (INT_MAX / 2)
-@@ -820,6 +822,11 @@ int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
+@@ -819,6 +821,11 @@ int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
int btrfs_init_writeback_bio_size(struct btrfs_fs_info *fs_info);
int btrfs_run_dev_stats(struct btrfs_trans_handle *trans);
-From b3af80d4e58b937314a4840129845611db1b825e Mon Sep 17 00:00:00 2001
+From df0e45e0fe79ddc8c332cba8ab8678b37e55c160 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 18 Oct 2026 15:50:43 -0400
Subject: [PATCH 12/12] btrfs: allocator hints: make the available space
abort and no lost files, and statfs reports the space data can really
use.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/space-info.c | 3 +-
fs/btrfs/super.c | 4 +
/* We don't want to do full transaction commit from inside sysfs */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 4017a4c07ce0c..39235ea12b746 100644
+index 34ef420d35ce8..30e4e217bbe64 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -200,7 +200,101 @@ static const int alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = {
const char *btrfs_bg_type_to_raid_name(u64 flags)
{
-@@ -5634,7 +5728,7 @@ static int btrfs_cmp_device_info(const void *a, const void *b)
+@@ -5646,7 +5740,7 @@ static int btrfs_cmp_device_info(const void *a, const void *b)
*/
static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
struct btrfs_device_info *devices_info,
u64 *allocated)
{
const struct btrfs_raid_attr *raid_attr = &btrfs_raid_array[type];
-@@ -5654,6 +5748,13 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
+@@ -5666,6 +5760,13 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state))
continue;
if (device->total_bytes > device->bytes_used +
device->per_profile_allocated)
avail = device->total_bytes - device->bytes_used -
-@@ -5688,6 +5789,16 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
+@@ -5700,6 +5801,16 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
}
sort(devices_info, ndevs, sizeof(struct btrfs_device_info),
btrfs_cmp_device_info, NULL);
ndevs = rounddown(ndevs, raid_attr->devs_increment);
if (ndevs < raid_attr->devs_min)
return -ENOSPC;
-@@ -5710,7 +5821,7 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
+@@ -5722,7 +5833,7 @@ static int alloc_virtual_chunk(struct btrfs_fs_info *fs_info,
}
static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
u64 *result_ret)
{
struct btrfs_device_info *devices_info = NULL;
-@@ -5738,7 +5849,8 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
+@@ -5750,7 +5861,8 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list)
device->per_profile_allocated = 0;
result += allocated;
out:
-@@ -5749,10 +5861,19 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
+@@ -5761,10 +5873,19 @@ static int calc_one_profile_avail(struct btrfs_fs_info *fs_info,
return 0;
}
int ret;
/*
-@@ -5762,21 +5883,33 @@ void btrfs_update_per_profile_avail(struct btrfs_fs_info *fs_info)
+@@ -5774,21 +5895,33 @@ void btrfs_update_per_profile_avail(struct btrfs_fs_info *fs_info)
if (btrfs_is_zoned(fs_info))
goto error;
spin_unlock(&fs_info->fs_devices->per_profile_lock);
}
-@@ -5979,56 +6112,9 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -5991,56 +6124,9 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
devices_info[ndevs].dev = device;
#ifdef CONFIG_BTRFS_ALLOCATOR_HINTS
#endif /* CONFIG_BTRFS_ALLOCATOR_HINTS */
++ndevs;
-@@ -6054,28 +6140,8 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
+@@ -6066,28 +6152,8 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices,
* select the minimum set of disks grouped by hint that
* can host the chunk
*/
BUG_ON(ndevs > ctl->ndevs);
ctl->ndevs = ndevs;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index f4dd7fd5e4d97..3fd0200e8ec73 100644
+index df5c6db129869..31538a7bf7fa6 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -337,6 +337,13 @@ enum btrfs_read_policy {
spinlock_t per_profile_lock;
};
-@@ -948,18 +957,26 @@ const char *btrfs_bg_type_to_raid_name(u64 flags);
+@@ -947,18 +956,26 @@ const char *btrfs_bg_type_to_raid_name(u64 flags);
int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
bool btrfs_verify_dev_items(const struct btrfs_fs_info *fs_info);
void btrfs_update_per_profile_avail(struct btrfs_fs_info *fs_info);
-From 46b25327a7470027c3c6ad6314e9bef9c6da6a4e Mon Sep 17 00:00:00 2001
+From e38f7c20705d1ff55bd3ed96b2e3c83650037984 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:03:59 -0400
+Date: Fri, 6 Nov 2026 05:48:14 -0500
Subject: [PATCH 0/3] btrfs: balance resume selects what the original request selected
To: linux-btrfs@vger.kernel.org
Zygo Blaxell (3):
btrfs: free queued remap chunks when balance bails out
- btrfs: replace the usage=90 balance resume heuristic with a vrange
- bound
- btrfs: keep the usage=90 resume heuristic for balance items without a
- vrange
+ btrfs: replace the balance resume heuristics with a vrange bound
+ btrfs: keep the old resume filters for balance items without a vrange
- fs/btrfs/fs.h | 6 +++
- fs/btrfs/volumes.c | 92 +++++++++++++++++++++++++++++++++++++++-------
- 2 files changed, 85 insertions(+), 13 deletions(-)
+ fs/btrfs/fs.h | 6 ++
+ fs/btrfs/volumes.c | 215 +++++++++++++++++++++++++++++++++++----------
+ fs/btrfs/volumes.h | 6 ++
+ 3 files changed, 181 insertions(+), 46 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 3a4e04bb5fbc61a0b85d7919e17d3364357862a6 Mon Sep 17 00:00:00 2001
+From d0136e6493082d001aa33ed4174dae6062abb49a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 13 Oct 2026 01:05:21 -0400
Subject: [PATCH 1/3] btrfs: free queued remap chunks when balance bails out
group and none is left read-only.
Fixes: 81e5a4551c32 ("btrfs: allow balancing remap tree")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/volumes.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index ce78a9441c64f..2ed57bc7a9905 100644
+index 3d4ef6725de0e..788f60910acf5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -4744,6 +4744,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
+@@ -4756,6 +4756,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
}
}
error:
--- /dev/null
+From d406ea315d237d2860e238c0cccdf9dc2c94b3c0 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Wed, 16 Sep 2026 02:29:10 -0400
+Subject: [PATCH 2/3] btrfs: replace the balance resume heuristics with a
+ vrange bound
+To: linux-btrfs@vger.kernel.org
+
+When a balance is resumed after a pause or an unmount,
+update_balance_args() adds a usage=90 filter to every chunk type that is
+not being converted. That changes the set of block groups the original
+request selected. It skips full block groups the interrupted balance had
+not reached yet, so the resumed balance can finish without having done
+what was asked, and it selects again any block group the interrupted
+balance created that is less than 90% full, relocating the same data a
+second time. For the chunk types that are being converted it adds the
+soft filter instead, so the resume does not convert again the block
+groups the interrupted balance converted, but it also skips the ones
+that already had the target profile when the balance started, which the
+original request selected.
+
+Replace it with a bound fixed when the balance starts. Before the
+balance item is written, limit the vrange filter of each chunk type to
+the addresses below the next chunk to be allocated: add a 0..end range
+when the request had no vrange filter, or lower the end of the one it
+had. Every block group that existed when the balance started stays
+selected until the balance relocates it.
+
+New chunks are allocated after the last chunk, but relocation can remove
+the highest chunks without allocating any (their data fits in free space
+lower down), and the next chunk would then reuse their addresses, below
+the bound. A resumed balance would select it again, although the
+interrupted one, walking downward, never would have. So while a balance
+item exists, find_next_chunk() never returns an address below the bound:
+an in-memory floor, set when the balance starts and when the balance
+item is recovered at mount, and cleared when the item is deleted. Every
+chunk allocated in that time, relocation targets included, stays outside
+the range, on the first run and after a resume. The gap the floor can
+leave in the logical address space is harmless.
+
+A resume now uses the arguments exactly as they were stored: the bound
+already keeps out every block group the interrupted balance created,
+converted ones included, so neither the usage filter nor the soft filter
+is needed, and update_balance_args() goes away.
+
+The bound does not move as the balance progresses. Block groups the
+balance has relocated are gone, so on resume the walk only revisits the
+chunks it left in place above the point where it stopped (filtered out,
+ENOSPC, active swapfile) and checks them against the filters again.
+Nothing is skipped.
+
+Because the bound is written with the balance item and never changes,
+there is no progress to persist: a resume after an unmount or a crash
+needs no extra writes.
+
+A balance item recovered at mount is limited in the same way before the
+floor is set from it: a vrange 0..end is added to each chunk type that
+has none, and a vrange that ends above the next chunk is lowered to it.
+That covers items written by older kernels, which have no vrange or a
+vrange the user gave, which can end anywhere (a 1 TiB end would put
+every new chunk at 1 TiB and above). A bound written by this kernel
+changes only when relocation removed the highest chunks and allocated
+none above it; no chunk exists between the next chunk and the old end,
+so lowering it drops nothing. When the recovered arguments change,
+they are written back to the balance item once, when the balance
+resumes, so a resume that is interrupted again resumes with the same
+bound and not with a new one that includes the chunks the first resume
+allocated.
+
+A balance item written by an older kernel therefore resumes with the
+bound and without the usage or soft filter: the resumed balance restarts
+from the beginning, relocating again every block group the request
+selects, including the ones the interrupted run created or converted,
+but it skips none.
+
+The bound is visible: `btrfs balance status -v`, the
+BTRFS_IOC_BALANCE_PROGRESS ioctl and the "balance: start" and "balance:
+resume" log lines show a vrange the user did not give.
+
+---
+ fs/btrfs/fs.h | 6 ++
+ fs/btrfs/volumes.c | 178 ++++++++++++++++++++++++++++++++-------------
+ fs/btrfs/volumes.h | 6 ++
+ 3 files changed, 140 insertions(+), 50 deletions(-)
+
+diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
+index 2dd167c32d612..a42aa4de2bcc6 100644
+--- a/fs/btrfs/fs.h
++++ b/fs/btrfs/fs.h
+@@ -785,6 +785,12 @@ struct btrfs_fs_info {
+ atomic_t balance_cancel_req;
+ struct btrfs_balance_control *balance_ctl;
+ wait_queue_head_t balance_wait_q;
++ /*
++ * 0, or the end of the balance's vrange bound: while a balance item
++ * exists (running or paused) find_next_chunk() allocates at or above
++ * it, so the balance never selects a chunk it allocated.
++ */
++ u64 balance_chunk_floor;
+
+ /* Cancellation requests for chunk relocation */
+ atomic_t reloc_cancel_req;
+diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
+index 788f60910acf5..9251087396828 100644
+--- a/fs/btrfs/volumes.c
++++ b/fs/btrfs/volumes.c
+@@ -2035,7 +2035,7 @@ static u64 find_next_chunk(struct btrfs_fs_info *fs_info)
+ }
+ read_unlock(&fs_info->mapping_tree_lock);
+
+- return ret;
++ return max(ret, READ_ONCE(fs_info->balance_chunk_floor));
+ }
+
+ static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
+@@ -3970,13 +3970,27 @@ static void btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk,
+ disk->stripes_max = cpu_to_le32(cpu->stripes_max);
+ }
+
++static void set_balance_item(struct extent_buffer *leaf,
++ struct btrfs_balance_item *item,
++ const struct btrfs_balance_control *bctl)
++{
++ struct btrfs_disk_balance_args disk_bargs;
++
++ btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data);
++ btrfs_set_balance_data(leaf, item, &disk_bargs);
++ btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->meta);
++ btrfs_set_balance_meta(leaf, item, &disk_bargs);
++ btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->sys);
++ btrfs_set_balance_sys(leaf, item, &disk_bargs);
++ btrfs_set_balance_flags(leaf, item, bctl->flags & ~BTRFS_BALANCE_RESUME);
++}
++
+ static int insert_balance_item(struct btrfs_fs_info *fs_info,
+ struct btrfs_balance_control *bctl)
+ {
+ struct btrfs_root *root = fs_info->tree_root;
+ struct btrfs_trans_handle *trans;
+ struct btrfs_balance_item *item;
+- struct btrfs_disk_balance_args disk_bargs;
+ struct btrfs_path *path;
+ struct extent_buffer *leaf;
+ struct btrfs_key key;
+@@ -4005,14 +4019,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
+ item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
+
+ memzero_extent_buffer(leaf, (unsigned long)item, sizeof(*item));
+-
+- btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->data);
+- btrfs_set_balance_data(leaf, item, &disk_bargs);
+- btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->meta);
+- btrfs_set_balance_meta(leaf, item, &disk_bargs);
+- btrfs_cpu_balance_args_to_disk(&disk_bargs, &bctl->sys);
+- btrfs_set_balance_sys(leaf, item, &disk_bargs);
+- btrfs_set_balance_flags(leaf, item, bctl->flags);
++ set_balance_item(leaf, item, bctl);
+ out:
+ btrfs_free_path(path);
+ if (ret == 0)
+@@ -4023,6 +4030,43 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
+ return ret;
+ }
+
++/* Write the arguments of a resumed balance to its existing item. */
++static int update_balance_item(struct btrfs_fs_info *fs_info,
++ const struct btrfs_balance_control *bctl)
++{
++ struct btrfs_root *root = fs_info->tree_root;
++ struct btrfs_trans_handle *trans;
++ BTRFS_PATH_AUTO_FREE(path);
++ struct btrfs_key key;
++ int ret;
++
++ path = btrfs_alloc_path();
++ if (!path)
++ return -ENOMEM;
++
++ trans = btrfs_start_transaction(root, 0);
++ if (IS_ERR(trans))
++ return PTR_ERR(trans);
++
++ key.objectid = BTRFS_BALANCE_OBJECTID;
++ key.type = BTRFS_TEMPORARY_ITEM_KEY;
++ key.offset = 0;
++
++ ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
++ if (ret > 0)
++ ret = -ENOENT;
++ if (ret < 0) {
++ btrfs_end_transaction(trans);
++ return ret;
++ }
++
++ set_balance_item(path->nodes[0],
++ btrfs_item_ptr(path->nodes[0], path->slots[0],
++ struct btrfs_balance_item), bctl);
++ btrfs_release_path(path);
++ return btrfs_commit_transaction(trans);
++}
++
+ static int del_balance_item(struct btrfs_fs_info *fs_info)
+ {
+ struct btrfs_root *root = fs_info->tree_root;
+@@ -4064,47 +4108,61 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
+ return ret;
+ }
+
++static bool limit_balance_vrange(struct btrfs_balance_args *bargs, u64 end)
++{
++ if (!(bargs->flags & BTRFS_BALANCE_ARGS_VRANGE)) {
++ bargs->flags |= BTRFS_BALANCE_ARGS_VRANGE;
++ bargs->vstart = 0;
++ bargs->vend = end;
++ return true;
++ }
++ if (bargs->vend <= end)
++ return false;
++ bargs->vend = end;
++ return true;
++}
++
+ /*
+- * This is a heuristic used to reduce the number of chunks balanced on
+- * resume after balance was interrupted.
++ * Limit the request to the chunks that exist now. The bound is written with
++ * the balance item and never moves, so there is no progress to persist. New
++ * chunks are allocated after the last chunk, but once relocation has removed
++ * the highest chunks the last chunk is lower than the bound, so while the
++ * balance item exists find_next_chunk() also observes balance_chunk_floor:
++ * every chunk allocated in that time, relocation targets included, stays
++ * outside the range, on this run and after a resume.
++ *
++ * Return true if any of the arguments changed.
+ */
+-static void update_balance_args(struct btrfs_balance_control *bctl)
++static bool limit_balance_to_existing_chunks(struct btrfs_fs_info *fs_info,
++ struct btrfs_balance_control *bctl)
+ {
+- /*
+- * Turn on soft mode for chunk types that were being converted.
+- */
+- if (bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT)
+- bctl->data.flags |= BTRFS_BALANCE_ARGS_SOFT;
+- if (bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT)
+- bctl->sys.flags |= BTRFS_BALANCE_ARGS_SOFT;
+- if (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)
+- bctl->meta.flags |= BTRFS_BALANCE_ARGS_SOFT;
++ const u64 end = find_next_chunk(fs_info);
++ bool changed = false;
+
+- /*
+- * Turn on usage filter if is not already used. The idea is
+- * that chunks that we have already balanced should be
+- * reasonably full. Don't do it for chunks that are being
+- * converted - that will keep us from relocating unconverted
+- * (albeit full) chunks.
+- */
+- if (!(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE) &&
+- !(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
+- !(bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
+- bctl->data.flags |= BTRFS_BALANCE_ARGS_USAGE;
+- bctl->data.usage = 90;
+- }
+- if (!(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE) &&
+- !(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
+- !(bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
+- bctl->sys.flags |= BTRFS_BALANCE_ARGS_USAGE;
+- bctl->sys.usage = 90;
+- }
+- if (!(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE) &&
+- !(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
+- !(bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
+- bctl->meta.flags |= BTRFS_BALANCE_ARGS_USAGE;
+- bctl->meta.usage = 90;
+- }
++ if (bctl->flags & BTRFS_BALANCE_DATA)
++ changed |= limit_balance_vrange(&bctl->data, end);
++ if (bctl->flags & BTRFS_BALANCE_METADATA)
++ changed |= limit_balance_vrange(&bctl->meta, end);
++ if (bctl->flags & BTRFS_BALANCE_SYSTEM)
++ changed |= limit_balance_vrange(&bctl->sys, end);
++ return changed;
++}
++
++/* The highest vrange end of the selected chunk types, 0 if none has one. */
++static u64 balance_chunk_floor(const struct btrfs_balance_control *bctl)
++{
++ u64 floor = 0;
++
++ if ((bctl->flags & BTRFS_BALANCE_DATA) &&
++ (bctl->data.flags & BTRFS_BALANCE_ARGS_VRANGE))
++ floor = max(floor, bctl->data.vend);
++ if ((bctl->flags & BTRFS_BALANCE_METADATA) &&
++ (bctl->meta.flags & BTRFS_BALANCE_ARGS_VRANGE))
++ floor = max(floor, bctl->meta.vend);
++ if ((bctl->flags & BTRFS_BALANCE_SYSTEM) &&
++ (bctl->sys.flags & BTRFS_BALANCE_ARGS_VRANGE))
++ floor = max(floor, bctl->sys.vend);
++ return floor;
+ }
+
+ /*
+@@ -4123,6 +4181,7 @@ static void reset_balance_state(struct btrfs_fs_info *fs_info)
+
+ kfree(bctl);
+ ret = del_balance_item(fs_info);
++ WRITE_ONCE(fs_info->balance_chunk_floor, 0);
+ if (ret)
+ btrfs_handle_fs_error(fs_info, ret, NULL);
+ }
+@@ -5088,6 +5147,9 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
+ btrfs_bg_type_to_raid_name(data_target));
+ }
+
++ if (!(bctl->flags & BTRFS_BALANCE_RESUME))
++ limit_balance_to_existing_chunks(fs_info, bctl);
++
+ ret = insert_balance_item(fs_info, bctl);
+ if (ret && ret != -EEXIST)
+ goto out;
+@@ -5098,11 +5160,16 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
+ spin_lock(&fs_info->balance_lock);
+ fs_info->balance_ctl = bctl;
+ spin_unlock(&fs_info->balance_lock);
++ WRITE_ONCE(fs_info->balance_chunk_floor,
++ balance_chunk_floor(bctl));
+ } else {
+ BUG_ON(ret != -EEXIST);
+- spin_lock(&fs_info->balance_lock);
+- update_balance_args(bctl);
+- spin_unlock(&fs_info->balance_lock);
++ if (bctl->update_item) {
++ ret = update_balance_item(fs_info, bctl);
++ if (ret)
++ goto out;
++ bctl->update_item = false;
++ }
+ }
+
+ ASSERT(!test_bit(BTRFS_FS_BALANCE_RUNNING, &fs_info->flags));
+@@ -5255,6 +5322,17 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
+ btrfs_balance_sys(leaf, item, &disk_bargs);
+ btrfs_disk_balance_args_to_cpu(&bctl->sys, &disk_bargs);
+
++ /*
++ * Bound the request as a new balance would be: an item written by an
++ * older kernel has no vrange, and one a user gave to such a kernel can
++ * end anywhere. The floor is still 0, so find_next_chunk() returns the
++ * end of the last chunk, and lowering a vend above it drops no block
++ * group from the range. The bound is written back to the item when
++ * the balance resumes, so a resume that is interrupted again keeps it.
++ */
++ bctl->update_item = limit_balance_to_existing_chunks(fs_info, bctl);
++ WRITE_ONCE(fs_info->balance_chunk_floor, balance_chunk_floor(bctl));
++
+ /*
+ * This should never happen, as the paused balance state is recovered
+ * during mount without any chance of other exclusive ops to collide.
+diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
+index 891bc2432870a..e7112257014e8 100644
+--- a/fs/btrfs/volumes.h
++++ b/fs/btrfs/volumes.h
+@@ -665,6 +665,12 @@ struct btrfs_balance_control {
+
+ u64 flags;
+
++ /*
++ * The arguments recovered at mount were bounded and differ from the
++ * balance item: write them back when the balance resumes.
++ */
++ bool update_item;
++
+ struct btrfs_balance_progress stat;
+ };
+
+--
+2.47.3
+
+++ /dev/null
-From cff18d11ec6e4922138d46fdf89802343fab4c70 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Wed, 16 Sep 2026 02:29:10 -0400
-Subject: [PATCH 2/3] btrfs: replace the usage=90 balance resume heuristic with
- a vrange bound
-To: linux-btrfs@vger.kernel.org
-
-When a balance is resumed after a pause or an unmount,
-update_balance_args() adds a usage=90 filter to every chunk type that is
-not being converted. That changes the set of block groups the original
-request selected. It skips full block groups the interrupted balance had
-not reached yet, so the resumed balance can finish without having done
-what was asked, and it selects again any block group the interrupted
-balance created that is less than 90% full, relocating the same data a
-second time.
-
-Replace it with a bound fixed when the balance starts. Before the
-balance item is written, limit the vrange filter of each chunk type to
-the addresses below the next chunk to be allocated: add a 0..end range
-when the request had no vrange filter, or lower the end of the one it
-had. Every block group that existed when the balance started stays
-selected until the balance relocates it.
-
-New chunks are allocated after the last chunk, but relocation can remove
-the highest chunks without allocating any (their data fits in free space
-lower down), and the next chunk would then reuse their addresses, below
-the bound. A resumed balance would select it again, although the
-interrupted one, walking downward, never would have. So while a balance
-item exists, find_next_chunk() never returns an address below the bound:
-an in-memory floor, set when the balance starts and when the balance
-item is recovered at mount, and cleared when the item is deleted. Every
-chunk allocated in that time, relocation targets included, stays outside
-the range, on the first run and after a resume. The gap the floor can
-leave in the logical address space is harmless.
-
-The bound does not move as the balance progresses. Block groups the
-balance has relocated are gone, so on resume the walk only revisits the
-chunks it left in place above the point where it stopped (filtered out,
-ENOSPC, active swapfile) and checks them against the filters again.
-Nothing is skipped.
-
-Because the bound is written with the balance item and never changes,
-there is no progress to persist: a resume after an unmount or a crash
-needs no extra writes.
-
-A balance item written by an older kernel has no bound and now resumes
-without the usage filter: the resumed balance restarts from the
-beginning, relocating again every block group the request selects,
-including the ones the interrupted run created, but it skips none.
-
-The bound is visible: `btrfs balance status -v`, the
-BTRFS_IOC_BALANCE_PROGRESS ioctl and the "balance: start" and "balance:
-resume" log lines show a vrange the user did not give.
-
-Assisted-by: Codex:gpt-5
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/fs.h | 6 ++++
- fs/btrfs/volumes.c | 87 ++++++++++++++++++++++++++++++----------------
- 2 files changed, 64 insertions(+), 29 deletions(-)
-
-diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
-index 2dd167c32d612..a42aa4de2bcc6 100644
---- a/fs/btrfs/fs.h
-+++ b/fs/btrfs/fs.h
-@@ -785,6 +785,12 @@ struct btrfs_fs_info {
- atomic_t balance_cancel_req;
- struct btrfs_balance_control *balance_ctl;
- wait_queue_head_t balance_wait_q;
-+ /*
-+ * 0, or the end of the balance's vrange bound: while a balance item
-+ * exists (running or paused) find_next_chunk() allocates at or above
-+ * it, so the balance never selects a chunk it allocated.
-+ */
-+ u64 balance_chunk_floor;
-
- /* Cancellation requests for chunk relocation */
- atomic_t reloc_cancel_req;
-diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 2ed57bc7a9905..1996ebaeadc76 100644
---- a/fs/btrfs/volumes.c
-+++ b/fs/btrfs/volumes.c
-@@ -2035,7 +2035,7 @@ static u64 find_next_chunk(struct btrfs_fs_info *fs_info)
- }
- read_unlock(&fs_info->mapping_tree_lock);
-
-- return ret;
-+ return max(ret, READ_ONCE(fs_info->balance_chunk_floor));
- }
-
- static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
-@@ -4052,10 +4052,7 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
- return ret;
- }
-
--/*
-- * This is a heuristic used to reduce the number of chunks balanced on
-- * resume after balance was interrupted.
-- */
-+/* Update balance arguments when resuming an interrupted balance. */
- static void update_balance_args(struct btrfs_balance_control *bctl)
- {
- /*
-@@ -4067,34 +4064,58 @@ static void update_balance_args(struct btrfs_balance_control *bctl)
- bctl->sys.flags |= BTRFS_BALANCE_ARGS_SOFT;
- if (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)
- bctl->meta.flags |= BTRFS_BALANCE_ARGS_SOFT;
-+}
-
-- /*
-- * Turn on usage filter if is not already used. The idea is
-- * that chunks that we have already balanced should be
-- * reasonably full. Don't do it for chunks that are being
-- * converted - that will keep us from relocating unconverted
-- * (albeit full) chunks.
-- */
-- if (!(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE) &&
-- !(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
-- !(bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
-- bctl->data.flags |= BTRFS_BALANCE_ARGS_USAGE;
-- bctl->data.usage = 90;
-- }
-- if (!(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE) &&
-- !(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
-- !(bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
-- bctl->sys.flags |= BTRFS_BALANCE_ARGS_USAGE;
-- bctl->sys.usage = 90;
-- }
-- if (!(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE) &&
-- !(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
-- !(bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)) {
-- bctl->meta.flags |= BTRFS_BALANCE_ARGS_USAGE;
-- bctl->meta.usage = 90;
-+static void limit_balance_vrange(struct btrfs_balance_args *bargs, u64 end)
-+{
-+ if (bargs->flags & BTRFS_BALANCE_ARGS_VRANGE) {
-+ bargs->vend = min(bargs->vend, end);
-+ } else {
-+ bargs->flags |= BTRFS_BALANCE_ARGS_VRANGE;
-+ bargs->vstart = 0;
-+ bargs->vend = end;
- }
- }
-
-+/*
-+ * Limit the request to the chunks that exist now. The bound is written with
-+ * the balance item and never moves, so there is no progress to persist. New
-+ * chunks are allocated after the last chunk, but once relocation has removed
-+ * the highest chunks the last chunk is lower than the bound, so while the
-+ * balance item exists find_next_chunk() also observes balance_chunk_floor:
-+ * every chunk allocated in that time, relocation targets included, stays
-+ * outside the range, on this run and after a resume.
-+ */
-+static void limit_balance_to_existing_chunks(struct btrfs_fs_info *fs_info,
-+ struct btrfs_balance_control *bctl)
-+{
-+ const u64 end = find_next_chunk(fs_info);
-+
-+ if (bctl->flags & BTRFS_BALANCE_DATA)
-+ limit_balance_vrange(&bctl->data, end);
-+ if (bctl->flags & BTRFS_BALANCE_METADATA)
-+ limit_balance_vrange(&bctl->meta, end);
-+ if (bctl->flags & BTRFS_BALANCE_SYSTEM)
-+ limit_balance_vrange(&bctl->sys, end);
-+}
-+
-+/* The highest vrange end of the selected chunk types, 0 if none has one. */
-+static u64 balance_chunk_floor(const struct btrfs_balance_control *bctl)
-+{
-+ u64 floor = 0;
-+
-+ if ((bctl->flags & BTRFS_BALANCE_DATA) &&
-+ (bctl->data.flags & BTRFS_BALANCE_ARGS_VRANGE))
-+ floor = max(floor, bctl->data.vend);
-+ if ((bctl->flags & BTRFS_BALANCE_METADATA) &&
-+ (bctl->meta.flags & BTRFS_BALANCE_ARGS_VRANGE))
-+ floor = max(floor, bctl->meta.vend);
-+ if ((bctl->flags & BTRFS_BALANCE_SYSTEM) &&
-+ (bctl->sys.flags & BTRFS_BALANCE_ARGS_VRANGE))
-+ floor = max(floor, bctl->sys.vend);
-+ return floor;
-+}
-+
- /*
- * Clear the balance status in fs_info and delete the balance item from disk.
- */
-@@ -4111,6 +4132,7 @@ static void reset_balance_state(struct btrfs_fs_info *fs_info)
-
- kfree(bctl);
- ret = del_balance_item(fs_info);
-+ WRITE_ONCE(fs_info->balance_chunk_floor, 0);
- if (ret)
- btrfs_handle_fs_error(fs_info, ret, NULL);
- }
-@@ -5076,6 +5098,9 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
- btrfs_bg_type_to_raid_name(data_target));
- }
-
-+ if (!(bctl->flags & BTRFS_BALANCE_RESUME))
-+ limit_balance_to_existing_chunks(fs_info, bctl);
-+
- ret = insert_balance_item(fs_info, bctl);
- if (ret && ret != -EEXIST)
- goto out;
-@@ -5086,6 +5111,8 @@ int btrfs_balance(struct btrfs_fs_info *fs_info,
- spin_lock(&fs_info->balance_lock);
- fs_info->balance_ctl = bctl;
- spin_unlock(&fs_info->balance_lock);
-+ WRITE_ONCE(fs_info->balance_chunk_floor,
-+ balance_chunk_floor(bctl));
- } else {
- BUG_ON(ret != -EEXIST);
- spin_lock(&fs_info->balance_lock);
-@@ -5243,6 +5270,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
- btrfs_balance_sys(leaf, item, &disk_bargs);
- btrfs_disk_balance_args_to_cpu(&bctl->sys, &disk_bargs);
-
-+ WRITE_ONCE(fs_info->balance_chunk_floor, balance_chunk_floor(bctl));
-+
- /*
- * This should never happen, as the paused balance state is recovered
- * during mount without any chance of other exclusive ops to collide.
---
-2.47.3
-
--- /dev/null
+From e38f7c20705d1ff55bd3ed96b2e3c83650037984 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 13 Oct 2026 14:24:01 -0400
+Subject: [PATCH 3/3] btrfs: keep the old resume filters for balance items
+ without a vrange
+To: linux-btrfs@vger.kernel.org
+
+This patch is optional. It is offered so that reviewers can take it or
+drop it; the author's preference is to drop it. The previous patches do
+not depend on it.
+
+A balance item written by a kernel without the vrange bound has no vrange
+filter. With the previous patch alone, a balance that was paused or
+interrupted on such a kernel and is resumed on a new one restarts from
+the beginning: every block group the original request selects is
+relocated again, including the ones the interrupted run created.
+
+This patch restores the old resume adjustments for exactly those items.
+When a chunk type has no vrange filter in the stored item, the resume
+changes its arguments as before: it adds the soft filter if the type is
+being converted, and usage=90 if it has no usage, usage range or convert
+filter. This is decided when the item is recovered at mount, before
+the previous patch adds the bound, and is written back with the bound.
+A chunk type with a vrange, which is every balance started by a kernel
+with the previous patch and any balance the user gave a vrange, relies
+on the vrange and is resumed unchanged.
+
+The trade-off: the legacy resume neither completes the original request
+(block groups more than 90% full are skipped, and so are the ones being
+converted that already had the target profile) nor avoids much work on a
+filesystem that is more than 90% full, and keeping it adds a layer of
+surprising behavior and code for a case that only arises once, when a
+balance spans the kernel upgrade. Without it, such a balance repeats
+work but skips nothing.
+
+---
+ fs/btrfs/volumes.c | 37 +++++++++++++++++++++++++++++++++++++
+ 1 file changed, 37 insertions(+)
+
+diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
+index 9251087396828..baf824b1d72a3 100644
+--- a/fs/btrfs/volumes.c
++++ b/fs/btrfs/volumes.c
+@@ -4108,6 +4108,41 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
+ return ret;
+ }
+
++/*
++ * A balance item written by a kernel without the vrange bound has no vrange
++ * filter. Resume it as those kernels did. A chunk type with a vrange relies
++ * on it and is resumed unchanged.
++ */
++static void update_legacy_balance_args(struct btrfs_balance_args *bargs)
++{
++ if (bargs->flags & BTRFS_BALANCE_ARGS_VRANGE)
++ return;
++
++ /* Turn on soft mode for chunk types that were being converted. */
++ if (bargs->flags & BTRFS_BALANCE_ARGS_CONVERT) {
++ bargs->flags |= BTRFS_BALANCE_ARGS_SOFT;
++ return;
++ }
++
++ /*
++ * Turn on the usage filter if it is not already used. The idea is
++ * that chunks that we have already balanced should be reasonably full.
++ */
++ if (!(bargs->flags & (BTRFS_BALANCE_ARGS_USAGE |
++ BTRFS_BALANCE_ARGS_USAGE_RANGE))) {
++ bargs->flags |= BTRFS_BALANCE_ARGS_USAGE;
++ bargs->usage = 90;
++ }
++}
++
++/* Update the arguments of a balance item recovered at mount. */
++static void update_balance_args(struct btrfs_balance_control *bctl)
++{
++ update_legacy_balance_args(&bctl->data);
++ update_legacy_balance_args(&bctl->sys);
++ update_legacy_balance_args(&bctl->meta);
++}
++
+ static bool limit_balance_vrange(struct btrfs_balance_args *bargs, u64 end)
+ {
+ if (!(bargs->flags & BTRFS_BALANCE_ARGS_VRANGE)) {
+@@ -5329,7 +5364,9 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
+ * end of the last chunk, and lowering a vend above it drops no block
+ * group from the range. The bound is written back to the item when
+ * the balance resumes, so a resume that is interrupted again keeps it.
++ * Adjust the chunk types that have no vrange on disk first.
+ */
++ update_balance_args(bctl);
+ bctl->update_item = limit_balance_to_existing_chunks(fs_info, bctl);
+ WRITE_ONCE(fs_info->balance_chunk_floor, balance_chunk_floor(bctl));
+
+--
+2.47.3
+
+++ /dev/null
-From 46b25327a7470027c3c6ad6314e9bef9c6da6a4e Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Tue, 13 Oct 2026 14:24:01 -0400
-Subject: [PATCH 3/3] btrfs: keep the usage=90 resume heuristic for balance
- items without a vrange
-To: linux-btrfs@vger.kernel.org
-
-This patch is optional. It is offered so that reviewers can take it or
-drop it; the author's preference is to drop it. The previous patches do
-not depend on it.
-
-A balance item written by a kernel without the vrange bound has no vrange
-filter. With the previous patch alone, a balance that was paused or
-interrupted on such a kernel and is resumed on a new one restarts from
-the beginning: every block group the original request selects is
-relocated again, including the ones the interrupted run created.
-
-This patch restores the old heuristic for exactly those items: when a
-chunk type has no usage, convert or vrange filter, the resume adds
-usage=90 as before. Items with a vrange, which is every balance started
-by a kernel with the previous patch and any balance the user gave a
-vrange, rely on the vrange and are unaffected.
-
-The trade-off: the legacy resume neither completes the original request
-(block groups more than 90% full are skipped) nor avoids much work on a
-filesystem that is more than 90% full, and keeping it adds a layer of
-surprising behavior and code for a case that only arises once, when a
-balance spans the kernel upgrade. Without it, such a balance repeats
-work but skips nothing.
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/volumes.c | 29 +++++++++++++++++++++++++++++
- 1 file changed, 29 insertions(+)
-
-diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 1996ebaeadc76..09fcc5d981d8a 100644
---- a/fs/btrfs/volumes.c
-+++ b/fs/btrfs/volumes.c
-@@ -4064,6 +4064,35 @@ static void update_balance_args(struct btrfs_balance_control *bctl)
- bctl->sys.flags |= BTRFS_BALANCE_ARGS_SOFT;
- if (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT)
- bctl->meta.flags |= BTRFS_BALANCE_ARGS_SOFT;
-+
-+ /*
-+ * A balance item written by a kernel without the vrange bound has no
-+ * vrange filter. Resume it as those kernels did: turn on the usage
-+ * filter if no usage, convert or vrange filter is used, on the idea
-+ * that the chunks already balanced should be reasonably full. Items
-+ * with a vrange rely on it instead.
-+ */
-+ if (!(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE) &&
-+ !(bctl->data.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
-+ !(bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
-+ !(bctl->data.flags & BTRFS_BALANCE_ARGS_VRANGE)) {
-+ bctl->data.flags |= BTRFS_BALANCE_ARGS_USAGE;
-+ bctl->data.usage = 90;
-+ }
-+ if (!(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE) &&
-+ !(bctl->sys.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
-+ !(bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
-+ !(bctl->sys.flags & BTRFS_BALANCE_ARGS_VRANGE)) {
-+ bctl->sys.flags |= BTRFS_BALANCE_ARGS_USAGE;
-+ bctl->sys.usage = 90;
-+ }
-+ if (!(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE) &&
-+ !(bctl->meta.flags & BTRFS_BALANCE_ARGS_USAGE_RANGE) &&
-+ !(bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
-+ !(bctl->meta.flags & BTRFS_BALANCE_ARGS_VRANGE)) {
-+ bctl->meta.flags |= BTRFS_BALANCE_ARGS_USAGE;
-+ bctl->meta.usage = 90;
-+ }
- }
-
- static void limit_balance_vrange(struct btrfs_balance_args *bargs, u64 end)
---
-2.47.3
-
-From 420b87ed47953436d52528ef49be054222d039b7 Mon Sep 17 00:00:00 2001
+From 464a17c7110ff10889f59c0230001ef8fde4ca92 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:03:59 -0400
-Subject: [PATCH 0/11] btrfs: fix and simplify inode flag vs compression interactions
+Date: Fri, 6 Nov 2026 05:48:14 -0500
+Subject: [PATCH 00/11] btrfs: fix and simplify inode flag vs compression interactions
To: linux-btrfs@vger.kernel.org
This series fixes problems in the interaction between btrfs inode flags
btrfs: dont propagate nodatacow mount option on files with inherited
compression
+Zygo Blaxell (4):
+ btrfs: fix nodatacow vs compression inode flag conflict check
+ btrfs: allow NODATACOW | NOCOMPRESS
+ btrfs: props: reject NUL bytes in btrfs.compression values
+ btrfs: props: keep compressing inodes with legacy compression property
+ values
+
koraynilay (6):
btrfs: export btrfs_match_compress_type(), move it to compression.h
btrfs: also validate compression levels in
btrfs: add btrfs_compress_typelevel2str() helper
btrfs: preserve btrfs.compression when setting inode flags
-Zygo Blaxell (4):
- btrfs: fix nodatacow vs compression inode flag conflict check
- btrfs: allow NODATACOW | NOCOMPRESS
- btrfs: props: reject NUL bytes in btrfs.compression values
- btrfs: props: keep compressing inodes with legacy compression property
- values
-
fs/btrfs/btrfs_inode.h | 1 +
- fs/btrfs/compression.c | 55 +++++++++++++++++++++++++++++--
+ fs/btrfs/compression.c | 55 ++++++++++++++++++++++++--
fs/btrfs/compression.h | 5 ++-
- fs/btrfs/inode.c | 29 ++++++++++++++---
- fs/btrfs/ioctl.c | 87 ++++++++++++++++++++++++++++++++++----------------
- fs/btrfs/props.c | 78 +++++++++++++++++++++++++++++++++-----------
- fs/btrfs/props.h | 9 ++++++
- fs/btrfs/super.c | 8 -----
+ fs/btrfs/inode.c | 29 +++++++++++---
+ fs/btrfs/ioctl.c | 87 ++++++++++++++++++++++++++++--------------
+ fs/btrfs/props.c | 78 ++++++++++++++++++++++++++++---------
+ fs/btrfs/props.h | 9 +++++
+ fs/btrfs/super.c | 8 ----
8 files changed, 208 insertions(+), 64 deletions(-)
-base-commit: 83cd81353093be02aa7e60874c413ec340e55bce
+
--
2.47.3
--- /dev/null
+From f6f89b848e57b05d5cbda97b4bcd8670519930e0 Mon Sep 17 00:00:00 2001
+From: Filipe Manana <fdmanana@suse.com>
+Date: Mon, 2 Nov 2026 19:55:04 +0000
+Subject: [PATCH 01/11] btrfs: dont propagate nodatacow mount option on files
+ with inherited compression
+To: linux-btrfs@vger.kernel.org
+
+If we set the compression property on a directory and the filesystem was
+mounted with the nodatacow option, then when creating a file under that
+directory we get both the compression and nodatacow attributes set on the
+file. These are incompatible attributes as compression requires COW.
+
+This has a couple unexpected behaviours:
+
+1) If later a user sets another attribute on the file, like immutability
+ or append writing mode for example, the chattr command will fail with
+ -EINVAL since we in the setattr callback (btrfs_fileattr_set()) we do
+ some validation, through a call to check_fsflags(), that rejects having
+ both the nodatacow and compression flags set.
+
+ I.e, doing a simple:
+
+ $ chattr +i file
+ /usr/bin/chattr: Invalid argument while setting flags on file
+
+2) The file ends up not being compressed, which is unexpected since the
+ compression attribute set on a directory/file should have precedence
+ over the global nodatacow mount option.
+
+Example reproducer:
+
+ $ cat test.sh
+ #!/bin/bash
+
+ DEV=/dev/sdi
+ MNT=/mnt/sdi
+
+ mkfs.btrfs -f $DEV
+ mount -o nodatacow $DEV $MNT
+
+ # Create a directory with the compression attribute, so that all files
+ # created under it inherit the compression attribute.
+ mkdir $MNT/dir
+ chattr +c $MNT/dir
+
+ # Now create a file with some data inside the directory.
+ xfs_io -f -c "pwrite 0 128K" $MNT/dir/foo
+
+ # Now try to make the file immutable, it should work.
+ chattr +i $MNT/dir/foo
+
+ umount $MNT
+
+ # Check the file has a compressed extent. It should have since
+ # despite the fs being mounted with nodatacow, the directory has
+ # the compression flag set and so that should take priority and
+ # it's what makes sense.
+ btrfs inspect-internal dump-tree -t 5 $DEV | grep -A 5 'EXTENT_DATA 0'
+
+Running it:
+
+ $ ./test.sh
+ (...)
+ chattr: Invalid argument while setting flags on /mnt/sdi/dir/foo
+ item 11 key (258 EXTENT_DATA 0) itemoff 15529 itemsize 53
+ generation 9 type 1 (regular)
+ extent data disk byte 13631488 nr 131072
+ extent data offset 0 nr 131072 ram 131072
+ extent compression 0 (none)
+ extent encryption 0
+
+Fix this by updating btrfs_create_new_inode() to not apply the mount
+options nodatacow and nodatasum on a file that has inherited compression
+from its parent directory.
+
+A test case will follow soon for fstests.
+
+Signed-off-by: Filipe Manana <fdmanana@suse.com>
+Link: https://lore.kernel.org/r/1c729c63075e727042efdeb07df10a70b0ba1a0d.1793647368.git.fdmanana@suse.com
+Reviewed-by: Qu Wenruo <wqu@suse.com>
+---
+ fs/btrfs/inode.c | 19 ++++++++++++++-----
+ 1 file changed, 14 insertions(+), 5 deletions(-)
+
+diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
+index abaa334714566..0bc668c9ec883 100644
+--- a/fs/btrfs/inode.c
++++ b/fs/btrfs/inode.c
+@@ -6654,11 +6654,20 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
+
+ btrfs_set_inode_mapping_order(BTRFS_I(inode));
+ if (S_ISREG(inode->i_mode)) {
+- if (btrfs_test_opt(fs_info, NODATASUM))
+- BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
+- if (btrfs_test_opt(fs_info, NODATACOW))
+- BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW |
+- BTRFS_INODE_NODATASUM;
++ /*
++ * If we inherited compression from the parent directory, it
++ * takes precedence to nodatacow/nodatasum and we don't set
++ * compression along with nodatacow/nodatasun, otherwise if a
++ * user attempts to change some other attribute (say chattr +i),
++ * it will fail at -EINVAL.
++ */
++ if (!(BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS)) {
++ if (btrfs_test_opt(fs_info, NODATASUM))
++ BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
++ if (btrfs_test_opt(fs_info, NODATACOW))
++ BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW |
++ BTRFS_INODE_NODATASUM;
++ }
+ btrfs_update_inode_mapping_flags(BTRFS_I(inode));
+ }
+
+--
+2.47.3
+
+++ /dev/null
-From 4abdf8c9bc525c0b8b990d4938b26228e9309178 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 16 Aug 2025 22:20:01 -0400
-Subject: [PATCH 1/5] btrfs: fix nodatacow vs compression inode flag conflict
- check
-To: linux-btrfs@vger.kernel.org
-
-Applications expect inode flags to be orthogonal: changes can be combined
-or applied separately in any order, as long as each intermediate state is
-valid and unchanged flags are left untouched.
-
-Commit f37c563bab42 ("btrfs: add missing check for nocow and compression
-inode flags") intended to forbid combining FS_NOCOW_FL with either
-FS_NOCOMP_FL or FS_COMPR_FL. The implementation contained a bug and
-introduced multiple regressions.
-
-Bug: FS_NOCOW_FL (+C) and FS_NOCOMP_FL (+m) can still be set together in
-a single FS_IOC_SETFLAGS call, even though the commit message states this
-combination should be rejected.
-
-Regression 1: Switching from +C+m back to -C-m only works if both flag
-changes are combined into one ioctl; separate -C and -m calls are
-rejected.
-
-Regression 2: Switching between +C-c and -C+c only works if the changes
-are split across multiple ioctls; a combined -C+c call is rejected.
-
-Regression 3: Inodes created on kernels before commit f37c563bab42
-("btrfs: add missing check for nocow and compression inode flags") with
-both COMPR and NOCOW set cannot have any other fsattrs changed on newer
-kernels. Even unrelated operations (such as adding +i, or clearing just
-one of the compression bits) fail with EINVAL, because the conflict
-check rejects the entire ioctl whenever conflicting bits are present,
-even if those bits are not being modified. This makes it impossible to
-manage older files without first undoing their existing flags.
-
-Fix by:
- * Rewriting the conflict checks so FS_NOCOW_FL cannot be combined with
- FS_NOCOMP_FL or FS_COMPR_FL in any ioctl (fixes the original bug and
- regressions 1-2).
- * Allowing existing conflicting flags to remain if they are not modified
- by the ioctl (fixes regression 3).
- * Moving the check later in the flag-validation sequence so that it
- occurs after handling the long-standing rule that FS_NOCOW_FL changes
- are silently ignored on non-empty files. This preserves the pre-existing
- behavior while still applying the corrected conflict logic.
-
-Also commit the new inode flags to the inode before setting the
-compression property, restoring them if the property cannot be set:
-property validation rejects compression on nodatacow inodes based on
-the inode's current flags, which would otherwise reject a single ioctl
-that both clears NOCOW and sets COMPR (regression 2) even with the
-conflict check corrected.
-
-Fixes: f37c563bab42 ("btrfs: add missing check for nocow and compression inode flags")
-Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
----
- fs/btrfs/ioctl.c | 60 ++++++++++++++++++++++++++++++++++++------------
- 1 file changed, 45 insertions(+), 15 deletions(-)
-
-diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index ac070c745b0eb..55762f77006e0 100644
---- a/fs/btrfs/ioctl.c
-+++ b/fs/btrfs/ioctl.c
-@@ -216,9 +216,9 @@ void btrfs_sync_inode_flags_to_i_flags(struct btrfs_inode *inode)
-
- /*
- * Check if @flags are a supported and valid set of FS_*_FL flags and that
-- * the old and new flags are not conflicting
-+ * the flags are not conflicting
- */
--static int check_fsflags(unsigned int old_flags, unsigned int flags)
-+static int check_fsflags(unsigned int flags)
- {
- if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
- FS_NOATIME_FL | FS_NODUMP_FL | \
-@@ -227,19 +227,10 @@ static int check_fsflags(unsigned int old_flags, unsigned int flags)
- FS_NOCOW_FL))
- return -EOPNOTSUPP;
-
-- /* COMPR and NOCOMP on new/old are valid */
-+ /* Only one of COMPR and NOCOMP is valid at a time */
- if ((flags & FS_NOCOMP_FL) && (flags & FS_COMPR_FL))
- return -EINVAL;
-
-- if ((flags & FS_COMPR_FL) && (flags & FS_NOCOW_FL))
-- return -EINVAL;
--
-- /* NOCOW and compression options are mutually exclusive */
-- if ((old_flags & FS_NOCOW_FL) && (flags & (FS_COMPR_FL | FS_NOCOMP_FL)))
-- return -EINVAL;
-- if ((flags & FS_NOCOW_FL) && (old_flags & (FS_COMPR_FL | FS_NOCOMP_FL)))
-- return -EINVAL;
--
- return 0;
- }
-
-@@ -288,6 +279,7 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
- unsigned int fsflags, old_fsflags;
- int ret;
- const char *comp = NULL;
-+ u32 old_inode_flags;
- u32 inode_flags;
- bool prop_set = false;
-
-@@ -299,7 +291,7 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
-
- fsflags = btrfs_mask_fsflags_for_type(&inode->vfs_inode, fa->flags);
- old_fsflags = btrfs_inode_flags_to_fsflags(inode);
-- ret = check_fsflags(old_fsflags, fsflags);
-+ ret = check_fsflags(fsflags);
- if (ret)
- return ret;
-
-@@ -355,6 +347,30 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
- } else {
- inode_flags |= BTRFS_INODE_NODATACOW;
- }
-+ /*
-+ * NODATACOW files will ignore COMPRESS, so forbid
-+ * COMPRESS | NODATACOW.
-+ *
-+ * We do this check here, after we've decided whether
-+ * to silently drop the NODATACOW bit for non-empty files.
-+ *
-+ * NODATACOW files will inherit flags from NODATACOW
-+ * directories, so COMPRESS is forbidden for them too.
-+ *
-+ * Old kernels allowed the forbidden combination of flags
-+ * to be set, and they may still be found on existing
-+ * filesystems. If the forbidden combination of flags
-+ * are already set, we will allow an application to set
-+ * or clear unrelated flags (like IMMUTABLE or NOATIME)
-+ * as long as the existing COMPRESS | NODATACOW flags
-+ * are not changed.
-+ */
-+ if ((inode_flags & BTRFS_INODE_NODATACOW) &&
-+ (fsflags & (FS_COMPR_FL | FS_NOCOMP_FL))) {
-+ if ((old_fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)) !=
-+ (fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)))
-+ return -EINVAL;
-+ }
- } else {
- /* We can only change NODATACOW for zero-sized regular file. */
- if (S_ISREG(inode->vfs_inode.i_mode) && (inode->vfs_inode.i_size == 0)) {
-@@ -434,18 +450,32 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
- if (IS_ERR(trans))
- return PTR_ERR(trans);
-
-+ /*
-+ * Commit the new flags to the inode before setting the compression
-+ * property: property validation rejects compression on nodatacow
-+ * inodes based on the inode's current flags, which would incorrectly
-+ * reject a single ioctl that both clears NOCOW and sets COMPR.
-+ * Restore the original flags if the property cannot be set.
-+ */
-+ old_inode_flags = inode->flags;
-+ inode->flags = inode_flags;
-+
- if (comp) {
- ret = btrfs_set_prop(trans, inode, "btrfs.compression",
- comp, strlen(comp), 0);
-- if (ret)
-+ if (ret) {
-+ inode->flags = old_inode_flags;
- goto out_end_trans;
-+ }
- prop_set = true;
- } else {
- ret = btrfs_set_prop(trans, inode, "btrfs.compression", NULL, 0, 0);
- prop_set = (ret == 0);
- /* If ret == -ENODATA ignore and proceed to update inode item. */
-- if (ret && ret != -ENODATA)
-+ if (ret && ret != -ENODATA) {
-+ inode->flags = old_inode_flags;
- goto out_end_trans;
-+ }
- }
-
- update_flags:
---
-2.47.3
-
+++ /dev/null
-From e862b18927ec88f831323b2ac4f050b837fbaf54 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 18 Oct 2026 15:44:15 -0400
-Subject: [PATCH 2/5] btrfs: do not leave COMPRESS on an inode that gets
- NODATACOW at creation
-To: linux-btrfs@vger.kernel.org
-
-btrfs_fileattr_set() refuses to combine FS_NOCOW_FL with FS_COMPR_FL, and
-property validation refuses compression on nodatacow inodes, because
-NODATACOW data is never compressed. Inode creation can still produce the
-combination: btrfs_inherit_iflags() copies COMPRESS from a parent directory
-with chattr +c, and btrfs_create_new_inode() then adds NODATACOW for a
-regular file when the filesystem is mounted with -o nodatacow. A parent
-directory that already carries both flags (set by a kernel before
-f37c563bab42 ("btrfs: add missing check for nocow and compression inode
-flags")) passes both on to every new inode as well.
-
-The result is an inode that lsattr shows as "cC", which FS_IOC_SETFLAGS
-would refuse to create, and on kernels before the previous commit could
-not have any of its flags changed at all.
-
-Drop COMPRESS whenever NODATACOW is set on a new inode, from either source.
-NOCOMPRESS is left alone: it is valid together with NODATACOW.
-
-Reproducer: mkdir d; chattr +c d; mount -o nodatacow; touch d/f;
-lsattr d/f shows "cC" without this patch and "C" with it
-(compress-props-test.sh, "inherit" phase, in the raid56-wh-harness).
-
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/inode.c | 7 ++++++-
- 1 file changed, 6 insertions(+), 1 deletion(-)
-
-diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b071ed59a583f..ea4a2fb26e4d1 100644
---- a/fs/btrfs/inode.c
-+++ b/fs/btrfs/inode.c
-@@ -6551,6 +6551,8 @@ static void btrfs_inherit_iflags(struct btrfs_inode *inode, struct btrfs_inode *
- inode->flags |= BTRFS_INODE_NODATACOW;
- if (S_ISREG(inode->vfs_inode.i_mode))
- inode->flags |= BTRFS_INODE_NODATASUM;
-+ /* NODATACOW data is never compressed, and the two conflict. */
-+ inode->flags &= ~BTRFS_INODE_COMPRESS;
- }
-
- btrfs_sync_inode_flags_to_i_flags(inode);
-@@ -6656,9 +6658,12 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
- if (S_ISREG(inode->i_mode)) {
- if (btrfs_test_opt(fs_info, NODATASUM))
- BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM;
-- if (btrfs_test_opt(fs_info, NODATACOW))
-+ if (btrfs_test_opt(fs_info, NODATACOW)) {
- BTRFS_I(inode)->flags |= BTRFS_INODE_NODATACOW |
- BTRFS_INODE_NODATASUM;
-+ /* Not COMPRESS inherited from the parent directory. */
-+ BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
-+ }
- btrfs_update_inode_mapping_flags(BTRFS_I(inode));
- }
-
---
-2.47.3
-
--- /dev/null
+From 09b5474f55d329cfae8d8ab89862153f559df67f Mon Sep 17 00:00:00 2001
+From: koraynilay <koray.fra@gmail.com>
+Date: Tue, 3 Nov 2026 20:47:29 +0100
+Subject: [PATCH 02/11] btrfs: export btrfs_match_compress_type(), move it to
+ compression.h
+To: linux-btrfs@vger.kernel.org
+
+Export btrfs_match_compress_type() from being a static and locally used
+function in super.c and move it to compression.c, exporting it in
+compression.h. This allows it to be used in the next patches as
+validation for compression algorithm names.
+
+Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.5
+Signed-off-by: koraynilay <koray.fra@gmail.com>
+Link: https://lore.kernel.org/r/20261103194734.598182-2-koray.fra@gmail.com
+---
+ fs/btrfs/compression.c | 17 +++++++++++++++++
+ fs/btrfs/compression.h | 1 +
+ fs/btrfs/super.c | 8 --------
+ 3 files changed, 18 insertions(+), 8 deletions(-)
+
+diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
+index b12b7f1b31fdf..9f0e42424e865 100644
+--- a/fs/btrfs/compression.c
++++ b/fs/btrfs/compression.c
+@@ -1646,3 +1646,20 @@ int btrfs_compress_str2level(unsigned int type, const char *str, int *level_ret)
+ *level_ret = btrfs_compress_set_level(type, level);
+ return 0;
+ }
++
++/**
++ * btrfs_match_compress_type - Check if the string matches the compression type
++ * @string: The string to check
++ * @type: The compression type string (name) to match against (e.g. "zstd")
++ * @may_have_level: If true, the string may have a level suffix (e.g., ":1")
++ *
++ * Return: %true if the string matches the type and, if %may_have_level is %true,
++ * has a level suffix, %false otherwise.
++ */
++bool btrfs_match_compress_type(const char *string, const char *type, bool may_have_level)
++{
++ const int len = strlen(type);
++
++ return (strncmp(string, type, len) == 0) &&
++ ((may_have_level && string[len] == ':') || string[len] == '\0');
++}
+diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
+index 1022dc53ec51e..e67ba47b4cdc5 100644
+--- a/fs/btrfs/compression.h
++++ b/fs/btrfs/compression.h
+@@ -97,6 +97,7 @@ void btrfs_submit_compressed_write(struct btrfs_ordered_extent *ordered,
+ void btrfs_submit_compressed_read(struct btrfs_bio *bbio);
+
+ int btrfs_compress_str2level(unsigned int type, const char *str, int *level_ret);
++bool btrfs_match_compress_type(const char *string, const char *type, bool may_have_level);
+
+ struct folio *btrfs_alloc_compr_folio(struct btrfs_fs_info *fs_info, gfp_t gfp);
+ void btrfs_free_compr_folio(struct folio *folio);
+diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
+index b424cc836bd4a..372d4e75bfb60 100644
+--- a/fs/btrfs/super.c
++++ b/fs/btrfs/super.c
+@@ -270,14 +270,6 @@ static const struct fs_parameter_spec btrfs_fs_parameters[] = {
+ {}
+ };
+
+-static bool btrfs_match_compress_type(const char *string, const char *type, bool may_have_level)
+-{
+- const int len = strlen(type);
+-
+- return (strncmp(string, type, len) == 0) &&
+- ((may_have_level && string[len] == ':') || string[len] == '\0');
+-}
+-
+ static int btrfs_parse_compress(struct btrfs_fs_context *ctx,
+ const struct fs_parameter *param, int opt)
+ {
+--
+2.47.3
+
+++ /dev/null
-From b87ce7ce09a2d2703dcd5aa193ae9f1e624578b5 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 17 Aug 2025 16:57:07 -0400
-Subject: [PATCH 3/5] btrfs: allow NODATACOW | NOCOMPRESS
-To: linux-btrfs@vger.kernel.org
-
-Commit f37c563bab42 ("btrfs: add missing check for nocow and compression
-inode flags") added conflict checks for certain inode flag combinations,
-and commit 0e852ab8974c ("btrfs: do not allow compression on nodatacow
-files") extended the same logic to xattrs.
-
-Both commits also forbade the combination of FS_NOCOW_FL (NODATACOW)
-and FS_NOCOMP_FL (NOCOMPRESS). This restriction is undocumented, has
-no technical basis, and provides no benefit. NODATACOW files cannot be
-compressed in any case, so the NOCOMPRESS bit is a no-op: behavior is
-the same whether the flag is present or not.
-
-Forcing an unnecessary conflict makes inode flags harder to use.
-Portable applications may inherit COMPRESS, NOCOMPRESS, or NODATACOW bits
-from parent directories and combine them with unrelated flags such as
-IMMUTABLE or NOATIME. Rejecting otherwise valid flag sets with EINVAL
-creates surprises for applications that do not know about btrfs-specific
-interactions and only touch the flags they care about.
-
-Fix by permitting the combination of NODATACOW and NOCOMPRESS, both via
-FS_IOC_SETFLAGS and by setting btrfs.compression to "no"/"none" through
-xattrs.
-
-Fixes: f37c563bab42 ("btrfs: add missing check for nocow and compression inode flags")
-Fixes: 0e852ab8974c ("btrfs: do not allow compression on nodatacow files")
-Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
----
- fs/btrfs/ioctl.c | 6 +++---
- fs/btrfs/props.c | 8 ++++----
- 2 files changed, 7 insertions(+), 7 deletions(-)
-
-diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index 55762f77006e0..0de6a06e3c3e8 100644
---- a/fs/btrfs/ioctl.c
-+++ b/fs/btrfs/ioctl.c
-@@ -366,9 +366,9 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
- * are not changed.
- */
- if ((inode_flags & BTRFS_INODE_NODATACOW) &&
-- (fsflags & (FS_COMPR_FL | FS_NOCOMP_FL))) {
-- if ((old_fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)) !=
-- (fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)))
-+ (fsflags & FS_COMPR_FL)) {
-+ if ((old_fsflags & (FS_NOCOW_FL | FS_COMPR_FL)) !=
-+ (fsflags & (FS_NOCOW_FL | FS_COMPR_FL)))
- return -EINVAL;
- }
- } else {
-diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
-index 7cc82366a1dfc..9e0e17c348cfd 100644
---- a/fs/btrfs/props.c
-+++ b/fs/btrfs/props.c
-@@ -295,14 +295,14 @@ int btrfs_load_inode_props(struct btrfs_inode *inode, struct btrfs_path *path)
- static int prop_compression_validate(const struct btrfs_inode *inode,
- const char *value, size_t len)
- {
-- if (!btrfs_inode_can_compress(inode))
-- return -EINVAL;
--
- if (!value)
- return 0;
-
-- if (btrfs_compress_is_valid_type(value, len))
-+ if (btrfs_compress_is_valid_type(value, len)) {
-+ if (!btrfs_inode_can_compress(inode))
-+ return -EINVAL;
- return 0;
-+ }
-
- if ((len == 2 && strncmp("no", value, 2) == 0) ||
- (len == 4 && strncmp("none", value, 4) == 0))
---
-2.47.3
-
--- /dev/null
+From 067b8b770e2ee07a755241860e663376a2316a05 Mon Sep 17 00:00:00 2001
+From: koraynilay <koray.fra@gmail.com>
+Date: Tue, 3 Nov 2026 20:47:30 +0100
+Subject: [PATCH 03/11] btrfs: also validate compression levels in
+ btrfs_compress_is_valid_type()
+To: linux-btrfs@vger.kernel.org
+
+Change btrfs_compress_is_valid_type() to use btrfs_match_compress_type()
+and btrfs_compress_str2level() instead of a simple strncmp(), which would
+validate even incorrect strings (e.g. "zstd:invalid" or "zstdinvalid").
+
+This also makes the function validate levels in the same way the
+compress= option gets parsed, allowing bigger or smaller values, but
+still clamping them to the min or max supported.
+
+Furthermore, remove the len parameter, since now it requires a
+NUL-terminated string because of btrfs_compress_str2level(); this change
+is fine because btrfs_compress_is_valid_type() is used only once in
+props.c by prop_compression_validate(), which now uses a stack-based
+buffer and memcpy() to convert the user-supplied xattr value to a
+NUL-terminated string.
+
+Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.5
+Signed-off-by: koraynilay <koray.fra@gmail.com>
+Link: https://lore.kernel.org/r/20261103194734.598182-3-koray.fra@gmail.com
+---
+ fs/btrfs/compression.c | 18 +++++++++++++++---
+ fs/btrfs/compression.h | 2 +-
+ fs/btrfs/props.c | 18 +++++++++++++++++-
+ 3 files changed, 33 insertions(+), 5 deletions(-)
+
+diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
+index 9f0e42424e865..b1f8323fffe7d 100644
+--- a/fs/btrfs/compression.c
++++ b/fs/btrfs/compression.c
+@@ -70,18 +70,30 @@ static struct compressed_bio *alloc_compressed_bio(struct btrfs_inode *inode,
+ return to_compressed_bio(bbio);
+ }
+
+-bool btrfs_compress_is_valid_type(const char *str, size_t len)
++/**
++ * btrfs_compress_is_valid_type - Check if a string is a valid compression type.
++ * @str: The compression string to check. Must be null-terminated.
++ *
++ * Return: %true if the string is a valid compression algorithm (optionally with
++ * a level suffix, e.g. "zstd" or "zstd:9"), %false otherwise.
++ */
++bool btrfs_compress_is_valid_type(const char *str)
+ {
++ size_t len = strlen(str);
+ int i;
+
+ for (i = 1; i < ARRAY_SIZE(btrfs_compress_types); i++) {
+ size_t comp_len = strlen(btrfs_compress_types[i]);
++ const char *comp_type = btrfs_compress_types[i];
++ int tmp_level;
+
+ if (len < comp_len)
+ continue;
+
+- if (!strncmp(btrfs_compress_types[i], str, comp_len))
+- return true;
++ if (btrfs_match_compress_type(str, comp_type, true)) {
++ if (btrfs_compress_str2level(i, str + comp_len, &tmp_level) == 0)
++ return true;
++ }
+ }
+ return false;
+ }
+diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
+index e67ba47b4cdc5..c63bed9f4152e 100644
+--- a/fs/btrfs/compression.h
++++ b/fs/btrfs/compression.h
+@@ -132,7 +132,7 @@ extern const struct btrfs_compress_levels btrfs_lzo_compress;
+ extern const struct btrfs_compress_levels btrfs_zstd_compress;
+
+ const char* btrfs_compress_type2str(enum btrfs_compression_type type);
+-bool btrfs_compress_is_valid_type(const char *str, size_t len);
++bool btrfs_compress_is_valid_type(const char *str);
+
+ int btrfs_compress_heuristic(struct btrfs_inode *inode, u64 start, u64 end);
+
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index 7cc82366a1dfc..d196b73f4ffa1 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -18,6 +18,15 @@
+ #include "super.h"
+ #include "dir-item.h"
+
++/*
++ * Max length of compression algorithm:level string.
++ *
++ * For now the longest possible string is "zstd:-15", which is
++ * 8 characters + 1 terminating null byte.
++ * Rounding it up to the closest power of 2 gives 16.
++ */
++#define BTRFS_COMPRESS_PROP_MAX_LEN 16
++
+ #define BTRFS_PROP_HANDLERS_HT_BITS 8
+ static DEFINE_HASHTABLE(prop_handlers_ht, BTRFS_PROP_HANDLERS_HT_BITS);
+
+@@ -295,13 +304,20 @@ int btrfs_load_inode_props(struct btrfs_inode *inode, struct btrfs_path *path)
+ static int prop_compression_validate(const struct btrfs_inode *inode,
+ const char *value, size_t len)
+ {
++ char value_str[BTRFS_COMPRESS_PROP_MAX_LEN];
++
+ if (!btrfs_inode_can_compress(inode))
+ return -EINVAL;
+
+ if (!value)
+ return 0;
+
+- if (btrfs_compress_is_valid_type(value, len))
++ if (len >= BTRFS_COMPRESS_PROP_MAX_LEN)
++ return -EINVAL;
++
++ memcpy(value_str, value, len);
++ value_str[len] = '\0';
++ if (btrfs_compress_is_valid_type(value_str))
+ return 0;
+
+ if ((len == 2 && strncmp("no", value, 2) == 0) ||
+--
+2.47.3
+
--- /dev/null
+From 028a26fdfebc49832d0f7401b20019df7f93962d Mon Sep 17 00:00:00 2001
+From: koraynilay <koray.fra@gmail.com>
+Date: Tue, 3 Nov 2026 20:47:31 +0100
+Subject: [PATCH 04/11] btrfs: add per-inode compression levels in xattrs
+To: linux-btrfs@vger.kernel.org
+
+Add support for specifying algo:level using
+btrfs property set /path/to/file compression "algo:level".
+
+Add a signed 8 bit prop_compress_level property to btrfs_inode, which
+can support from level -128 to 127, plenty for the currently supported
+algo:level(s).
+
+Change prop_compression_apply() to use the already present
+btrfs_match_compress_type() and btrfs_compress_str2level() to parse the
+xattr, using a stack-based buffer and memcpy() to convert the
+user-supplied xattr value to a NUL-terminated string to be used by
+btrfs_compress_str2level().
+
+Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.5
+Signed-off-by: koraynilay <koray.fra@gmail.com>
+Link: https://lore.kernel.org/r/20261103194734.598182-4-koray.fra@gmail.com
+---
+ fs/btrfs/btrfs_inode.h | 1 +
+ fs/btrfs/inode.c | 10 ++++++++++
+ fs/btrfs/props.c | 31 ++++++++++++++++++++++++++++---
+ 3 files changed, 39 insertions(+), 3 deletions(-)
+
+diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
+index 0782f917fcccb..58ee9bbd7b5bf 100644
+--- a/fs/btrfs/btrfs_inode.h
++++ b/fs/btrfs/btrfs_inode.h
+@@ -137,6 +137,7 @@ struct btrfs_inode {
+
+ /* Cached value of inode property 'compression'. */
+ u8 prop_compress;
++ s8 prop_compress_level;
+
+ /*
+ * Force compression on the file using the defrag ioctl, could be
+diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
+index 0bc668c9ec883..2078a3b004fe9 100644
+--- a/fs/btrfs/inode.c
++++ b/fs/btrfs/inode.c
+@@ -945,6 +945,11 @@ static void compress_file_range(struct btrfs_work *work)
+ compress_level = inode->defrag_compress_level;
+ } else if (inode->prop_compress) {
+ compress_type = inode->prop_compress;
++ if (inode->prop_compress_level)
++ compress_level = inode->prop_compress_level;
++ else if (compress_type != fs_info->compress_type)
++ compress_level = 0;
++ /* else use fs_info->compress_level */
+ }
+
+ /* Compression level is applied here. */
+@@ -2330,6 +2335,11 @@ static int run_delalloc_inline(struct btrfs_inode *inode, struct folio *locked_f
+ compress_level = inode->defrag_compress_level;
+ } else if (inode->prop_compress) {
+ compress_type = inode->prop_compress;
++ if (inode->prop_compress_level)
++ compress_level = inode->prop_compress_level;
++ else if (compress_type != fs_info->compress_type)
++ compress_level = 0;
++ /* else use fs_info->compress_level */
+ }
+ /*
+ * We need to pass blocksize and not i_size, otherwise we can't
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index d196b73f4ffa1..effc2daa2e3df 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -332,6 +332,10 @@ static int prop_compression_apply(struct btrfs_inode *inode, const char *value,
+ {
+ struct btrfs_fs_info *fs_info = inode->root->fs_info;
+ int type;
++ int level = 0;
++ int ret = 0;
++ char value_str[BTRFS_COMPRESS_PROP_MAX_LEN];
++ int level_pos = 0;
+
+ /* Reset to defaults */
+ if (len == 0) {
+@@ -351,21 +355,42 @@ static int prop_compression_apply(struct btrfs_inode *inode, const char *value,
+ return 0;
+ }
+
+- if (!strncmp("lzo", value, 3)) {
++ if (len >= BTRFS_COMPRESS_PROP_MAX_LEN)
++ return -EINVAL;
++
++ memcpy(value_str, value, len);
++ value_str[len] = '\0';
++
++ if (btrfs_match_compress_type(value_str, "lzo", true)) {
+ type = BTRFS_COMPRESS_LZO;
+ btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
+- } else if (!strncmp("zlib", value, 4)) {
++ } else if (btrfs_match_compress_type(value_str, "zlib", true)) {
+ type = BTRFS_COMPRESS_ZLIB;
+- } else if (!strncmp("zstd", value, 4)) {
++ level_pos = 4;
++ } else if (btrfs_match_compress_type(value_str, "zstd", true)) {
+ type = BTRFS_COMPRESS_ZSTD;
++ level_pos = 4;
+ btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
+ } else {
+ return -EINVAL;
+ }
+
++ /* Parse level if the algorithm supports it */
++ if (level_pos > 0) {
++ const char *level_str = value_str + level_pos;
++
++ /* and if user specified it */
++ if (level_str[0] == ':') {
++ ret = btrfs_compress_str2level(type, level_str, &level);
++ if (ret < 0)
++ return ret;
++ }
++ }
++
+ inode->flags &= ~BTRFS_INODE_NOCOMPRESS;
+ inode->flags |= BTRFS_INODE_COMPRESS;
+ inode->prop_compress = type;
++ inode->prop_compress_level = level;
+
+ return 0;
+ }
+--
+2.47.3
+
+++ /dev/null
-From 627b9f25057fbb9eb7abfb968f7528499df41cd1 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Thu, 6 Aug 2026 21:39:01 -0400
-Subject: [PATCH 4/5] btrfs: props: add per-inode compression level support
-To: linux-btrfs@vger.kernel.org
-
-Setting a per-file compression level is an often requested feature, and
-the btrfs.compression property has silently accepted level suffixes
-("zstd:9") since compression types were added to it: the property
-validator only matches the algorithm name prefix, the verbatim string is
-stored in the xattr and returned by getxattr, and everything after the
-algorithm name is ignored when the value is parsed into the in-memory
-compression type.
-
-All of the pieces needed to honor the level already exist: the level is
-a per-call argument down the whole compression path, per-inode levels
-are already implemented for the defrag ioctl (defrag_compress_level),
-and btrfs_compress_str2level() already parses and clamps ":level"
-suffixes for the mount options. Wire the property path up to them:
-
- * Cache the parsed level in a new btrfs_inode::prop_compress_level,
- with 0 meaning no level was specified, in which case the level from
- the mount options is used as before. The field is signed to allow
- negative (realtime) zstd levels.
-
- * Parse an optional ":level" suffix in prop_compression_apply().
- Values stored by old kernels were never validated, so an unparseable
- suffix falls back to the default level rather than making the inode's
- properties fail to load. Levels for lzo parse and clamp to nothing,
- matching commit 6db1df415d73 ("btrfs: accept and ignore compression
- level for lzo").
-
- * Use the level in compress_file_range() and the inline compression
- path in run_delalloc_inline(). The defrag ioctl retains precedence.
-
- * Regenerate the canonical "type:level" string with a new helper,
- btrfs_prop_compression_extract(), so that directory inheritance
- propagates the level to new inodes, and so that FS_IOC_SETFLAGS,
- which rewrites the property when setting FS_COMPR_FL, preserves the
- level instead of truncating the value to the bare algorithm name.
- The prop_handler extract hook itself is unchanged: it still returns
- a static string, and the inheritance loop regenerates the leveled
- value only for the compression property.
-
-There is no disk format change: the level lives in the already-existing
-xattr value string. Note that levels stored by old kernels (which were
-accepted but ignored) become effective after this change.
-
-Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Assisted-by: Claude:claude-fable-5
----
- fs/btrfs/btrfs_inode.h | 7 +++++
- fs/btrfs/inode.c | 4 +++
- fs/btrfs/ioctl.c | 18 ++++++-----
- fs/btrfs/props.c | 71 ++++++++++++++++++++++++++++++++++++++++++
- fs/btrfs/props.h | 3 ++
- 5 files changed, 96 insertions(+), 7 deletions(-)
-
-diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
-index f7aa0d1451851..a9ccdd0a1f693 100644
---- a/fs/btrfs/btrfs_inode.h
-+++ b/fs/btrfs/btrfs_inode.h
-@@ -138,6 +138,13 @@ struct btrfs_inode {
- /* Cached value of inode property 'compression'. */
- u8 prop_compress;
-
-+ /*
-+ * Cached compression level from the 'compression' property. 0 means
-+ * no level was specified, in which case the mount option level is
-+ * used.
-+ */
-+ s8 prop_compress_level;
-+
- /*
- * Force compression on the file using the defrag ioctl, could be
- * different from prop_compress and takes precedence if set.
-diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index ea4a2fb26e4d1..9cac6f5866a1f 100644
---- a/fs/btrfs/inode.c
-+++ b/fs/btrfs/inode.c
-@@ -945,6 +945,8 @@ static void compress_file_range(struct btrfs_work *work)
- compress_level = inode->defrag_compress_level;
- } else if (inode->prop_compress) {
- compress_type = inode->prop_compress;
-+ if (inode->prop_compress_level)
-+ compress_level = inode->prop_compress_level;
- }
-
- /* Compression level is applied here. */
-@@ -2330,6 +2332,8 @@ static int run_delalloc_inline(struct btrfs_inode *inode, struct folio *locked_f
- compress_level = inode->defrag_compress_level;
- } else if (inode->prop_compress) {
- compress_type = inode->prop_compress;
-+ if (inode->prop_compress_level)
-+ compress_level = inode->prop_compress_level;
- }
- /*
- * We need to pass blocksize and not i_size, otherwise we can't
-diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index 0de6a06e3c3e8..bb1c989c53dcb 100644
---- a/fs/btrfs/ioctl.c
-+++ b/fs/btrfs/ioctl.c
-@@ -280,6 +280,7 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
- int ret;
- const char *comp = NULL;
- u32 old_inode_flags;
-+ char comp_buf[16];
- u32 inode_flags;
- bool prop_set = false;
-
-@@ -431,13 +432,16 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap,
- * Inodes with the compress flag set but no property keep using
- * the mount default, so they behave as before.
- */
-- if (inode->prop_compress)
-- comp_type = inode->prop_compress;
-- else if (fs_info->compress_type)
-- comp_type = fs_info->compress_type;
-- else
-- comp_type = BTRFS_COMPRESS_ZLIB;
-- comp = btrfs_compress_type2str(comp_type);
-+ if (btrfs_prop_compression_extract(inode, comp_buf,
-+ sizeof(comp_buf)) > 0) {
-+ comp = comp_buf;
-+ } else {
-+ if (fs_info->compress_type)
-+ comp_type = fs_info->compress_type;
-+ else
-+ comp_type = BTRFS_COMPRESS_ZLIB;
-+ comp = btrfs_compress_type2str(comp_type);
-+ }
- } else {
- inode_flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
- }
-diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
-index 9e0e17c348cfd..efef14c80e39a 100644
---- a/fs/btrfs/props.c
-+++ b/fs/btrfs/props.c
-@@ -317,11 +317,15 @@ static int prop_compression_apply(struct btrfs_inode *inode, const char *value,
- struct btrfs_fs_info *fs_info = inode->root->fs_info;
- int type;
-
-+ size_t type_len;
-+ int level = 0;
-+
- /* Reset to defaults */
- if (len == 0) {
- inode->flags &= ~BTRFS_INODE_COMPRESS;
- inode->flags &= ~BTRFS_INODE_NOCOMPRESS;
- inode->prop_compress = BTRFS_COMPRESS_NONE;
-+ inode->prop_compress_level = 0;
- return 0;
- }
-
-@@ -331,29 +335,86 @@ static int prop_compression_apply(struct btrfs_inode *inode, const char *value,
- inode->flags |= BTRFS_INODE_NOCOMPRESS;
- inode->flags &= ~BTRFS_INODE_COMPRESS;
- inode->prop_compress = BTRFS_COMPRESS_NONE;
-+ inode->prop_compress_level = 0;
-
- return 0;
- }
-
- if (!strncmp("lzo", value, 3)) {
- type = BTRFS_COMPRESS_LZO;
-+ type_len = 3;
- btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
- } else if (!strncmp("zlib", value, 4)) {
- type = BTRFS_COMPRESS_ZLIB;
-+ type_len = 4;
- } else if (!strncmp("zstd", value, 4)) {
- type = BTRFS_COMPRESS_ZSTD;
-+ type_len = 4;
- btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
- } else {
- return -EINVAL;
- }
-
-+ /*
-+ * Parse an optional ":level" suffix. Old kernels accepted and
-+ * silently ignored arbitrary suffixes after the algorithm name, and
-+ * such values may still exist on disk, so fall back to the default
-+ * level instead of returning an error when the suffix cannot be
-+ * parsed, otherwise the inode's properties could not be loaded.
-+ */
-+ if (len > type_len && value[type_len] == ':') {
-+ char str[16];
-+ size_t suffix_len = len - type_len;
-+
-+ if (suffix_len < sizeof(str)) {
-+ memcpy(str, value + type_len, suffix_len);
-+ str[suffix_len] = 0;
-+ if (btrfs_compress_str2level(type, str, &level) < 0)
-+ level = 0;
-+ }
-+ }
-+
- inode->flags &= ~BTRFS_INODE_NOCOMPRESS;
- inode->flags |= BTRFS_INODE_COMPRESS;
- inode->prop_compress = type;
-+ inode->prop_compress_level = level;
-
- return 0;
- }
-
-+/*
-+ * Regenerate the canonical "type" or "type:level" value of the
-+ * compression property from the inode's cached fields. Used where the
-+ * property is rewritten rather than parsed: FS_IOC_SETFLAGS preserving
-+ * an existing property, and directory inheritance.
-+ */
-+ssize_t btrfs_prop_compression_extract(const struct btrfs_inode *inode,
-+ char *buf, size_t size)
-+{
-+ int len;
-+
-+ switch (inode->prop_compress) {
-+ case BTRFS_COMPRESS_ZLIB:
-+ case BTRFS_COMPRESS_LZO:
-+ case BTRFS_COMPRESS_ZSTD:
-+ break;
-+ default:
-+ return -ENODATA;
-+ }
-+
-+ if (inode->prop_compress_level)
-+ len = snprintf(buf, size, "%s:%d",
-+ btrfs_compress_type2str(inode->prop_compress),
-+ inode->prop_compress_level);
-+ else
-+ len = snprintf(buf, size, "%s",
-+ btrfs_compress_type2str(inode->prop_compress));
-+ if (len >= size)
-+ return -EOVERFLOW;
-+
-+ return len;
-+}
-+
- static bool prop_compression_ignore(const struct btrfs_inode *inode)
- {
- /*
-@@ -411,6 +472,7 @@ int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans,
- for (i = 0; i < ARRAY_SIZE(prop_handlers); i++) {
- const struct prop_handler *h = &prop_handlers[i];
- const char *value;
-+ char buf[16];
- u64 num_bytes = 0;
-
- if (!h->inheritable)
-@@ -423,6 +485,15 @@ int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans,
- if (!value)
- continue;
-
-+ /*
-+ * The extract hooks return static strings, which cannot
-+ * carry the compression property's optional ":level"
-+ * suffix; regenerate the full value for inheritance.
-+ */
-+ if (h->extract == prop_compression_extract &&
-+ btrfs_prop_compression_extract(parent, buf, sizeof(buf)) > 0)
-+ value = buf;
-+
- /*
- * This is not strictly necessary as the property should be
- * valid, but in case it isn't, don't propagate it further.
-diff --git a/fs/btrfs/props.h b/fs/btrfs/props.h
-index 15d9a025c923d..86a004be4e469 100644
---- a/fs/btrfs/props.h
-+++ b/fs/btrfs/props.h
-@@ -24,6 +24,9 @@ bool btrfs_ignore_prop(const struct btrfs_inode *inode, const char *name);
-
- int btrfs_load_inode_props(struct btrfs_inode *inode, struct btrfs_path *path);
-
-+ssize_t btrfs_prop_compression_extract(const struct btrfs_inode *inode,
-+ char *buf, size_t size);
-+
- int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans,
- struct btrfs_inode *inode,
- const struct btrfs_inode *dir);
---
-2.47.3
-
+++ /dev/null
-From 420b87ed47953436d52528ef49be054222d039b7 Mon Sep 17 00:00:00 2001
-From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sun, 19 Jul 2026 14:33:53 -0400
-Subject: [PATCH 5/5] btrfs: props: validate compression property values
- strictly
-To: linux-btrfs@vger.kernel.org
-
-The btrfs.compression property validator matches only the algorithm
-name prefix, so values like "zstdgarbage" or "zstd:banana" are accepted
-and stored verbatim. Now that ":level" suffixes are meaningful,
-validate new values strictly: accept exactly an algorithm name,
-optionally followed by a ":level" suffix that btrfs_compress_str2level()
-can parse, mirroring the mount option validation from commit
-b98b20830057 ("btrfs: reject invalid compression level"). Out of range
-levels are clamped, also matching the mount options. "no" and "none"
-are accepted as before. Embedded NUL bytes are rejected before parsing
-the length-delimited xattr value: otherwise the temporary
-NUL-terminated suffix buffer would let a value such as "zstd:3" followed
-by a NUL and junk pass validation and be stored verbatim.
-
-Values stored by old kernels are not affected: property loading goes
-through the apply hook, which remains permissive, so existing inodes
-with sloppy stored values keep working; only new setxattr calls see the
-stricter checks.
-
-This is a user-visible behavior change: applications that set malformed
-property values, which were previously accepted and ignored, will now
-receive EINVAL. It is split into its own commit so that it can be
-accepted or rejected independently of per-inode compression level
-support.
-
-Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Codex:gpt-5
----
- fs/btrfs/props.c | 42 +++++++++++++++++++++++++++++++++++++-----
- 1 file changed, 37 insertions(+), 5 deletions(-)
-
-diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
-index efef14c80e39a..59f1835d57dc3 100644
---- a/fs/btrfs/props.c
-+++ b/fs/btrfs/props.c
-@@ -295,19 +295,51 @@ int btrfs_load_inode_props(struct btrfs_inode *inode, struct btrfs_path *path)
- static int prop_compression_validate(const struct btrfs_inode *inode,
- const char *value, size_t len)
- {
-+ size_t type_len;
-+ int type;
-+
- if (!value)
- return 0;
-+ if (memchr(value, '\0', len))
-+ return -EINVAL;
-
-- if (btrfs_compress_is_valid_type(value, len)) {
-- if (!btrfs_inode_can_compress(inode))
-- return -EINVAL;
-+ if ((len == 2 && strncmp("no", value, 2) == 0) ||
-+ (len == 4 && strncmp("none", value, 4) == 0))
- return 0;
-+
-+ if (len >= 3 && strncmp("lzo", value, 3) == 0) {
-+ type = BTRFS_COMPRESS_LZO;
-+ type_len = 3;
-+ } else if (len >= 4 && strncmp("zlib", value, 4) == 0) {
-+ type = BTRFS_COMPRESS_ZLIB;
-+ type_len = 4;
-+ } else if (len >= 4 && strncmp("zstd", value, 4) == 0) {
-+ type = BTRFS_COMPRESS_ZSTD;
-+ type_len = 4;
-+ } else {
-+ return -EINVAL;
- }
-
-- if ((len == 2 && strncmp("no", value, 2) == 0) ||
-- (len == 4 && strncmp("none", value, 4) == 0))
-+ if (!btrfs_inode_can_compress(inode))
-+ return -EINVAL;
-+
-+ if (len == type_len)
- return 0;
-
-+ /* Only a valid ":level" suffix may follow the algorithm name. */
-+ if (value[type_len] == ':') {
-+ char str[16];
-+ size_t suffix_len = len - type_len;
-+ int level;
-+
-+ if (suffix_len >= sizeof(str))
-+ return -EINVAL;
-+ memcpy(str, value + type_len, suffix_len);
-+ str[suffix_len] = 0;
-+ if (btrfs_compress_str2level(type, str, &level) == 0)
-+ return 0;
-+ }
-+
- return -EINVAL;
- }
-
---
-2.47.3
-
--- /dev/null
+From f1ed856e732f62ca0a0dc413068937e8d856ff8c Mon Sep 17 00:00:00 2001
+From: koraynilay <koray.fra@gmail.com>
+Date: Tue, 3 Nov 2026 20:47:32 +0100
+Subject: [PATCH 05/11] btrfs: support inheritance for per-inode compression
+ levels
+To: linux-btrfs@vger.kernel.org
+
+Change prop_handler's extract() signature to take an output buffer and
+its length. This allows for the algo:level string to be generated
+dynamically, but now the caller is in charge of managing that buffer
+memory. Before this patch prop_compression_extract() would return only
+the address of statically compiled string without being able to add the
+level, now it concatenates the level to that statically compiled string.
+
+This signature change is fine because the only currently supported prop
+is compression, so there is only 1 extract() function.
+
+Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.5
+Signed-off-by: koraynilay <koray.fra@gmail.com>
+Link: https://lore.kernel.org/r/20261103194734.598182-5-koray.fra@gmail.com
+---
+ fs/btrfs/props.c | 14 +++++++++++---
+ 1 file changed, 11 insertions(+), 3 deletions(-)
+
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index effc2daa2e3df..9427be2f28e02 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -36,7 +36,7 @@ struct prop_handler {
+ int (*validate)(const struct btrfs_inode *inode, const char *value,
+ size_t len);
+ int (*apply)(struct btrfs_inode *inode, const char *value, size_t len);
+- const char *(*extract)(const struct btrfs_inode *inode);
++ const char *(*extract)(const struct btrfs_inode *inode, char *buf, size_t len);
+ bool (*ignore)(const struct btrfs_inode *inode);
+ int inheritable;
+ };
+@@ -411,12 +411,19 @@ static bool prop_compression_ignore(const struct btrfs_inode *inode)
+ return false;
+ }
+
+-static const char *prop_compression_extract(const struct btrfs_inode *inode)
++static const char *prop_compression_extract(const struct btrfs_inode *inode,
++ char *buf, size_t len)
+ {
+ switch (inode->prop_compress) {
+ case BTRFS_COMPRESS_ZLIB:
+ case BTRFS_COMPRESS_LZO:
+ case BTRFS_COMPRESS_ZSTD:
++ if (inode->prop_compress_level) {
++ snprintf(buf, len, "%s:%d",
++ btrfs_compress_type2str(inode->prop_compress),
++ inode->prop_compress_level);
++ return buf;
++ }
+ return btrfs_compress_type2str(inode->prop_compress);
+ default:
+ break;
+@@ -453,6 +460,7 @@ int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans,
+ const struct prop_handler *h = &prop_handlers[i];
+ const char *value;
+ u64 num_bytes = 0;
++ char buf[BTRFS_COMPRESS_PROP_MAX_LEN];
+
+ if (!h->inheritable)
+ continue;
+@@ -460,7 +468,7 @@ int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans,
+ if (h->ignore(inode))
+ continue;
+
+- value = h->extract(parent);
++ value = h->extract(parent, buf, sizeof(buf));
+ if (!value)
+ continue;
+
+--
+2.47.3
+
--- /dev/null
+From 65af9f44ec1ecd3ad14f509a27caf469ce11bb1f Mon Sep 17 00:00:00 2001
+From: koraynilay <koray.fra@gmail.com>
+Date: Tue, 3 Nov 2026 20:47:33 +0100
+Subject: [PATCH 06/11] btrfs: add btrfs_compress_typelevel2str() helper
+To: linux-btrfs@vger.kernel.org
+
+Add the type:level equivalent of btrfs_compress_type2str() and use it
+in prop_compression_extract() .
+
+Signed-off-by: koraynilay <koray.fra@gmail.com>
+Link: https://lore.kernel.org/r/20261103194734.598182-6-koray.fra@gmail.com
+---
+ fs/btrfs/compression.c | 20 ++++++++++++++++++++
+ fs/btrfs/compression.h | 2 ++
+ fs/btrfs/props.c | 19 +++----------------
+ 3 files changed, 25 insertions(+), 16 deletions(-)
+
+diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
+index b1f8323fffe7d..068c24576b71e 100644
+--- a/fs/btrfs/compression.c
++++ b/fs/btrfs/compression.c
+@@ -53,6 +53,26 @@ const char* btrfs_compress_type2str(enum btrfs_compression_type type)
+ return NULL;
+ }
+
++const char* btrfs_compress_typelevel2str(enum btrfs_compression_type type,
++ int level, char *buf, size_t len)
++{
++ switch (type) {
++ case BTRFS_COMPRESS_ZLIB:
++ case BTRFS_COMPRESS_LZO:
++ case BTRFS_COMPRESS_ZSTD:
++ if (level) {
++ snprintf(buf, len, "%s:%d",
++ btrfs_compress_type2str(type), level);
++ return buf;
++ }
++ return btrfs_compress_type2str(type);
++ default:
++ break;
++ }
++
++ return NULL;
++}
++
+ static inline struct compressed_bio *to_compressed_bio(struct btrfs_bio *bbio)
+ {
+ return container_of(bbio, struct compressed_bio, bbio);
+diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
+index c63bed9f4152e..b9cc1bdd3ccbf 100644
+--- a/fs/btrfs/compression.h
++++ b/fs/btrfs/compression.h
+@@ -132,6 +132,8 @@ extern const struct btrfs_compress_levels btrfs_lzo_compress;
+ extern const struct btrfs_compress_levels btrfs_zstd_compress;
+
+ const char* btrfs_compress_type2str(enum btrfs_compression_type type);
++const char* btrfs_compress_typelevel2str(enum btrfs_compression_type type,
++ int level, char *buf, size_t len);
+ bool btrfs_compress_is_valid_type(const char *str);
+
+ int btrfs_compress_heuristic(struct btrfs_inode *inode, u64 start, u64 end);
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index 9427be2f28e02..3edda1f11a741 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -414,22 +414,9 @@ static bool prop_compression_ignore(const struct btrfs_inode *inode)
+ static const char *prop_compression_extract(const struct btrfs_inode *inode,
+ char *buf, size_t len)
+ {
+- switch (inode->prop_compress) {
+- case BTRFS_COMPRESS_ZLIB:
+- case BTRFS_COMPRESS_LZO:
+- case BTRFS_COMPRESS_ZSTD:
+- if (inode->prop_compress_level) {
+- snprintf(buf, len, "%s:%d",
+- btrfs_compress_type2str(inode->prop_compress),
+- inode->prop_compress_level);
+- return buf;
+- }
+- return btrfs_compress_type2str(inode->prop_compress);
+- default:
+- break;
+- }
+-
+- return NULL;
++ return btrfs_compress_typelevel2str(inode->prop_compress,
++ inode->prop_compress_level,
++ buf, len);
+ }
+
+ static struct prop_handler prop_handlers[] = {
+--
+2.47.3
+
--- /dev/null
+From 2e91da3ba65a1d8973f07a857c6641b8d32ec121 Mon Sep 17 00:00:00 2001
+From: koraynilay <koray.fra@gmail.com>
+Date: Tue, 3 Nov 2026 20:47:34 +0100
+Subject: [PATCH 07/11] btrfs: preserve btrfs.compression when setting inode
+ flags
+To: linux-btrfs@vger.kernel.org
+
+Commit e8a0095c7df170 ("btrfs: preserve the compression property when
+other inode flags change") fixed an issue where any call to
+FS_IOC_SETFLAGS (e.g. via chattr) would overwrite the btrfs.compression
+property with the mount default compression type, even when no flag bits
+change and even for flags unrelated to compression.
+
+Update the fixed code to also preserve the newly introduced level
+specification by using the new btrfs_compress_typelevel2str() helper.
+
+Also move BTRFS_COMPRESS_PROP_MAX_LEN from props.c to props.h so it can
+be used by ioctl.c, since it now requires a temporary buffer to write the
+property string to.
+
+[ Commit message and code adapted from Zygo's patch for this same issue ]
+
+Reported-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Suggested-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.7
+Signed-off-by: koraynilay <koray.fra@gmail.com>
+Link: https://lore.kernel.org/r/20261103194734.598182-7-koray.fra@gmail.com
+---
+ fs/btrfs/ioctl.c | 27 ++++++++++++++-------------
+ fs/btrfs/props.c | 9 ---------
+ fs/btrfs/props.h | 9 +++++++++
+ 3 files changed, 23 insertions(+), 22 deletions(-)
+
+diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
+index 215e3220df7fa..ecf0f334514db 100644
+--- a/fs/btrfs/ioctl.c
++++ b/fs/btrfs/ioctl.c
+@@ -288,6 +288,7 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
+ unsigned int fsflags, old_fsflags;
+ int ret;
+ const char *comp = NULL;
++ char comp_buf[BTRFS_COMPRESS_PROP_MAX_LEN];
+ u32 inode_flags;
+ bool prop_set = false;
+
+@@ -397,7 +398,6 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
+ inode_flags &= ~BTRFS_INODE_COMPRESS;
+ inode_flags |= BTRFS_INODE_NOCOMPRESS;
+ } else if (fsflags & FS_COMPR_FL) {
+- enum btrfs_compression_type comp_type;
+
+ if (IS_SWAPFILE(&inode->vfs_inode))
+ return -ETXTBSY;
+@@ -406,22 +406,23 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
+ inode_flags &= ~BTRFS_INODE_NOCOMPRESS;
+
+ /*
+- * Keep the algorithm recorded in the compression property,
+- * otherwise changing an unrelated attribute would reset it to
+- * the mount default, since FS_IOC_SETFLAGS callers write back
+- * the whole flag set they got from FS_IOC_GETFLAGS and that
+- * includes FS_COMPR_FL for any inode carrying the property.
++ * If compression is already enabled, we must reconstruct the
++ * full "algo:level" property string and write it back.
++ * Otherwise changing an unrelated attribute would reset it to
++ * the mount default and drop the level, since FS_IOC_SETFLAGS
++ * callers write back the whole flag set they got from
++ * FS_IOC_GETFLAGS, and that includes FS_COMPR_FL.
+ *
+ * Inodes with the compress flag set but no property keep using
+ * the mount default, so they behave as before.
+ */
+- if (inode->prop_compress)
+- comp_type = inode->prop_compress;
+- else if (fs_info->compress_type)
+- comp_type = fs_info->compress_type;
+- else
+- comp_type = BTRFS_COMPRESS_ZLIB;
+- comp = btrfs_compress_type2str(comp_type);
++ comp = btrfs_compress_typelevel2str(inode->prop_compress,
++ inode->prop_compress_level,
++ comp_buf, sizeof(comp_buf));
++ if (!comp || comp[0] == 0)
++ comp = btrfs_compress_type2str(fs_info->compress_type);
++ if (!comp || comp[0] == 0)
++ comp = btrfs_compress_type2str(BTRFS_COMPRESS_ZLIB);
+ } else {
+ inode_flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
+ }
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index 3edda1f11a741..05e594ce613b0 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -18,15 +18,6 @@
+ #include "super.h"
+ #include "dir-item.h"
+
+-/*
+- * Max length of compression algorithm:level string.
+- *
+- * For now the longest possible string is "zstd:-15", which is
+- * 8 characters + 1 terminating null byte.
+- * Rounding it up to the closest power of 2 gives 16.
+- */
+-#define BTRFS_COMPRESS_PROP_MAX_LEN 16
+-
+ #define BTRFS_PROP_HANDLERS_HT_BITS 8
+ static DEFINE_HASHTABLE(prop_handlers_ht, BTRFS_PROP_HANDLERS_HT_BITS);
+
+diff --git a/fs/btrfs/props.h b/fs/btrfs/props.h
+index 15d9a025c923d..93b55a85a728a 100644
+--- a/fs/btrfs/props.h
++++ b/fs/btrfs/props.h
+@@ -9,6 +9,15 @@
+ #include <linux/types.h>
+ #include <linux/compiler_types.h>
+
++/*
++ * Max length of compression algorithm:level string.
++ *
++ * For now the longest possible string is "zstd:-15", which is
++ * 8 characters + 1 terminating null byte.
++ * Rounding it up to the closest power of 2 gives 16.
++ */
++#define BTRFS_COMPRESS_PROP_MAX_LEN 16
++
+ struct btrfs_inode;
+ struct btrfs_path;
+ struct btrfs_trans_handle;
+--
+2.47.3
+
--- /dev/null
+From e535624aac207911db5b934f43979a556f9687ea Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Sat, 16 Aug 2025 22:20:01 -0400
+Subject: [PATCH 08/11] btrfs: fix nodatacow vs compression inode flag conflict
+ check
+To: linux-btrfs@vger.kernel.org
+
+Applications expect inode flags to be orthogonal: changes can be combined
+or applied separately in any order, as long as each intermediate state is
+valid and unchanged flags are left untouched.
+
+Commit f37c563bab42 ("btrfs: add missing check for nocow and compression
+inode flags") intended to forbid combining FS_NOCOW_FL with either
+FS_NOCOMP_FL or FS_COMPR_FL. The implementation contained a bug and
+introduced multiple regressions.
+
+Bug: FS_NOCOW_FL (+C) and FS_NOCOMP_FL (+m) can still be set together in
+a single FS_IOC_SETFLAGS call, even though the commit message states this
+combination should be rejected.
+
+Regression 1: Switching from +C+m back to -C-m only works if both flag
+changes are combined into one ioctl; separate -C and -m calls are
+rejected.
+
+Regression 2: Switching between +C-c and -C+c only works if the changes
+are split across multiple ioctls; a combined -C+c call is rejected.
+
+Regression 3: Inodes created on kernels before commit f37c563bab42
+("btrfs: add missing check for nocow and compression inode flags") with
+both COMPR and NOCOW set cannot have any other fsattrs changed on newer
+kernels. Even unrelated operations (such as adding +i, or clearing just
+one of the compression bits) fail with EINVAL, because the conflict
+check rejects the entire ioctl whenever conflicting bits are present,
+even if those bits are not being modified. This makes it impossible to
+manage older files without first undoing their existing flags.
+
+Fix by:
+ * Rewriting the conflict checks so FS_NOCOW_FL cannot be combined with
+ FS_NOCOMP_FL or FS_COMPR_FL in any ioctl (fixes the original bug and
+ regressions 1-2).
+ * Allowing existing conflicting flags to remain if they are not modified
+ by the ioctl (fixes regression 3).
+ * Moving the check later in the flag-validation sequence so that it
+ occurs after handling the long-standing rule that FS_NOCOW_FL changes
+ are silently ignored on non-empty files. This preserves the pre-existing
+ behavior while still applying the corrected conflict logic.
+
+Also commit the new inode flags to the inode before setting the
+compression property, restoring them if the property cannot be set:
+property validation rejects compression on nodatacow inodes based on
+the inode's current flags, which would otherwise reject a single ioctl
+that both clears NOCOW and sets COMPR (regression 2) even with the
+conflict check corrected.
+
+Fixes: f37c563bab42 ("btrfs: add missing check for nocow and compression inode flags")
+Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+---
+ fs/btrfs/ioctl.c | 60 ++++++++++++++++++++++++++++++++++++------------
+ 1 file changed, 45 insertions(+), 15 deletions(-)
+
+diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
+index ecf0f334514db..5b597ec81db9d 100644
+--- a/fs/btrfs/ioctl.c
++++ b/fs/btrfs/ioctl.c
+@@ -216,9 +216,9 @@ void btrfs_sync_inode_flags_to_i_flags(struct btrfs_inode *inode)
+
+ /*
+ * Check if @flags are a supported and valid set of FS_*_FL flags and that
+- * the old and new flags are not conflicting
++ * the flags are not conflicting
+ */
+-static int check_fsflags(unsigned int old_flags, unsigned int flags)
++static int check_fsflags(unsigned int flags)
+ {
+ if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
+ FS_NOATIME_FL | FS_NODUMP_FL | \
+@@ -227,19 +227,10 @@ static int check_fsflags(unsigned int old_flags, unsigned int flags)
+ FS_NOCOW_FL))
+ return -EOPNOTSUPP;
+
+- /* COMPR and NOCOMP on new/old are valid */
++ /* Only one of COMPR and NOCOMP is valid at a time */
+ if ((flags & FS_NOCOMP_FL) && (flags & FS_COMPR_FL))
+ return -EINVAL;
+
+- if ((flags & FS_COMPR_FL) && (flags & FS_NOCOW_FL))
+- return -EINVAL;
+-
+- /* NOCOW and compression options are mutually exclusive */
+- if ((old_flags & FS_NOCOW_FL) && (flags & (FS_COMPR_FL | FS_NOCOMP_FL)))
+- return -EINVAL;
+- if ((flags & FS_NOCOW_FL) && (old_flags & (FS_COMPR_FL | FS_NOCOMP_FL)))
+- return -EINVAL;
+-
+ return 0;
+ }
+
+@@ -289,6 +280,7 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
+ int ret;
+ const char *comp = NULL;
+ char comp_buf[BTRFS_COMPRESS_PROP_MAX_LEN];
++ u32 old_inode_flags;
+ u32 inode_flags;
+ bool prop_set = false;
+
+@@ -300,7 +292,7 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
+
+ fsflags = btrfs_mask_fsflags_for_type(&inode->vfs_inode, fa->flags);
+ old_fsflags = btrfs_inode_flags_to_fsflags(inode);
+- ret = check_fsflags(old_fsflags, fsflags);
++ ret = check_fsflags(fsflags);
+ if (ret)
+ return ret;
+
+@@ -356,6 +348,30 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
+ } else {
+ inode_flags |= BTRFS_INODE_NODATACOW;
+ }
++ /*
++ * NODATACOW files will ignore COMPRESS, so forbid
++ * COMPRESS | NODATACOW.
++ *
++ * We do this check here, after we've decided whether
++ * to silently drop the NODATACOW bit for non-empty files.
++ *
++ * NODATACOW files will inherit flags from NODATACOW
++ * directories, so COMPRESS is forbidden for them too.
++ *
++ * Old kernels allowed the forbidden combination of flags
++ * to be set, and they may still be found on existing
++ * filesystems. If the forbidden combination of flags
++ * are already set, we will allow an application to set
++ * or clear unrelated flags (like IMMUTABLE or NOATIME)
++ * as long as the existing COMPRESS | NODATACOW flags
++ * are not changed.
++ */
++ if ((inode_flags & BTRFS_INODE_NODATACOW) &&
++ (fsflags & (FS_COMPR_FL | FS_NOCOMP_FL))) {
++ if ((old_fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)) !=
++ (fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)))
++ return -EINVAL;
++ }
+ } else {
+ /* We can only change NODATACOW for zero-sized regular file. */
+ if (S_ISREG(inode->vfs_inode.i_mode) && (inode->vfs_inode.i_size == 0)) {
+@@ -435,18 +451,32 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
+ if (IS_ERR(trans))
+ return PTR_ERR(trans);
+
++ /*
++ * Commit the new flags to the inode before setting the compression
++ * property: property validation rejects compression on nodatacow
++ * inodes based on the inode's current flags, which would incorrectly
++ * reject a single ioctl that both clears NOCOW and sets COMPR.
++ * Restore the original flags if the property cannot be set.
++ */
++ old_inode_flags = inode->flags;
++ inode->flags = inode_flags;
++
+ if (comp) {
+ ret = btrfs_set_prop(trans, inode, "btrfs.compression",
+ comp, strlen(comp), 0);
+- if (ret)
++ if (ret) {
++ inode->flags = old_inode_flags;
+ goto out_end_trans;
++ }
+ prop_set = true;
+ } else {
+ ret = btrfs_set_prop(trans, inode, "btrfs.compression", NULL, 0, 0);
+ prop_set = (ret == 0);
+ /* If ret == -ENODATA ignore and proceed to update inode item. */
+- if (ret && ret != -ENODATA)
++ if (ret && ret != -ENODATA) {
++ inode->flags = old_inode_flags;
+ goto out_end_trans;
++ }
+ }
+
+ update_flags:
+--
+2.47.3
+
--- /dev/null
+From f2dd82de6a73ea3041f029b85aa2c1d2a2a4748e Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Sun, 17 Aug 2025 16:57:07 -0400
+Subject: [PATCH 09/11] btrfs: allow NODATACOW | NOCOMPRESS
+To: linux-btrfs@vger.kernel.org
+
+Commit f37c563bab42 ("btrfs: add missing check for nocow and compression
+inode flags") added conflict checks for certain inode flag combinations,
+and commit 0e852ab8974c ("btrfs: do not allow compression on nodatacow
+files") extended the same logic to xattrs.
+
+Both commits also forbade the combination of FS_NOCOW_FL (NODATACOW)
+and FS_NOCOMP_FL (NOCOMPRESS). This restriction is undocumented, has
+no technical basis, and provides no benefit. NODATACOW files cannot be
+compressed in any case, so the NOCOMPRESS bit is a no-op: behavior is
+the same whether the flag is present or not.
+
+Forcing an unnecessary conflict makes inode flags harder to use.
+Portable applications may inherit COMPRESS, NOCOMPRESS, or NODATACOW bits
+from parent directories and combine them with unrelated flags such as
+IMMUTABLE or NOATIME. Rejecting otherwise valid flag sets with EINVAL
+creates surprises for applications that do not know about btrfs-specific
+interactions and only touch the flags they care about.
+
+Fix by permitting the combination of NODATACOW and NOCOMPRESS, both via
+FS_IOC_SETFLAGS and by setting btrfs.compression to "no"/"none" through
+xattrs.
+
+Fixes: f37c563bab42 ("btrfs: add missing check for nocow and compression inode flags")
+Fixes: 0e852ab8974c ("btrfs: do not allow compression on nodatacow files")
+Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+---
+ fs/btrfs/ioctl.c | 6 +++---
+ fs/btrfs/props.c | 8 ++++----
+ 2 files changed, 7 insertions(+), 7 deletions(-)
+
+diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
+index 5b597ec81db9d..5d35b2072886f 100644
+--- a/fs/btrfs/ioctl.c
++++ b/fs/btrfs/ioctl.c
+@@ -367,9 +367,9 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap,
+ * are not changed.
+ */
+ if ((inode_flags & BTRFS_INODE_NODATACOW) &&
+- (fsflags & (FS_COMPR_FL | FS_NOCOMP_FL))) {
+- if ((old_fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)) !=
+- (fsflags & (FS_NOCOW_FL | FS_COMPR_FL | FS_NOCOMP_FL)))
++ (fsflags & FS_COMPR_FL)) {
++ if ((old_fsflags & (FS_NOCOW_FL | FS_COMPR_FL)) !=
++ (fsflags & (FS_NOCOW_FL | FS_COMPR_FL)))
+ return -EINVAL;
+ }
+ } else {
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index 05e594ce613b0..adc4dc540840c 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -297,9 +297,6 @@ static int prop_compression_validate(const struct btrfs_inode *inode,
+ {
+ char value_str[BTRFS_COMPRESS_PROP_MAX_LEN];
+
+- if (!btrfs_inode_can_compress(inode))
+- return -EINVAL;
+-
+ if (!value)
+ return 0;
+
+@@ -308,8 +305,11 @@ static int prop_compression_validate(const struct btrfs_inode *inode,
+
+ memcpy(value_str, value, len);
+ value_str[len] = '\0';
+- if (btrfs_compress_is_valid_type(value_str))
++ if (btrfs_compress_is_valid_type(value_str)) {
++ if (!btrfs_inode_can_compress(inode))
++ return -EINVAL;
+ return 0;
++ }
+
+ if ((len == 2 && strncmp("no", value, 2) == 0) ||
+ (len == 4 && strncmp("none", value, 4) == 0))
+--
+2.47.3
+
--- /dev/null
+From a41f99c734a9d5e3a5344cb2d0371b3cc16ff586 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 3 Nov 2026 18:41:30 -0500
+Subject: [PATCH 10/11] btrfs: props: reject NUL bytes in btrfs.compression
+ values
+To: linux-btrfs@vger.kernel.org
+
+The btrfs.compression xattr value is length-delimited, and
+prop_compression_validate() copies it into a NUL-terminated buffer before
+btrfs_compress_is_valid_type() parses it. An embedded NUL byte ends the
+string early in the copy, so a value such as "zstd:3" followed by a NUL
+and arbitrary junk passes validation and is stored verbatim, junk and
+all, where getxattr returns it.
+
+No algorithm name or level contains a NUL byte, so reject such values
+before the copy. "no" and "none" were already compared with an exact
+length and are not affected.
+
+---
+ fs/btrfs/props.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index adc4dc540840c..0fabd64cffd2b 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -303,6 +303,14 @@ static int prop_compression_validate(const struct btrfs_inode *inode,
+ if (len >= BTRFS_COMPRESS_PROP_MAX_LEN)
+ return -EINVAL;
+
++ /*
++ * The value is length-delimited and may contain NUL bytes, which the
++ * NUL-terminated copy would hide from the parser: "zstd:3" followed
++ * by a NUL and junk would pass and be stored verbatim.
++ */
++ if (memchr(value, '\0', len))
++ return -EINVAL;
++
+ memcpy(value_str, value, len);
+ value_str[len] = '\0';
+ if (btrfs_compress_is_valid_type(value_str)) {
+--
+2.47.3
+
--- /dev/null
+From 464a17c7110ff10889f59c0230001ef8fde4ca92 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Tue, 3 Nov 2026 18:41:31 -0500
+Subject: [PATCH 11/11] btrfs: props: keep compressing inodes with legacy
+ compression property values
+To: linux-btrfs@vger.kernel.org
+
+Older kernels matched btrfs.compression values by algorithm name prefix
+only, both in the property validator and in prop_compression_apply(),
+so values such as "zstd:banana", "zstd:", "zstd:3x", "zstdgarbage", or
+anything longer than BTRFS_COMPRESS_PROP_MAX_LEN were accepted, stored
+verbatim, and compressed with the named algorithm. Such values are
+still found on existing filesystems.
+
+Since per-inode compression levels were added, prop_compression_apply()
+parses the value strictly and rejects these with -EINVAL. The property is
+loaded with the inode, and inode_prop_iterator() only warns about a
+failed apply, so these inodes silently stop compressing, with a warning
+every time the inode is loaded.
+
+Keep compressing them as older kernels did: in prop_compression_apply(),
+match the algorithm by name prefix again, and treat a level suffix that
+does not parse, or a value too long to hold a valid level, as an
+unspecified level (prop_compress_level = 0). The compression paths then
+pick the level as for a value with no level at all: the mount option's
+level if the mount option uses the same algorithm, otherwise the
+algorithm's default level.
+
+setxattr still goes through prop_compression_validate(), which keeps
+rejecting these values, so only values that are already stored take this
+path.
+
+---
+ fs/btrfs/props.c | 35 ++++++++++++++++++++---------------
+ 1 file changed, 20 insertions(+), 15 deletions(-)
+
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index 0fabd64cffd2b..4d58c14ff9427 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -332,8 +332,8 @@ static int prop_compression_apply(struct btrfs_inode *inode, const char *value,
+ struct btrfs_fs_info *fs_info = inode->root->fs_info;
+ int type;
+ int level = 0;
+- int ret = 0;
+ char value_str[BTRFS_COMPRESS_PROP_MAX_LEN];
++ size_t copy_len = min(len, sizeof(value_str) - 1);
+ int level_pos = 0;
+
+ /* Reset to defaults */
+@@ -354,19 +354,23 @@ static int prop_compression_apply(struct btrfs_inode *inode, const char *value,
+ return 0;
+ }
+
+- if (len >= BTRFS_COMPRESS_PROP_MAX_LEN)
+- return -EINVAL;
+-
+- memcpy(value_str, value, len);
+- value_str[len] = '\0';
++ /*
++ * Older kernels matched only the algorithm name prefix and stored the
++ * rest of the value without validation, and inodes with such values
++ * are still out there. Keep compressing them with the named
++ * algorithm, as those kernels did: match the prefix here, and leave
++ * the strict checks to prop_compression_validate().
++ */
++ memcpy(value_str, value, copy_len);
++ value_str[copy_len] = '\0';
+
+- if (btrfs_match_compress_type(value_str, "lzo", true)) {
++ if (strncmp(value_str, "lzo", 3) == 0) {
+ type = BTRFS_COMPRESS_LZO;
+ btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
+- } else if (btrfs_match_compress_type(value_str, "zlib", true)) {
++ } else if (strncmp(value_str, "zlib", 4) == 0) {
+ type = BTRFS_COMPRESS_ZLIB;
+ level_pos = 4;
+- } else if (btrfs_match_compress_type(value_str, "zstd", true)) {
++ } else if (strncmp(value_str, "zstd", 4) == 0) {
+ type = BTRFS_COMPRESS_ZSTD;
+ level_pos = 4;
+ btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
+@@ -378,12 +382,13 @@ static int prop_compression_apply(struct btrfs_inode *inode, const char *value,
+ if (level_pos > 0) {
+ const char *level_str = value_str + level_pos;
+
+- /* and if user specified it */
+- if (level_str[0] == ':') {
+- ret = btrfs_compress_str2level(type, level_str, &level);
+- if (ret < 0)
+- return ret;
+- }
++ /*
++ * and if user specified it. A level that does not parse, or a
++ * value too long to be one, counts as unspecified.
++ */
++ if (len == copy_len && level_str[0] == ':' &&
++ btrfs_compress_str2level(type, level_str, &level) < 0)
++ level = 0;
+ }
+
+ inode->flags &= ~BTRFS_INODE_NOCOMPRESS;
+--
+2.47.3
+
-From 0b2a2621fdc37ab3063892db73bfa0cff0f0e29c Mon Sep 17 00:00:00 2001
+From a4a830eb6b96cfcf9bc52dc145cf41f4dc927b7a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:00 -0400
+Date: Fri, 6 Nov 2026 05:48:14 -0500
Subject: [PATCH 0/3] btrfs: deadlocks between reflink, relocation and space reservation
To: linux-btrfs@vger.kernel.org
range has delalloc
btrfs: relocation: reserve all of a folio's slices before dirtying any
- fs/btrfs/reflink.c | 296 +++++++++++++++++++++++++++---------------
- fs/btrfs/relocation.c | 81 ++++++++++--
- 2 files changed, 259 insertions(+), 118 deletions(-)
+ fs/btrfs/reflink.c | 249 ++++++++++++++++++++++++------------------
+ fs/btrfs/relocation.c | 74 +++++++++++--
+ 2 files changed, 205 insertions(+), 118 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 4ec553632d4497d4ae8a2ccf6a546d152d32b16f Mon Sep 17 00:00:00 2001
+From 740693bb3d78f9d17b6d1c253e2c59214969838b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 15 Aug 2026 22:21:10 -0400
Subject: [PATCH 1/3] btrfs: fix flushoncommit deadlock when cloning an inline
folio invalidation.
Fixes: 05a5a7621ce6 ("Btrfs: implement full reflink support for inline extents")
-Assisted-by: Claude:claude-fable-5
---
- fs/btrfs/reflink.c | 177 +++++++++++++++++++--------------------------
- 1 file changed, 74 insertions(+), 103 deletions(-)
+ fs/btrfs/reflink.c | 158 ++++++++++++++++-----------------------------
+ 1 file changed, 55 insertions(+), 103 deletions(-)
diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c
-index b5d2c094941df..c487ab4a63322 100644
+index b5d2c094941df..7a2f5095682ed 100644
--- a/fs/btrfs/reflink.c
+++ b/fs/btrfs/reflink.c
@@ -65,7 +65,6 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
struct folio *folio = NULL;
struct address_space *mapping = inode->vfs_inode.i_mapping;
int ret;
-@@ -74,16 +73,12 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
+@@ -74,16 +73,9 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
file_offset, block_size);
/*
- * inodes, we also have locked the inodes, so we are safe to do a
- * reservation here. Also we must not do the reservation while holding
- * a transaction open, otherwise we would deadlock.
-+ * Our caller has reserved data and metadata space for our block and
-+ * holds an open transaction handle. The reservation can not be done
-+ * here since reserving space while holding a transaction open can
-+ * deadlock, and the transaction must be started before dirtying the
-+ * folio below (see clone_copy_inline_extent()).
++ * Our caller reserved space for our block and started the transaction
++ * before we dirty the folio, see clone_copy_inline_extent().
*/
- ret = btrfs_delalloc_reserve_space(inode, &data_reserved, file_offset,
- block_size);
folio = __filemap_get_folio(mapping, file_offset >> PAGE_SHIFT,
FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
btrfs_alloc_write_mask(mapping));
-@@ -101,13 +96,11 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
+@@ -101,13 +93,11 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
goto out_unlock;
/*
* when we finish cloning all extents, since a transaction is started
* after finding each extent to clone.
*/
-@@ -147,12 +140,6 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
+@@ -147,12 +137,6 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
folio_unlock(folio);
folio_put(folio);
}
return ret;
}
-@@ -178,16 +165,12 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
+@@ -178,16 +162,12 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
fs_info->sectorsize);
struct btrfs_trans_handle *trans = NULL;
struct btrfs_drop_extents_args drop_args = { 0 };
key.objectid = btrfs_ino(inode);
key.type = BTRFS_EXTENT_DATA_KEY;
-@@ -290,73 +273,7 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
+@@ -290,73 +270,7 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
if (unlikely(ret))
btrfs_abort_transaction(trans, ret);
out:
if (ret && trans)
btrfs_end_transaction(trans);
if (!ret)
-@@ -367,17 +284,71 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
+@@ -367,17 +281,55 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
copy_to_page:
/*
* Release our path because we don't need it anymore and also because
btrfs_release_path(path);
+ /*
-+ * Reserve space and start the transaction for the inode item update
-+ * BEFORE copying the inline extent's data into a folio and dirtying
-+ * it.
-+ *
-+ * We hold the destination range locked in the inode's io tree for the
-+ * whole duration of the clone, so once we dirty a folio in that range
-+ * we must not block waiting for a transaction commit: with the
-+ * flushoncommit mount option the committing task flushes dirty inodes
-+ * through the generic writeback path, which knows nothing about
-+ * BTRFS_INODE_NO_DELALLOC_FLUSH, and its flusher then blocks forever
-+ * in find_lock_delalloc_range() on our locked range while we wait for
-+ * that same commit - a deadlock. This is a variant of the one fixed
-+ * by commit b48c980b6a7e ("btrfs: fix deadlock between reflink and
-+ * transaction commit when using flushoncommit"), with the folio
-+ * inside i_size so the flusher writes it back instead of invalidating
-+ * it.
-+ *
-+ * While the locked range is still clean the flusher has no reason to
-+ * touch it, so it is safe to block here, and once we hold the open
-+ * transaction handle we can no longer block waiting for a commit.
-+ * The space reservation must stay ordered before the transaction
-+ * start, since reserving space may flush and wait for a transaction
-+ * commit.
++ * Reserve space and start the transaction before dirtying the folio. We
++ * hold the destination range locked for the whole clone, and with
++ * flushoncommit a commit writes back dirty inodes through the generic
++ * writeback path, which ignores BTRFS_INODE_NO_DELALLOC_FLUSH and would
++ * block on our locked range while we wait for that commit. While the
++ * range is clean, blocking here is safe. Reserve first, since reserving
++ * space may itself wait for a commit.
+ */
+ ret = btrfs_delalloc_reserve_space(inode, &data_reserved,
+ new_key->offset,
+ if (ret)
+ goto out;
+
-+ /* 1 unit to update the inode item after copying the inline extent. */
++ /* 1 unit to update inode item */
+ trans = btrfs_start_transaction(root, 1);
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
-From 52896b16014356c4176587554d6c379201533d36 Mon Sep 17 00:00:00 2001
+From 9a8355ccedd983d8f3b284a3ae3aa086bb9e2541 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 16 Aug 2026 03:31:14 -0400
Subject: [PATCH 2/3] btrfs: reflink: never block on space reservations while
userspace (e.g. a dedupe agent) retry the same range forever.
Fixes: 05a5a7621ce6 ("Btrfs: implement full reflink support for inline extents")
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
- fs/btrfs/reflink.c | 133 +++++++++++++++++++++++++++++++++++++++++----
- 1 file changed, 122 insertions(+), 11 deletions(-)
+ fs/btrfs/reflink.c | 105 ++++++++++++++++++++++++++++++++++++++++-----
+ 1 file changed, 94 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c
-index c487ab4a63322..b7b7437482ead 100644
+index 7a2f5095682ed..976eaa8b51efc 100644
--- a/fs/btrfs/reflink.c
+++ b/fs/btrfs/reflink.c
-@@ -157,7 +157,8 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
+@@ -154,7 +154,8 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
const u64 size,
const u8 comp_type,
char *inline_data,
{
struct btrfs_root *root = inode->root;
struct btrfs_fs_info *fs_info = root->fs_info;
-@@ -340,13 +341,17 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
+@@ -321,13 +322,17 @@ static int clone_copy_inline_extent(struct btrfs_inode *inode,
btrfs_delalloc_release_space(inode, data_reserved,
new_key->offset,
fs_info->sectorsize, true);
}
btrfs_delalloc_release_extents(inode, fs_info->sectorsize);
-@@ -380,6 +385,8 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
+@@ -361,6 +366,8 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
const u64 len = olen_aligned;
u64 last_dest_end = destoff;
u64 prev_extent_end = off;
ret = -ENOMEM;
buf = kvmalloc(fs_info->nodesize, GFP_KERNEL);
-@@ -406,6 +413,7 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
+@@ -387,6 +394,7 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
u64 datao = 0, datal = 0;
u8 comp;
u64 drop_start;
/* Note the key will change type as we walk through the tree */
ret = btrfs_search_slot(NULL, src->root, &key, path, 0, 0);
-@@ -554,7 +562,8 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
+@@ -535,7 +543,8 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
ret = clone_copy_inline_extent(inode, path, &new_key,
drop_start, datal, size,
if (ret)
goto out;
}
-@@ -585,6 +594,29 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
+@@ -566,6 +575,21 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
destoff, olen, no_time_update);
if (ret)
goto out;
+ /*
-+ * Copying an inline extent's data into a folio left delalloc
-+ * inside our caller's locked destination range. The rest of
-+ * the clone starts transactions and reserves space, which must
-+ * not block while the lock covers dirty data: under the
-+ * flushoncommit mount option, a transaction commit (including
-+ * one issued to satisfy a metadata reservation ticket) flushes
-+ * dirty inodes through the generic writeback path, and its
-+ * flusher would block forever on our extent lock while we wait
-+ * for that same commit or ticket. Unlock the dirtied block
-+ * now: every byte still locked is clean, so writeback never
-+ * needs our lock, and the inode's i_rwsem (held for the whole
-+ * remap) keeps writers away from the unlocked block until the
-+ * clone finishes. The inode item for the copied data was
-+ * already updated by clone_finish_inode_update() above.
++ * The inline copy left delalloc in our caller's locked range,
++ * and the rest of the clone may wait for a commit or a
++ * reservation ticket whose flushoncommit writeback would block
++ * on our lock. Unlock the dirtied block so that only clean data
++ * stays locked; i_rwsem keeps writers out of it until the clone
++ * finishes.
+ */
+ if (copied_to_page) {
+ unlocked_start = new_key.offset;
if (new_key.offset + datal >= destoff + len)
break;
-@@ -636,6 +668,22 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
+@@ -617,6 +641,19 @@ static int btrfs_clone(struct btrfs_inode *src, struct btrfs_inode *inode,
}
out:
+ /*
-+ * Our caller unlocks the whole destination range when we return, so
-+ * lock the block we unlocked above again, or the caller would unlock
-+ * it a second time, possibly dropping a lock that writeback or a read
-+ * took on it in the meantime. This cannot deadlock once the path is
-+ * released: we hold no transaction handle or tree lock, writeback of
-+ * the copied block has no reason to lock the rest of our range (it
-+ * has no delalloc), and btrfs_lock_extent() drops the part of a range
-+ * it got before waiting for the rest, so a read covering more than
-+ * the block does not keep it while waiting for us.
++ * Our caller unlocks the whole destination range, so lock the block
++ * unlocked above again, or its unlock could drop a lock that writeback
++ * or a read took meanwhile. With the path released we hold no
++ * transaction or tree lock, and nobody holding this block waits for the
++ * rest of our range (it is clean, and btrfs_lock_extent() drops a
++ * partial range before it waits), so this cannot deadlock.
+ */
+ if (unlocked_end) {
+ btrfs_release_path(path);
clear_bit(BTRFS_INODE_NO_DELALLOC_FLUSH, &inode->runtime_flags);
return ret;
-@@ -669,8 +717,47 @@ static int btrfs_extent_same_range(struct btrfs_inode *src, u64 loff, u64 len,
+@@ -650,8 +687,34 @@ static int btrfs_extent_same_range(struct btrfs_inode *src, u64 loff, u64 len,
* we are safe from concurrency with relocation of source extents
* because we have already locked the inode's i_mmap_lock in exclusive
* mode.
+ *
-+ * The locked range must also have no delalloc: the clone below starts
-+ * transactions and reserves space while holding the lock, and under
-+ * the flushoncommit mount option a transaction commit (including one
-+ * issued to satisfy a metadata reservation ticket) flushes dirty
-+ * inodes through the generic writeback path, whose flusher blocks on
-+ * our extent lock while we may be blocked waiting on that very commit
-+ * or ticket - a deadlock. The ranges were flushed before locking,
-+ * but compressed writeback is asynchronous and may leave delalloc
-+ * behind by the time we lock; both inodes' i_rwsem are held, so once
-+ * the range is clean and locked nothing can dirty it again (the only
-+ * exception, copying an inline extent's data into a folio, unlocks
-+ * the dirtied block before the clone continues - see btrfs_clone()).
-+ *
-+ * Each wait below writes back and waits for whatever delalloc is left
-+ * in the range. Nothing can create more meanwhile: both inodes'
-+ * i_rwsem and i_mmap_lock are held exclusively, so neither write(2) nor
-+ * a page fault can dirty the range. Delalloc that survives two waits
-+ * is therefore a leaked EXTENT_DELALLOC bit (e.g. left behind by a
-+ * failed error path) that no amount of retrying clears, and cloning
-+ * over it would reopen the deadlock above. Report it and fail with
-+ * -EUCLEAN; -EAGAIN would invite userspace to retry forever.
++ * The locked range must also have no delalloc: the clone reserves space
++ * and starts transactions under the lock, and with flushoncommit a
++ * commit (including one serving a reservation ticket) writes back dirty
++ * inodes and would block on our lock. Compressed writeback is
++ * asynchronous and can leave delalloc after the pre-lock flush, so wait
++ * and retry. Both inodes' i_rwsem and i_mmap_lock are held, so delalloc
++ * that survives two waits is a leaked EXTENT_DELALLOC bit: fail with
++ * -EUCLEAN, since -EAGAIN would have userspace retry forever.
*/
- btrfs_lock_extent(&dst->io_tree, dst_loff, end, &cached_state);
+ for (int i = 0; ; i++) {
ret = btrfs_clone(src, dst, loff, len, ALIGN(len, bs), dst_loff, true);
btrfs_unlock_extent(&dst->io_tree, dst_loff, end, &cached_state);
-@@ -770,8 +857,32 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
+@@ -750,9 +813,29 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
+ * we are safe from concurrency with relocation of source extents
* because we have already locked the inode's i_mmap_lock in exclusive
* mode.
++ *
++ * The locked range must also have no delalloc, see
++ * btrfs_extent_same_range().
*/
-+ /*
-+ * The locked range must also have no delalloc before the clone starts
-+ * transactions or reserves space under the lock - see the comment in
-+ * btrfs_extent_same_range() for the flushoncommit deadlock this
-+ * prevents, and for why delalloc left after the waits is reported as
-+ * -EUCLEAN.
-+ */
end = round_up(destoff + len, bs) - 1;
- btrfs_lock_extent(&inode->io_tree, destoff, end, &cached_state);
+ for (int i = 0; ; i++) {
-From 0b2a2621fdc37ab3063892db73bfa0cff0f0e29c Mon Sep 17 00:00:00 2001
+From a4a830eb6b96cfcf9bc52dc145cf41f4dc927b7a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 16 Aug 2026 16:26:54 -0400
Subject: [PATCH 3/3] btrfs: relocation: reserve all of a folio's slices before
still tickets and still flushes, it just no longer traps the flusher.
Fixes: c2832898126f ("btrfs: make relocate_one_page() handle subpage case")
-Assisted-by: Claude:claude-fable-5
---
- fs/btrfs/relocation.c | 81 +++++++++++++++++++++++++++++++++++++------
- 1 file changed, 70 insertions(+), 11 deletions(-)
+ fs/btrfs/relocation.c | 74 ++++++++++++++++++++++++++++++++++++-------
+ 1 file changed, 63 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
-index b2ac5b836b217..8d034cca6313f 100644
+index b2ac5b836b217..be997d32b97d9 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
-@@ -2899,6 +2899,30 @@ static u64 get_cluster_boundary_end(const struct file_extent_cluster *cluster,
+@@ -2899,6 +2899,29 @@ static u64 get_cluster_boundary_end(const struct file_extent_cluster *cluster,
return cluster->boundary[cluster_nr + 1] - 1;
}
+/*
-+ * Release the per-slice delalloc metadata reservations taken up front by
-+ * relocate_one_folio() for the cluster extent slices covering [cur, end].
-+ * @nr is the cluster extent index of the slice containing @cur. Walks the
-+ * same slice geometry as the reservation pass so the releases pair exactly.
++ * Release the reservations relocate_one_folio() took for the cluster extent
++ * slices covering [cur, end]. @nr is the cluster extent index of the slice
++ * containing @cur.
+ */
+static void release_cluster_slice_reservations(struct btrfs_inode *inode,
+ const struct file_extent_cluster *cluster,
static int relocate_one_folio(struct reloc_control *rc,
struct file_ra_state *ra,
int *cluster_nr, u64 *file_offset_ret)
-@@ -2915,6 +2939,7 @@ static int relocate_one_folio(struct reloc_control *rc,
+@@ -2915,6 +2938,7 @@ static int relocate_one_folio(struct reloc_control *rc,
u64 folio_start;
u64 folio_end;
u64 cur;
int ret;
const bool use_rst = btrfs_need_stripe_tree_update(fs_info, rc->block_group->flags);
-@@ -2977,6 +3002,47 @@ static int relocate_one_folio(struct reloc_control *rc,
+@@ -2977,6 +3001,41 @@ static int relocate_one_folio(struct reloc_control *rc,
* inside the folio.
*/
cur = max(folio_start, cluster->boundary[*cluster_nr] - offset);
+
+ /*
-+ * Reserve the delalloc metadata for every cluster extent slice in
-+ * this folio up front, while the folio is still clean. Once a slice
-+ * has been dirtied, a flushing reservation for the next one can
-+ * sleep on a ticket that is only satisfiable by writing this inode
-+ * back (FLUSH_DELALLOC, or a transaction commit, which with
-+ * flushoncommit waits for the same writeback) -- and writeback
-+ * blocks in __folio_lock() on the folio we hold. A clean locked
-+ * folio, by contrast, is invisible to writeback, so flushing is
-+ * still safe here. With one extent slice per folio (4K pages) this
-+ * degenerates to the old single reservation; multiple slices happen
-+ * with large folios or sub-page sector sizes.
++ * Reserve metadata for every extent slice of this folio while the folio
++ * is still clean. Once a slice is dirty, a flushing reservation for the
++ * next one can wait for writeback of this inode (FLUSH_DELALLOC, or a
++ * commit under flushoncommit), which blocks on the folio lock we hold.
++ * Writeback ignores a clean folio, so flushing is safe here.
+ */
+ {
+ int nr = *cluster_nr;
while (cur <= folio_end) {
struct extent_state *cached_state = NULL;
u64 extent_start = cluster->boundary[*cluster_nr] - offset;
-@@ -2986,13 +3052,6 @@ static int relocate_one_folio(struct reloc_control *rc,
+@@ -2986,13 +3045,6 @@ static int relocate_one_folio(struct reloc_control *rc,
u64 clamped_end = min(folio_end, extent_end);
u32 clamped_len = clamped_end + 1 - clamped_start;
/* Mark the range delalloc and dirty for later writeback */
btrfs_lock_extent(&BTRFS_I(inode)->io_tree, clamped_start,
clamped_end, &cached_state);
-@@ -3003,10 +3062,10 @@ static int relocate_one_folio(struct reloc_control *rc,
+@@ -3003,10 +3055,10 @@ static int relocate_one_folio(struct reloc_control *rc,
clamped_start, clamped_end,
EXTENT_LOCKED | EXTENT_BOUNDARY,
&cached_state);
-From 53bbc18925a7d71dec81c68ff49a0c61b7f1c700 Mon Sep 17 00:00:00 2001
+From 1bfce31eb38de064ba209595df90676627d9d621 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:00 -0400
+Date: Fri, 6 Nov 2026 05:48:14 -0500
Subject: [PATCH 0/1] btrfs: one dedupe request, one extent reference
To: linux-btrfs@vger.kernel.org
1 file changed, 2 insertions(+), 19 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 53bbc18925a7d71dec81c68ff49a0c61b7f1c700 Mon Sep 17 00:00:00 2001
+From 1bfce31eb38de064ba209595df90676627d9d621 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Mon, 11 Nov 2024 20:32:54 -0500
Subject: [PATCH 1/1] btrfs: get rid of maximum dedupe length
-From b94af22598cb3e54b002e912db55bd91d27a7bd2 Mon Sep 17 00:00:00 2001
+From 5093b6bc045bef47c57792653482019b952e2cce Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:05 -0400
+Date: Fri, 6 Nov 2026 05:48:16 -0500
Subject: [PATCH 0/1] btrfs: keep mtime and ctime when a dedupe ends in a hole
To: linux-btrfs@vger.kernel.org
5 files changed, 13 insertions(+), 13 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From b94af22598cb3e54b002e912db55bd91d27a7bd2 Mon Sep 17 00:00:00 2001
+From 5093b6bc045bef47c57792653482019b952e2cce Mon Sep 17 00:00:00 2001
From: Ivan Kozik <ivan@ludios.org>
Date: Wed, 30 Sep 2026 06:27:48 +0000
Subject: [PATCH 1/1] btrfs: don't update mtime and ctime when deduping a range
struct btrfs_trans_handle **trans_out);
int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b071ed59a583f..ee7543aef34e0 100644
+index abaa334714566..c8d068a3a858b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -9135,7 +9135,6 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
+@@ -9132,7 +9132,6 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
extent_info.file_offset = file_offset;
extent_info.extent_buf = (char *)&stack_fi;
extent_info.is_new_extent = true;
extent_info.qgroup_reserved = qgroup_released;
extent_info.insertions = 0;
-@@ -9146,7 +9145,7 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
+@@ -9143,7 +9142,7 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
}
ret = btrfs_replace_file_extents(inode, path, file_offset,
-From 1a0d757caa9243c08178c666fde88445e2c0d102 Mon Sep 17 00:00:00 2001
+From 928af994881cc3904fc6572ec9be509e84d6acab Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:00 -0400
+Date: Fri, 6 Nov 2026 05:48:14 -0500
Subject: [PATCH 0/1] btrfs: drain pending NOCOW writes before a block group goes read-only
To: linux-btrfs@vger.kernel.org
5 files changed, 102 insertions(+), 5 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 1a0d757caa9243c08178c666fde88445e2c0d102 Mon Sep 17 00:00:00 2001
+From 928af994881cc3904fc6572ec9be509e84d6acab Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 12 Sep 2026 02:16:28 -0400
Subject: [PATCH 1/1] btrfs: drain pending NOCOW writes before making a block
the group flipped. The block is lifted if the transition fails and when
the group returns to read-write.
-Assisted-by: Claude:claude-opus-4-8
---
fs/btrfs/block-group.c | 58 ++++++++++++++++++++++++++++++++++++++++++
fs/btrfs/block-group.h | 9 +++++++
/* This protects tree_mod_log and tree_mod_seq_list */
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b071ed59a583f..aaf8b04623bd1 100644
+index abaa334714566..39e186cc4c8c0 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7370,10 +7370,20 @@ static bool btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
-From 7573a1e62c50390c9cbbdd8e2b30426a8f73cfc9 Mon Sep 17 00:00:00 2001
+From ba3c140a9b37784b18760540abbdf9e6d7a392b0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:00 -0400
-Subject: [PATCH 0/1] btrfs: allow setting the system chunk size through sysfs
+Date: Fri, 6 Nov 2026 05:48:14 -0500
+Subject: [PATCH 0/2] btrfs: allow setting the system chunk size through sysfs
To: linux-btrfs@vger.kernel.org
Data and metadata chunk sizes can be set through
with patch 2); with the system chunks left at 32 MiB the layout
never gets there and the 32 MiB dev_extents multiply.
-Zygo Blaxell (1):
+Zygo Blaxell (2):
btrfs: allow changing system dev_extent size via sysfs
+ btrfs: prefer aligned dev_extent holes when allocating chunks
- fs/btrfs/sysfs.c | 22 +++++++++++++---------
- 1 file changed, 13 insertions(+), 9 deletions(-)
+ fs/btrfs/sysfs.c | 22 +++++++++++++---------
+ fs/btrfs/volumes.c | 39 +++++++++++++++++++++++++++++----------
+ 2 files changed, 42 insertions(+), 19 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 7573a1e62c50390c9cbbdd8e2b30426a8f73cfc9 Mon Sep 17 00:00:00 2001
+From b42812e5e0a7f6a814164b882ed6f753ac71fc93 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 30 Sep 2023 02:47:08 -0400
-Subject: [PATCH 1/1] btrfs: allow changing system dev_extent size via sysfs
+Subject: [PATCH 1/2] btrfs: allow changing system dev_extent size via sysfs
To: linux-btrfs@vger.kernel.org
When a filesystem using striped profiles such as raid0, raid10, raid5,
--- /dev/null
+From ba3c140a9b37784b18760540abbdf9e6d7a392b0 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Wed, 14 Feb 2024 00:10:23 -0500
+Subject: [PATCH 2/2] btrfs: prefer aligned dev_extent holes when allocating
+ chunks
+To: linux-btrfs@vger.kernel.org
+
+With the previous patch, the data, metadata and system chunk sizes can
+all be set to 1 GiB, so that every dev_extent is 1 GiB long. The holes
+between them are only 1 GiB long as well if the dev_extents also start
+on a common grid. Every device reserves its first 1 MiB, so that grid
+is N GiB + 1 MiB. A dev_extent placed off the grid splits the holes on
+either side into pieces shorter than 1 GiB, and the fragmentation
+described in the previous patch can start from there.
+
+find_free_dev_extent() takes the first hole that is large enough,
+wherever it starts. Make it prefer a hole on the grid: walk the holes in
+device order as before, and take the first one that is large enough and
+starts at N GiB + 1 MiB. If there is none, take the first hole that is
+large enough, which is what the function returned before. If no hole is
+large enough, the largest hole is still returned, with -ENOSPC. The
+hole after the last dev_extent is checked the same way.
+
+Unless a hole on the grid is found, the search now visits every
+dev_extent of the device instead of stopping at the first hole that is
+large enough.
+
+On a device where every dev_extent is 1 GiB long and on the grid, every
+hole starts on the grid too, and the result is the same as before. On a
+device that has off-grid dev_extents, new chunks fill the aligned holes
+first, so balancing the off-grid ones moves them onto the grid.
+
+---
+ fs/btrfs/volumes.c | 39 +++++++++++++++++++++++++++++----------
+ 1 file changed, 29 insertions(+), 10 deletions(-)
+
+diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
+index 3d4ef6725de0e..8ac535d438713 100644
+--- a/fs/btrfs/volumes.c
++++ b/fs/btrfs/volumes.c
+@@ -1907,21 +1907,25 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
+ dev_extent_hole_check(device, &search_start, &hole_size,
+ num_bytes);
+
+- if (hole_size > max_hole_size) {
++ /*
++ * Once we find a hole of sufficient size we
++ * ignore any larger holes that may appear at
++ * higher device offsets. If we later find a
++ * hole that is sufficiently large, but aligned,
++ * we'll use that instead.
++ */
++ if (hole_size > max_hole_size && max_hole_size < num_bytes) {
+ max_hole_start = search_start;
+ max_hole_size = hole_size;
+ }
+
+ /*
+- * If this free space is greater than which we need,
+- * it must be the max free space that we have found
+- * until now, so max_hole_start must point to the start
+- * of this free space and the length of this free space
+- * is stored in max_hole_size. Thus, we return
+- * max_hole_start and max_hole_size and go back to the
+- * caller.
++ * If we find a hole that is aligned and as large
++ * as we need, then exit early with that hole.
+ */
+- if (hole_size >= num_bytes) {
++ if (hole_size >= num_bytes && (search_start & (SZ_1G - 1)) == SZ_1M) {
++ max_hole_start = search_start;
++ max_hole_size = hole_size;
+ ret = 0;
+ goto out;
+ }
+@@ -1946,9 +1950,24 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
+ hole_size = search_end - search_start;
+ dev_extent_hole_check(device, &search_start, &hole_size, num_bytes);
+
+- if (hole_size > max_hole_size) {
++ /*
++ * If this is a larger hole it might not be aligned.
++ * Keep the hole we found above if it was large enough.
++ */
++ if (hole_size > max_hole_size && max_hole_size < num_bytes) {
++ max_hole_start = search_start;
++ max_hole_size = hole_size;
++ }
++
++ /*
++ * The last hole may be aligned and longer than any other,
++ * so do the aligned check and exit early again.
++ */
++ if (hole_size >= num_bytes && (search_start & (SZ_1G - 1)) == SZ_1M) {
+ max_hole_start = search_start;
+ max_hole_size = hole_size;
++ ret = 0;
++ goto out;
+ }
+ }
+
+--
+2.47.3
+
-From ed41a6944651a6be3b301d67d2e7c479a69a98b1 Mon Sep 17 00:00:00 2001
+From 8b54332c3af675c544b8744e56c02a236319f7a9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:06 -0400
+Date: Fri, 6 Nov 2026 05:48:17 -0500
Subject: [PATCH 0/1] btrfs: persist device stats counted without a transaction
To: linux-btrfs@vger.kernel.org
6 files changed, 82 insertions(+), 13 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From ed41a6944651a6be3b301d67d2e7c479a69a98b1 Mon Sep 17 00:00:00 2001
+From 8b54332c3af675c544b8744e56c02a236319f7a9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 22:15:41 -0400
Subject: [PATCH 1/1] btrfs: write dirty device stats when no transaction is
Read-only mounts are unchanged and still lose their counts at unmount,
as do a crash and a shutdown or aborted filesystem.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/disk-io.c | 14 +++++++++++++-
fs/btrfs/super.c | 9 +++++++++
6 files changed, 82 insertions(+), 13 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index c628c5081d923..0955228f81201 100644
+index 6afcd6ca2a8a8..210172773d584 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1559,6 +1559,12 @@ static int transaction_kthread(void *arg)
* We've set the superblock to RO mode, so we might have made the
* cleaner task sleep without running all pending delayed iputs. Go
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index d265fac023e58..0f5c5a9e1e36c 100644
+index cd7dff5ba59b6..b4b6f41d4462d 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -2079,6 +2079,41 @@ int btrfs_commit_current_transaction(struct btrfs_root *root)
bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans);
void btrfs_throttle(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index ce78a9441c64f..e69f444a46622 100644
+index 3d4ef6725de0e..21211e1ea4a39 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -8528,6 +8528,28 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
+@@ -8540,6 +8540,28 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
return ret;
}
/*
* called from commit_transaction. Writes all changed device stats to disk.
*/
-@@ -8538,7 +8560,6 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
+@@ -8550,7 +8572,6 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
struct btrfs_device *device;
int stats_cnt;
int ret = 0;
/*
* Do an initial pass using RCU to see if we need to update any dev
-@@ -8556,17 +8577,7 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
+@@ -8568,17 +8589,7 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans)
* transaction commit, no one can be concurrently adding or removing a
* device.
*/
mutex_lock(&fs_devices->device_list_mutex);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 75b1179776c80..969826cc4fe1b 100644
+index 891bc2432870a..bc8a2c26b2e5d 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
-@@ -795,6 +795,7 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
+@@ -794,6 +794,7 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
int btrfs_init_devices_late(struct btrfs_fs_info *fs_info);
int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
int btrfs_init_writeback_bio_size(struct btrfs_fs_info *fs_info);
-From e0cc444349ea61d819ae8e23a77546608d8340d1 Mon Sep 17 00:00:00 2001
+From 46393acd1f98b9b78a4ca490c822bd4922b38216 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:03:59 -0400
+Date: Fri, 6 Nov 2026 05:48:14 -0500
Subject: [PATCH 0/3] btrfs: reducing LOGICAL_INO costs
To: linux-btrfs@vger.kernel.org
4 files changed, 127 insertions(+), 21 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 843be22c1b284a27d19ef3a1a4a0b87cccb86c65 Mon Sep 17 00:00:00 2001
+From f845118d35c2103f22ba3c00a668ffb87eb62235 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 17 Jul 2026 23:13:26 -0400
Subject: [PATCH 1/3] btrfs: backref: detect tree mod log rewind cycles in
baseline.
Link: https://lore.kernel.org/linux-btrfs/Y28XvZmK0bAS4Ht/@hungrycats.org/
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
---
fs/btrfs/backref.c | 32 ++++++++++++++++++++++++++++++
goto out_unlock;
else if (ret > 0)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b071ed59a583f..2886e24a20514 100644
+index abaa334714566..2944c66336d82 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -10434,7 +10434,20 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
+@@ -10431,7 +10431,20 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
ret = btrfs_is_data_extent_shared(BTRFS_I(inode), disk_bytenr,
extent_gen, backref_ctx);
-From 2054b07c5457979a47e886f6bfdd4bb9edfe4c35 Mon Sep 17 00:00:00 2001
+From 89c214f0311d9c08bbacdd1f4a7cc04bdb3b0481 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 12:36:42 -0400
Subject: [PATCH 2/3] btrfs: resume the delayed-ref merge walk instead of
The restart has had this shape since commit 0e0adbcfdc90 ("btrfs: track
refs in a rb_tree instead of a list") in v4.15.
-Assisted-by: Claude:claude-opus-5
---
fs/btrfs/delayed-ref.c | 49 ++++++++++++++++++++++++++++++++++++------
1 file changed, 42 insertions(+), 7 deletions(-)
-From e0cc444349ea61d819ae8e23a77546608d8340d1 Mon Sep 17 00:00:00 2001
+From 46393acd1f98b9b78a4ca490c822bd4922b38216 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Mon, 23 Jun 2025 13:56:36 +0200
Subject: [PATCH 3/3] btrfs: avoid RCU stall during backref list construction
-From 206f44fec60d023c07b8ebb664fa68bfbeb45902 Mon Sep 17 00:00:00 2001
+From 426b7892a9eb425bb1372bdae4a2aa7fb9f15bd0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:05 -0400
+Date: Fri, 6 Nov 2026 05:48:16 -0500
Subject: [PATCH 0/3] btrfs: keep room to relocate on a full filesystem
To: linux-btrfs@vger.kernel.org
13 files changed, 700 insertions(+), 10 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
prerequisite-patch-id: d27f13acdb7e1fb211a9524027f3f1c8c119f80b
prerequisite-patch-id: 3ba444b908adb7eb7dd36a0bac6a3816516935c4
prerequisite-patch-id: 9eebec1e5af9c3767f7de46e5a2406a7d140b135
prerequisite-patch-id: f1ddaf798fd2a1e0edafa0d5e0d1f6e69833909f
prerequisite-patch-id: 4887cec5ae407264b668f6b0516b62ca97d1da5b
prerequisite-patch-id: 2583346498570387d00120057670c87fd71412a1
+prerequisite-patch-id: 81f1548d694232cc14036224b720b31f9bed3e40
--
2.47.3
-From 94fe7c66de3f69133168923088dc46b4596d7d8d Mon Sep 17 00:00:00 2001
+From b0d57426978bef334b03ae6079cb3c860ea2b992 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 27 Sep 2026 15:02:40 -0400
Subject: [PATCH 1/3] btrfs: print the error when reclaim fails to relocate a
Print the error code.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
-From b9b09749cf786650d281e2a005bed5c80b427e5a Mon Sep 17 00:00:00 2001
+From 4ebff52cc7993f8bf6b6365486ddd76437d411ac Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Mon, 28 Sep 2026 18:14:56 -0400
Subject: [PATCH 2/3] btrfs: hold block groups free for relocation
filesystems, where the chunk allocator caps a chunk at that -- and a
filesystem needs room for the reserve beside its working block groups.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 436 +++++++++++++++++++++++++++++++++++-
fs/btrfs/block-group.h | 26 +++
void btrfs_reclaim_block_groups(struct btrfs_fs_info *fs_info, unsigned int limit);
void btrfs_reclaim_bgs_work(struct work_struct *work);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 27faf262898f7..ff4e7b38f9f1e 100644
+index a91fc9e510ba2..1aed34e4bf92e 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1520,6 +1520,9 @@ static int cleaner_kthread(void *arg)
BTRFS_ATTR_PTR(space_info, chunk_size),
BTRFS_ATTR_PTR(space_info, size_classes),
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 9f689c4c9d7f8..6a68ecc752d25 100644
+index 6c2a9e391dae7..6286a43d458c5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -3723,8 +3723,16 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
+@@ -3735,8 +3735,16 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
bg->start);
}
ret = PTR_ERR(trans);
btrfs_handle_fs_error(root->fs_info, ret, NULL);
return ret;
-@@ -3733,6 +3741,10 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
+@@ -3745,6 +3753,10 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
/* Step two, delete the device extents and the chunk tree entries. */
ret = btrfs_remove_chunk(trans, bg->start);
btrfs_end_transaction(trans);
return ret;
}
-@@ -4351,6 +4363,25 @@ static int should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk *
+@@ -4363,6 +4375,25 @@ static int should_balance_chunk(struct extent_buffer *leaf, struct btrfs_chunk *
return false;
}
-From 206f44fec60d023c07b8ebb664fa68bfbeb45902 Mon Sep 17 00:00:00 2001
+From 426b7892a9eb425bb1372bdae4a2aa7fb9f15bd0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 21 Oct 2026 12:48:13 -0400
Subject: [PATCH 3/3] btrfs: relocation: flush fully before failing a merge
the patch, 6 runs had no merge failure.
Fixes: 44d354abf33e ("btrfs: relocation: review the call sites which can be interrupted by signal")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/relocation.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
-From 34bdaeed875088260f83d6c1ad6212c858199eb1 Mon Sep 17 00:00:00 2001
+From 67df719ccdefbcc38d0f9167a1e42b9318f0ef98 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:01 -0400
+Date: Fri, 6 Nov 2026 05:48:14 -0500
Subject: [PATCH 0/1] btrfs: limit preallocated extents to 128 MiB
To: linux-btrfs@vger.kernel.org
1 file changed, 1 insertion(+), 1 deletion(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 34bdaeed875088260f83d6c1ad6212c858199eb1 Mon Sep 17 00:00:00 2001
+From 67df719ccdefbcc38d0f9167a1e42b9318f0ef98 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 21 Dec 2024 10:48:03 -0500
Subject: [PATCH 1/1] btrfs: use BTRFS_MAX_EXTENT_SIZE in prealloc
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b071ed59a583f..0202108393361 100644
+index abaa334714566..fed5bab60a000 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -9185,7 +9185,7 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9182,7 +9182,7 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
u64 end = start + num_bytes - 1;
while (num_bytes > 0) {
-From a4b35a2e9704dbbb331f8931774d6d433c4bffeb Mon Sep 17 00:00:00 2001
+From 3b022e96c7a88a5ad5c389f756b75ff8d3dcafa5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:01 -0400
+Date: Fri, 6 Nov 2026 05:48:14 -0500
Subject: [PATCH 00/10] btrfs: raid56: rbio lifetime and cache fixes, error reporting
To: linux-btrfs@vger.kernel.org
6 files changed, 601 insertions(+), 40 deletions(-)
-base-commit: 83cd81353093be02aa7e60874c413ec340e55bce
--
2.47.3
+++ /dev/null
-From 61de2dcc3af6651d7612d23fd7192fa2838c1278 Mon Sep 17 00:00:00 2001
-From: Qu Wenruo <wqu@suse.com>
-Date: Wed, 28 Oct 2026 17:00:46 +1030
-Subject: [PATCH 01/12] btrfs: fix racy bio_list changes for failed RMW rbio
-To: linux-btrfs@vger.kernel.org
-
-If an RMW work failed early, e.g. alloc_rbio_parity_pages() failed, it
-won't get RBIO_RMW_LOCKED_BIT set, and get rbio_orig_end_io() called.
-
-In that case, there can be a race between bio_list_get() on the rbio,
-and new incoming bio merging into the rbio:
-
- A is the rbio that rbio_orig_end_io() is running on.
- a is the higher layer bio that generated the rbio A.
-
- B is the new rbio that will be merged into A.
- b is the higher layer bio that generated the rbio B.
-
- rbio_orig_end_io(A) worker | lock_stripe_add(B)
---------------------------------------+---------------------------------
-rbio_orig_end_io(A) | lock_stripe_add(B)
-|- cur = bio_list_get(A) | |- rbio_can_merge(A, B)
-| |- bio = A->bio_list.head; | | which returned true
-| | which bio a is returned. | |
-| | | |
-| |- A->bio_list.tail = NULL; | |
-| | | |
-| | | |- merge_rbio(A, B)
-| | | | |- bio_list_merge_init()
-| | | | |- if (A->bio_list.tail)
-| | | | | A->bio_list.tail is
-| | | | | still NULL
-| | | | |
-| | | | |- A->bio_list.head = b
-| | | | |- A->bio_list.tail = b
-| |- A->bio_list.head = NULL; | |- return 1;
-| |- return bio; | Caller expect rbio A to
-| which is bio a. | complete bio b.
-|
-|- extra = bio_list_get()
-| Which is NULL
-|
-|- rbio_endio_bio_list(cur);
- Which only ends bio a.
-
-In above case, the bio_list race can get bio b lost, and never ended.
-Thankfully this race window is very tiny, so not practical in the real
-world.
-
-Fix it by setting RBIO_RMW_LOCKED_BIT for error path before calling
-rbio_orig_end_io().
-And since we're ensuring all RMW rbios have RBIO_RMW_LOCKED_BIT bit set
-before calling rbio_orig_end_io(), add two ASSERT()s for that and remove
-the old comment.
-
-Fixes: 5eb30ee26fa4 ("btrfs: raid56: introduce the main entrance for RMW path")
-Assisted-by: LLM (find and analyze the bug)
-Reviewed-by: Filipe Manana <fdmanana@suse.com>
-Signed-off-by: Qu Wenruo <wqu@suse.com>
-Link: https://lore.kernel.org/r/5a11091a4fb79de6a37bcec6c70b178467641f28.1793168898.git.wqu@suse.com
----
- fs/btrfs/raid56.c | 32 ++++++++++++++++++++------------
- 1 file changed, 20 insertions(+), 12 deletions(-)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 7dd937fa0c262..b24ec362909bb 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -874,7 +874,10 @@ static void rbio_endio_bio_list(struct bio *cur, blk_status_t status)
- static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
- {
- struct bio *cur = bio_list_get(&rbio->bio_list);
-- struct bio *extra;
-+
-+ /* An RMW rbio must have RBIO_RMW_LOCKED_BIT set. */
-+ if (rbio->operation == BTRFS_RBIO_WRITE)
-+ ASSERT(test_bit(RBIO_RMW_LOCKED_BIT, &rbio->flags));
-
- kfree(rbio->csum_buf);
- bitmap_free(rbio->csum_bitmap);
-@@ -888,21 +891,11 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
- */
- bitmap_clear(&rbio->dbitmap, 0, rbio->stripe_nsectors);
-
-- /*
-- * At this moment, rbio->bio_list is empty, however since rbio does not
-- * always have RBIO_RMW_LOCKED_BIT set and rbio is still linked on the
-- * hash list, rbio may be merged with others so that rbio->bio_list
-- * becomes non-empty.
-- * Once unlock_stripe() is done, rbio->bio_list will not be updated any
-- * more and we can call bio_endio() on all queued bios.
-- */
- unlock_stripe(rbio);
-- extra = bio_list_get(&rbio->bio_list);
-+ ASSERT(bio_list_empty(&rbio->bio_list));
- free_raid_bio(rbio);
-
- rbio_endio_bio_list(cur, status);
-- if (extra)
-- rbio_endio_bio_list(extra, status);
- }
-
- /*
-@@ -2464,6 +2457,21 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
- }
- }
- out:
-+ /*
-+ * If we hit an error early, the rbio won't get
-+ * RBIO_RMW_LOCKED_BIT bit set, and can cause unexpected
-+ * merge during rbio_orig_end_io().
-+ *
-+ * So set that flag before calling rbio_orig_end_io(), and
-+ * we have to hold the bio_list_lock, to make sure
-+ * rbio_can_merge() and merge_rbio() are seeing a stable
-+ * flag.
-+ */
-+ if (ret < 0) {
-+ spin_lock(&rbio->bio_list_lock);
-+ set_bit(RBIO_RMW_LOCKED_BIT, &rbio->flags);
-+ spin_unlock(&rbio->bio_list_lock);
-+ }
- rbio_orig_end_io(rbio, errno_to_blk_status(ret));
- }
-
---
-2.47.3
-
--- /dev/null
+From 85b1734748117b2908a2af848cf804a802447818 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/10] btrfs: log a message when dropping an extent due to IO
+ error
+To: linux-btrfs@vger.kernel.org
+
+When an IO error occurs while writing a datacow file, btrfs will drop the
+extent containing the unwritten blocks. This prevents potential leaks
+of information stored in the unwritten data blocks back to userspace, but
+it is also a data loss event that is not easily visible from userspace.
+
+The existing code does notify userspace of the error via the inode,
+and the notification can be received through fsync (for the inode) or
+syncfs (for any dirty inode on the filesystem) return values; however,
+for the common case of a process that writes to a file and exits with
+its data still in dirty cache pages, there is no process left to notify
+when the ordered writes eventually fail.
+
+In most cases the extent drop is preceded by error messages from the
+write operation, but the IOERR bit can be set for less visible or obvious
+reasons, like running out of memory, bad metadata, or as a result of
+bugs that appear in other parts of btrfs from time to time.
+
+Some of the existing error messages for writes contain only logical
+addresses, while other messages contain only disk bytenrs. For read
+errors, only one address is necessary, as the user can look up the other
+with `btrfs ins log -o` or `btrfs ins sub/ino`, but for write errors, the
+mapping between these addresses is removed when the error is detected in
+btrfs_finish_one_ordered, so we can't derive one address from the other.
+We need both addresses for separate purposes: the logical address to
+identify which files have missing data, and the disk bytenr to identify
+which part of the filesystem address space is failing to accept writes
+(resolvable to device sectors through the chunk tree).
+
+For now, inform the sysadmin that the data has been dropped by logging a
+message when it happens, including both the logical subvol/inode/offset
+triple and the disk bytenr, and the corresponding sizes.
+
+In the future we might want to add some stats counters for this event,
+similar to the dev stats counters, but not tied to any specific device.
+The first step is to detect and report the events at all.
+
+Other notes:
+
+Because the extent is dropped, the lost data cannot be detected by a csum
+mismatch or read failure, i.e. everything will look OK if the file is read
+or the filesystem scrubbed, but an application will notice a truncated
+file or a file with data replaced by zeros. For datasum files, we could
+simply keep the extent as-is, allow future reads or csum verification
+to fail, and report EIO errors that way. That is a larger and riskier
+change to btrfs behavior than simply adding some passive monitoring of
+the status quo. This approach also has problems with csum collisions,
+it doesn't work for nodatasum+datacow files, and it takes much longer
+for the errors to be detected and reported to a sysadmin.
+
+nodatacow files don't have their extents dropped; instead, they will
+simply have garbage in the blocks where the writes failed. In most
+use cases for nodatacow files (e.g. VM disk images or databases), the
+user will be running all writes through fsync(), O_DIRECT, or similar
+mechanisms that can observe the existing EIO return value notification
+path, so there's less need for diagnostic coverage in the kernel log
+for nodatacow files.
+
+Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+---
+ fs/btrfs/inode.c | 16 ++++++++++++++++
+ 1 file changed, 16 insertions(+)
+
+diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
+index abaa334714566..85ce4f2433eb4 100644
+--- a/fs/btrfs/inode.c
++++ b/fs/btrfs/inode.c
+@@ -3389,6 +3389,22 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
+ clear_reserved_extent &&
+ !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
+ !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
++ /*
++ * Notify the user that some data has been lost due
++ * to an error, unless we were already expected to
++ * remove the data because of truncate.
++ *
++ * Put both logical and physical addresses here
++ * because we're about to remove the mapping that
++ * would have allowed the user to translate from
++ * one to the other.
++ */
++ if (ret && !truncated)
++ btrfs_err_rl(fs_info,
++"dropping unwritten extent at root %llu ino %llu offset [%llu,%llu] disk bytenr %llu length %llu",
++ btrfs_root_id(inode->root), btrfs_ino(inode),
++ start, end, ordered_extent->disk_bytenr,
++ ordered_extent->disk_num_bytes);
+ /*
+ * Discard the range before returning it back to the
+ * free space pool
+--
+2.47.3
+
+++ /dev/null
-From ecf7603159cd81ec718af1efaeb529db1729132b Mon Sep 17 00:00:00 2001
-From: Qu Wenruo <wqu@suse.com>
-Date: Wed, 28 Oct 2026 17:00:47 +1030
-Subject: [PATCH 02/12] btrfs: don't cache rbio if an error is hit
-To: linux-btrfs@vger.kernel.org
-
-If rmw_rbio() hit an error after cache_rbio_pages() call, the rbio still
-have RBIO_CACHE_READY_BIT set, thus can be utilized for future page
-stealing.
-
-But that rbio didn't really reach the disk, thus using the pages for
-future steal can cause data inconsistency between in-memory cache and
-on-disk data.
-
-Fix the problem by clearing the RBIO_CACHE_READY_BIT on the error path
-of rmw_rbio().
-
-Fixes: 5eb30ee26fa4 ("btrfs: raid56: introduce the main entrance for RMW path")
-Assisted-by: LLM (find the bug)
-Reviewed-by: Filipe Manana <fdmanana@suse.com>
-Signed-off-by: Qu Wenruo <wqu@suse.com>
-Link: https://lore.kernel.org/r/b0d3adf5f3cc527b2ffd89c7ed93c99a0cbbdc76.1793168898.git.wqu@suse.com
----
- fs/btrfs/raid56.c | 3 +++
- 1 file changed, 3 insertions(+)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index b24ec362909bb..a8a8004bb14c7 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -2471,6 +2471,9 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
- spin_lock(&rbio->bio_list_lock);
- set_bit(RBIO_RMW_LOCKED_BIT, &rbio->flags);
- spin_unlock(&rbio->bio_list_lock);
-+
-+ /* Failed write, don't cache for page stealing. */
-+ clear_bit(RBIO_CACHE_READY_BIT, &rbio->flags);
- }
- rbio_orig_end_io(rbio, errno_to_blk_status(ret));
- }
---
-2.47.3
-
--- /dev/null
+From b0642b6384ab856b087762f9e6bba6ce93d93be6 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/10] btrfs: raid56: fix use-after-free of rbio in bio end_io
+ wakeups
+To: linux-btrfs@vger.kernel.org
+
+The read/write submission rounds in raid56 count in-flight bios in
+rbio->stripes_pending and wait with a bare
+wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0),
+while each bio's end_io does
+"if (atomic_dec_and_test(&stripes_pending)) wake_up(&rbio->io_wait)".
+
+Once the final decrement makes the counter visible as zero, the waiter
+can pass its condition check without consuming the wakeup -- via
+wait_event()'s fast path when all bios complete before the waiter
+arrives, or a condition recheck after an earlier wakeup -- and proceed
+to free the rbio through rbio_orig_end_io(). The end_io context is
+then still inside wake_up() operating on the freed rbio's embedded
+waitqueue lock.
+
+This shows up under sustained raid56 load in KVM guests as recurring
+"pvqspinlock: lock ... has corrupted value 0x0!" warnings from
+__pv_queued_spin_unlock_slowpath with a
+__wake_up <- raid_wait_{read,write}_end_io <- bio_endio call trace:
+paravirt spinlocks detect the unlock of the recycled lock word. KASAN
+reports it as a slab-use-after-free in __wake_up_common or
+do_raw_spin_unlock from the same end_io handlers. On bare metal
+without KASAN the use-after-free is silent and almost always harmless,
+which is how it has survived; it is a plausible match for
+long-standing sporadic crash reports on busy raid5 filesystems.
+
+It reproduces in about 12 seconds in a KVM guest running a KASAN
+kernel, on a degraded raid5 data / raid1 metadata filesystem on four
+2 GiB devices with one missing:
+ - 8 parallel O_DIRECT readers of 4K, 16K or 64K at random offsets in
+ existing files, so every read of a block on the missing device is a
+ reconstruction round;
+ - 2 writers rewriting small files with 4K..32K O_DIRECT writes, so
+ writes are sub-stripe read-modify-write rounds;
+ - the page cache dropped every second.
+With this patch the same load runs for 10 minutes without a warning.
+
+Convert the pair to a completion. wait_for_completion()'s fast path
+takes the completion's own lock, so it cannot return before complete()
+has released it: the completing context is provably finished with the
+rbio before the waiter can free it. A submitter-held bias count keeps
+one completion per submission round even when a round submits zero
+bios or every bio finishes before the submitter starts waiting; the
+scrub path only waits when finish_parity_scrub() actually began a
+round.
+
+Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+---
+ fs/btrfs/raid56.c | 54 ++++++++++++++++++++++++++++++++++++++---------
+ fs/btrfs/raid56.h | 10 ++++++++-
+ 2 files changed, 53 insertions(+), 11 deletions(-)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index a8a8004bb14c7..4453a50866b43 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -1019,7 +1019,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
+ }
+
+ bio_list_init(&rbio->bio_list);
+- init_waitqueue_head(&rbio->io_wait);
++ init_completion(&rbio->io_done);
+ INIT_LIST_HEAD(&rbio->plug_list);
+ spin_lock_init(&rbio->bio_list_lock);
+ INIT_LIST_HEAD(&rbio->stripe_cache);
+@@ -1606,6 +1606,40 @@ static void verify_bio_data_sectors(struct btrfs_raid_bio *rbio,
+ }
+ }
+
++/*
++ * Begin a submission round of @nr bios whose end_io functions report through
++ * rbio_dec_io(). stripes_pending gets one extra count on behalf of the
++ * submitter, dropped by rbio_wait_io(): this guarantees exactly one
++ * completion per round even when @nr is 0 or every bio finishes before the
++ * submitter starts waiting.
++ *
++ * The completion is what makes the round safe against a use-after-free the
++ * old bare waitqueue had: once the final bio's decrement made
++ * stripes_pending visible as zero, the waiter could pass its wait_event()
++ * condition check and free the rbio while the bio's end_io context was still
++ * inside wake_up() on the rbio's embedded waitqueue lock. With a
++ * completion, the waiter cannot return before complete() has released the
++ * completion's lock, so the completing context is finished with the rbio.
++ */
++static void rbio_begin_io(struct btrfs_raid_bio *rbio, unsigned int nr)
++{
++ reinit_completion(&rbio->io_done);
++ atomic_set(&rbio->stripes_pending, nr + 1);
++}
++
++static void rbio_dec_io(struct btrfs_raid_bio *rbio)
++{
++ if (atomic_dec_and_test(&rbio->stripes_pending))
++ complete(&rbio->io_done);
++}
++
++static void rbio_wait_io(struct btrfs_raid_bio *rbio)
++{
++ /* Drop the submitter's count from rbio_begin_io(). */
++ rbio_dec_io(rbio);
++ wait_for_completion(&rbio->io_done);
++}
++
+ static void raid_wait_read_end_io(struct bio *bio)
+ {
+ struct btrfs_raid_bio *rbio = bio->bi_private;
+@@ -1618,8 +1652,7 @@ static void raid_wait_read_end_io(struct bio *bio)
+ }
+
+ bio_put(bio);
+- if (atomic_dec_and_test(&rbio->stripes_pending))
+- wake_up(&rbio->io_wait);
++ rbio_dec_io(rbio);
+ }
+
+ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
+@@ -1627,7 +1660,7 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
+ {
+ struct bio *bio;
+
+- atomic_set(&rbio->stripes_pending, bio_list_size(bio_list));
++ rbio_begin_io(rbio, bio_list_size(bio_list));
+ while ((bio = bio_list_pop(bio_list))) {
+ bio->bi_end_io = raid_wait_read_end_io;
+
+@@ -1640,7 +1673,7 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
+ submit_bio(bio);
+ }
+
+- wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0);
++ rbio_wait_io(rbio);
+ }
+
+ static int alloc_rbio_data_pages(struct btrfs_raid_bio *rbio)
+@@ -2328,8 +2361,7 @@ static void raid_wait_write_end_io(struct bio *bio)
+ if (bio->bi_status)
+ rbio_update_error_bitmap(rbio, bio);
+ bio_put(bio);
+- if (atomic_dec_and_test(&rbio->stripes_pending))
+- wake_up(&rbio->io_wait);
++ rbio_dec_io(rbio);
+ }
+
+ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+@@ -2337,7 +2369,7 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+ {
+ struct bio *bio;
+
+- atomic_set(&rbio->stripes_pending, bio_list_size(bio_list));
++ rbio_begin_io(rbio, bio_list_size(bio_list));
+ while ((bio = bio_list_pop(bio_list))) {
+ bio->bi_end_io = raid_wait_write_end_io;
+
+@@ -2444,7 +2476,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+ /* We should have at least one bio assembled. */
+ ASSERT(bio_list_size(&bio_list));
+ submit_write_bios(rbio, &bio_list);
+- wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0);
++ rbio_wait_io(rbio);
+
+ /* We may have more errors than our tolerance during the read. */
+ for (sectornr = 0; sectornr < rbio->stripe_nsectors; sectornr++) {
+@@ -2915,7 +2947,9 @@ static void scrub_rbio(struct btrfs_raid_bio *rbio)
+ * and writeback the good content.
+ */
+ ret = finish_parity_scrub(rbio);
+- wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0);
++ /* A submission round only began if finish_parity_scrub() succeeded. */
++ if (ret == 0)
++ rbio_wait_io(rbio);
+ for (sector_nr = 0; sector_nr < rbio->stripe_nsectors; sector_nr++) {
+ int found_errors;
+
+diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
+index 8700910b8dc99..b56f9b958d713 100644
+--- a/fs/btrfs/raid56.h
++++ b/fs/btrfs/raid56.h
+@@ -13,6 +13,7 @@
+ #include <linux/bio.h>
+ #include <linux/refcount.h>
+ #include <linux/workqueue.h>
++#include <linux/completion.h>
+ #include "volumes.h"
+
+ struct page;
+@@ -173,9 +174,16 @@ struct btrfs_raid_bio {
+
+ refcount_t refs;
+
++ /*
++ * In-flight bios of the current submission round, plus one bias
++ * count held by the submitter and dropped when it starts waiting.
++ * The final decrement completes io_done; a completion (unlike a
++ * bare waitqueue) guarantees the completing context is finished
++ * with the rbio before the waiter can return and free it.
++ */
+ atomic_t stripes_pending;
+
+- wait_queue_head_t io_wait;
++ struct completion io_done;
+
+ /* Bitmap to record which horizontal stripe has data */
+ unsigned long dbitmap;
+--
+2.47.3
+
--- /dev/null
+From ad380c9ebe7095df530a61447fd8f81e4921f8bd Mon Sep 17 00:00:00 2001
+From: Josef Bacik <josef@toxicpanda.com>
+Date: Tue, 3 Nov 2026 15:05:16 +0000
+Subject: [PATCH 03/10] btrfs: don't drop the error of the last split bio
+To: linux-btrfs@vger.kernel.org
+
+When a btrfs_bio had to be split, btrfs_bio_end_io() saves the first error
+of any of its parts in the status field of the original btrfs_bio. The
+part that completes last is supposed to load it into bi_status of the
+original bio before calling the end_io handler, but that is only done if
+that last part was successful:
+
+ if (atomic_dec_and_test(&bbio->pending_ios)) {
+ /* Load split bio's error which might be set above. */
+ if (status == BLK_STS_OK)
+ bbio->bio.bi_status = READ_ONCE(bbio->status);
+
+If the last part failed, the assumption is that bi_status was set at the
+top of the function. That is true if the last part is what is left of the
+original bio. If it is a split bio, the assignment was done to the split
+bio, which was freed right after. If the original bio has completed before
+without an error, its bi_status is BLK_STS_OK and stays like that:
+
+ original bio (tail) split bio (head)
+
+ btrfs_bio_end_io(orig, OK)
+ orig->bio.bi_status = OK
+ pending_ios 2 -> 1
+ btrfs_bio_end_io(split, IOERR)
+ split->bio.bi_status = IOERR
+ bio_put(split)
+ cmpxchg(&orig->status, OK, IOERR)
+ pending_ios 1 -> 0
+ orig->end_io(), bi_status is OK
+
+The end_io handler covers the whole range, so for a buffered read all the
+folios are marked uptodate, including the ones that were never filled, and
+read(2) returns their content instead of -EIO. For a write the ordered
+extent is completed as if all the data had reached the device.
+
+This can be reproduced with raid0 data on two devices, one of them slower
+than the other and with a bad block, by reading a file whose last stripe
+is on the fast device.
+
+The saved status has the first error of all the parts, or BLK_STS_OK if
+there was none, so always use it.
+
+Fixes: d48e1dea3931 ("btrfs: fix error propagation of split bios")
+CC: stable@vger.kernel.org # 6.12+
+Reviewed-by: Qu Wenruo <wqu@suse.com>
+Reviewed-by: Filipe Manana <fdmanana@suse.com>
+Tested-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Signed-off-by: Josef Bacik <josef@toxicpanda.com>
+Link: https://lore.kernel.org/r/20261103-b4-btrfs-data-integrity-v2-1-577dc2690061@toxicpanda.com
+---
+ fs/btrfs/bio.c | 9 ++++++---
+ 1 file changed, 6 insertions(+), 3 deletions(-)
+
+diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
+index 2c6234f6182f8..fc0b021cdefb1 100644
+--- a/fs/btrfs/bio.c
++++ b/fs/btrfs/bio.c
+@@ -127,9 +127,12 @@ void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
+ cmpxchg(&bbio->status, BLK_STS_OK, status);
+
+ if (atomic_dec_and_test(&bbio->pending_ios)) {
+- /* Load split bio's error which might be set above. */
+- if (status == BLK_STS_OK)
+- bbio->bio.bi_status = READ_ONCE(bbio->status);
++ /*
++ * Load the first error, if any. It may come from a split bio,
++ * including the one we were called for, in which case nothing
++ * stored it in the original bio yet.
++ */
++ bbio->bio.bi_status = READ_ONCE(bbio->status);
+
+ if (bbio_has_ordered_extent(bbio)) {
+ struct btrfs_ordered_extent *ordered = bbio->ordered;
+--
+2.47.3
+
+++ /dev/null
-From c4a57fb229aadbdacfca2bc6b2bef62557183dfc 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 03/12] btrfs: log a message when dropping an extent due to IO
- error
-To: linux-btrfs@vger.kernel.org
-
-When an IO error occurs while writing a datacow file, btrfs will drop the
-extent containing the unwritten blocks. This prevents potential leaks
-of information stored in the unwritten data blocks back to userspace, but
-it is also a data loss event that is not easily visible from userspace.
-
-The existing code does notify userspace of the error via the inode,
-and the notification can be received through fsync (for the inode) or
-syncfs (for any dirty inode on the filesystem) return values; however,
-for the common case of a process that writes to a file and exits with
-its data still in dirty cache pages, there is no process left to notify
-when the ordered writes eventually fail.
-
-In most cases the extent drop is preceded by error messages from the
-write operation, but the IOERR bit can be set for less visible or obvious
-reasons, like running out of memory, bad metadata, or as a result of
-bugs that appear in other parts of btrfs from time to time.
-
-Some of the existing error messages for writes contain only logical
-addresses, while other messages contain only disk bytenrs. For read
-errors, only one address is necessary, as the user can look up the other
-with `btrfs ins log -o` or `btrfs ins sub/ino`, but for write errors, the
-mapping between these addresses is removed when the error is detected in
-btrfs_finish_one_ordered, so we can't derive one address from the other.
-We need both addresses for separate purposes: the logical address to
-identify which files have missing data, and the disk bytenr to identify
-which part of the filesystem address space is failing to accept writes
-(resolvable to device sectors through the chunk tree).
-
-For now, inform the sysadmin that the data has been dropped by logging a
-message when it happens, including both the logical subvol/inode/offset
-triple and the disk bytenr, and the corresponding sizes.
-
-In the future we might want to add some stats counters for this event,
-similar to the dev stats counters, but not tied to any specific device.
-The first step is to detect and report the events at all.
-
-Other notes:
-
-Because the extent is dropped, the lost data cannot be detected by a csum
-mismatch or read failure, i.e. everything will look OK if the file is read
-or the filesystem scrubbed, but an application will notice a truncated
-file or a file with data replaced by zeros. For datasum files, we could
-simply keep the extent as-is, allow future reads or csum verification
-to fail, and report EIO errors that way. That is a larger and riskier
-change to btrfs behavior than simply adding some passive monitoring of
-the status quo. This approach also has problems with csum collisions,
-it doesn't work for nodatasum+datacow files, and it takes much longer
-for the errors to be detected and reported to a sysadmin.
-
-nodatacow files don't have their extents dropped; instead, they will
-simply have garbage in the blocks where the writes failed. In most
-use cases for nodatacow files (e.g. VM disk images or databases), the
-user will be running all writes through fsync(), O_DIRECT, or similar
-mechanisms that can observe the existing EIO return value notification
-path, so there's less need for diagnostic coverage in the kernel log
-for nodatacow files.
-
-Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
----
- fs/btrfs/inode.c | 16 ++++++++++++++++
- 1 file changed, 16 insertions(+)
-
-diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b071ed59a583f..8b95be6893f0e 100644
---- a/fs/btrfs/inode.c
-+++ b/fs/btrfs/inode.c
-@@ -3389,6 +3389,22 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
- clear_reserved_extent &&
- !test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags) &&
- !test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
-+ /*
-+ * Notify the user that some data has been lost due
-+ * to an error, unless we were already expected to
-+ * remove the data because of truncate.
-+ *
-+ * Put both logical and physical addresses here
-+ * because we're about to remove the mapping that
-+ * would have allowed the user to translate from
-+ * one to the other.
-+ */
-+ if (ret && !truncated)
-+ btrfs_err_rl(fs_info,
-+"dropping unwritten extent at root %llu ino %llu offset [%llu,%llu] disk bytenr %llu length %llu",
-+ btrfs_root_id(inode->root), btrfs_ino(inode),
-+ start, end, ordered_extent->disk_bytenr,
-+ ordered_extent->disk_num_bytes);
- /*
- * Discard the range before returning it back to the
- * free space pool
---
-2.47.3
-
--- /dev/null
+From fe7a2838cad5d631362cc52d27549052b35854c0 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/10] btrfs: raid56: drop cached rbios when their stripes'
+ extents are freed
+To: linux-btrfs@vger.kernel.org
+
+A cached rbio keeps an in-memory copy of its full stripe's data
+sectors so that a later sub-stripe write can steal the pages (see
+steal_rbio()) and skip the RMW read. That is only safe while the
+cache and the disk agree. Nothing invalidates cache entries when the
+stripe's extents are freed, so an entry can outlive the data it
+describes: the space is reallocated, a sub-stripe write to the reused
+stripe steals the stale pages, and parity is generated from the
+cache's memory of the stripe's previous life instead of from disk.
+
+If the on-disk content diverged from that memory in the meantime, the
+result is silent, latent damage. The divergence does not require a
+second write: a device error that corrupts a column holding only
+freed data is invisible (no live extent, no csum to fail, nothing for
+scrub to check), but the stale cached copy of that column predates
+the corruption. The poisoned write then produces parity consistent
+with the cache's memory and inconsistent with the actual on-disk
+column. Every read of the live data still passes csum and scrub
+reports nothing, so the loss surfaces only when a device failure
+forces reconstruction -- which XORs the real on-disk garbage against
+parity that remembers different bytes, and hands back trash.
+
+This was found and proven byte-exactly on a raid5 test array: a
+stripe's parity solved uniquely as the XOR of fresh data with the
+PRE-corruption content of a free-space column -- bytes that existed
+nowhere on disk at write time and could only have come from the rbio
+cache. The resulting single-column loss was undetectable by scrub
+and unrecoverable by reconstruction.
+
+Drop cache entries overlapping freed extents at unpin time, when the
+space returns to circulation. The walk is gated on raid56 block
+groups, so filesystems without raid56 never touch it, and the LRU
+list is bounded (RBIO_CACHE_SIZE entries).
+
+The cost of dropping entries was measured on an instrumented stock
+kernel that marks affected entries instead of dropping them, and
+counts a reintroduced RMW full-stripe read whenever a read-skip was
+only possible because of a marked entry. In a worst-case free-heavy
+small-file churn on a 5-device raid5 array with raid5 metadata --
+conditions chosen to flatter the cache, and it delivers, with 87% of
+sub-stripe RMWs skipping their read -- only 1% of those skips (64 of
+6430) were enabled by entries this patch drops, costing 0.04-0.12
+MB/s of extra reads against the workload's own 0.3-0.7 MB/s of
+writes. 93% of the entries the patch drops were evicted without
+ever being stolen again.
+
+---
+ fs/btrfs/extent-tree.c | 10 ++++++++++
+ fs/btrfs/raid56.c | 37 +++++++++++++++++++++++++++++++++++++
+ fs/btrfs/raid56.h | 1 +
+ 3 files changed, 48 insertions(+)
+
+diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
+index 9b0a5c6b96f3c..e9248e52d1dce 100644
+--- a/fs/btrfs/extent-tree.c
++++ b/fs/btrfs/extent-tree.c
+@@ -2868,6 +2868,16 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
+ if (return_free_space)
+ btrfs_add_free_space(cache, start, len);
+
++ /*
++ * The rbio stripe cache may still remember this range's
++ * pre-free contents; a later sub-stripe write into the
++ * reused stripes would steal those pages and generate
++ * parity from them. Drop the stale entries now that the
++ * extents are gone.
++ */
++ if (cache->flags & BTRFS_BLOCK_GROUP_RAID56_MASK)
++ btrfs_raid56_uncache_range(fs_info, start, len);
++
+ start += len;
+ total_unpinned += len;
+ space_info = cache->space_info;
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 4453a50866b43..5ec0ec769a0c8 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -464,6 +464,43 @@ static void remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
+ spin_unlock(&table->cache_lock);
+ }
+
++/*
++ * Drop cached rbios whose full stripes overlap [start, start + len).
++ *
++ * Called when extents in that range are freed. A cached rbio holds an
++ * in-memory copy of its stripe's data sectors; once the extents are gone
++ * the space can be reallocated, and a later sub-stripe write to the same
++ * stripe would steal the cached pages (see steal_rbio()) and compute
++ * parity from the cache's memory of the stripe's previous life instead
++ * of reading the disk. If the on-disk content diverged from that memory
++ * in the meantime -- for example a device error corrupted a column that
++ * no longer had live data, so nothing noticed -- the write produces
++ * parity that disagrees with the on-disk columns, and the stripe is
++ * latently unreconstructible: every read of the live data passes csum,
++ * scrub sees nothing wrong, and the loss only surfaces when a device
++ * failure forces reconstruction. Freed extents' cache entries have no
++ * value to keep: drop them.
++ */
++void btrfs_raid56_uncache_range(struct btrfs_fs_info *info, u64 start, u64 len)
++{
++ struct btrfs_stripe_hash_table *table = info->stripe_hash_table;
++ struct btrfs_raid_bio *rbio;
++ struct btrfs_raid_bio *tmp;
++
++ if (!table)
++ return;
++
++ spin_lock(&table->cache_lock);
++ list_for_each_entry_safe(rbio, tmp, &table->stripe_cache, stripe_cache) {
++ const u64 rbio_start = rbio->bioc->full_stripe_logical;
++ const u64 rbio_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
++
++ if (rbio_start < start + len && start < rbio_start + rbio_len)
++ __remove_rbio_from_cache(rbio);
++ }
++ spin_unlock(&table->cache_lock);
++}
++
+ /*
+ * remove everything in the cache
+ */
+diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
+index b56f9b958d713..be507cceb465d 100644
+--- a/fs/btrfs/raid56.h
++++ b/fs/btrfs/raid56.h
+@@ -290,5 +290,6 @@ 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);
++void btrfs_raid56_uncache_range(struct btrfs_fs_info *info, u64 start, u64 len);
+
+ #endif
+--
+2.47.3
+
+++ /dev/null
-From 3056cb9be26eb4525718fa367091328e9ff9a356 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 04/12] btrfs: raid56: fix use-after-free of rbio in bio end_io
- wakeups
-To: linux-btrfs@vger.kernel.org
-
-The read/write submission rounds in raid56 count in-flight bios in
-rbio->stripes_pending and wait with a bare
-wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0),
-while each bio's end_io does
-"if (atomic_dec_and_test(&stripes_pending)) wake_up(&rbio->io_wait)".
-
-Once the final decrement makes the counter visible as zero, the waiter
-can pass its condition check without consuming the wakeup -- via
-wait_event()'s fast path when all bios complete before the waiter
-arrives, or a condition recheck after an earlier wakeup -- and proceed
-to free the rbio through rbio_orig_end_io(). The end_io context is
-then still inside wake_up() operating on the freed rbio's embedded
-waitqueue lock.
-
-This shows up under sustained raid56 load in KVM guests as recurring
-"pvqspinlock: lock ... has corrupted value 0x0!" warnings from
-__pv_queued_spin_unlock_slowpath with a
-__wake_up <- raid_wait_{read,write}_end_io <- bio_endio call trace:
-paravirt spinlocks detect the unlock of the recycled lock word. KASAN
-reports it as a slab-use-after-free in __wake_up_common or
-do_raw_spin_unlock from the same end_io handlers. On bare metal
-without KASAN the use-after-free is silent and almost always harmless,
-which is how it has survived; it is a plausible match for
-long-standing sporadic crash reports on busy raid5 filesystems.
-
-It reproduces in about 12 seconds in a KVM guest running a KASAN
-kernel, on a degraded raid5 data / raid1 metadata filesystem on four
-2 GiB devices with one missing:
- - 8 parallel O_DIRECT readers of 4K, 16K or 64K at random offsets in
- existing files, so every read of a block on the missing device is a
- reconstruction round;
- - 2 writers rewriting small files with 4K..32K O_DIRECT writes, so
- writes are sub-stripe read-modify-write rounds;
- - the page cache dropped every second.
-With this patch the same load runs for 10 minutes without a warning.
-
-Convert the pair to a completion. wait_for_completion()'s fast path
-takes the completion's own lock, so it cannot return before complete()
-has released it: the completing context is provably finished with the
-rbio before the waiter can free it. A submitter-held bias count keeps
-one completion per submission round even when a round submits zero
-bios or every bio finishes before the submitter starts waiting; the
-scrub path only waits when finish_parity_scrub() actually began a
-round.
-
-Assisted-by: Claude:claude-fable-5
-Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
----
- fs/btrfs/raid56.c | 54 ++++++++++++++++++++++++++++++++++++++---------
- fs/btrfs/raid56.h | 10 ++++++++-
- 2 files changed, 53 insertions(+), 11 deletions(-)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index a8a8004bb14c7..4453a50866b43 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -1019,7 +1019,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
- }
-
- bio_list_init(&rbio->bio_list);
-- init_waitqueue_head(&rbio->io_wait);
-+ init_completion(&rbio->io_done);
- INIT_LIST_HEAD(&rbio->plug_list);
- spin_lock_init(&rbio->bio_list_lock);
- INIT_LIST_HEAD(&rbio->stripe_cache);
-@@ -1606,6 +1606,40 @@ static void verify_bio_data_sectors(struct btrfs_raid_bio *rbio,
- }
- }
-
-+/*
-+ * Begin a submission round of @nr bios whose end_io functions report through
-+ * rbio_dec_io(). stripes_pending gets one extra count on behalf of the
-+ * submitter, dropped by rbio_wait_io(): this guarantees exactly one
-+ * completion per round even when @nr is 0 or every bio finishes before the
-+ * submitter starts waiting.
-+ *
-+ * The completion is what makes the round safe against a use-after-free the
-+ * old bare waitqueue had: once the final bio's decrement made
-+ * stripes_pending visible as zero, the waiter could pass its wait_event()
-+ * condition check and free the rbio while the bio's end_io context was still
-+ * inside wake_up() on the rbio's embedded waitqueue lock. With a
-+ * completion, the waiter cannot return before complete() has released the
-+ * completion's lock, so the completing context is finished with the rbio.
-+ */
-+static void rbio_begin_io(struct btrfs_raid_bio *rbio, unsigned int nr)
-+{
-+ reinit_completion(&rbio->io_done);
-+ atomic_set(&rbio->stripes_pending, nr + 1);
-+}
-+
-+static void rbio_dec_io(struct btrfs_raid_bio *rbio)
-+{
-+ if (atomic_dec_and_test(&rbio->stripes_pending))
-+ complete(&rbio->io_done);
-+}
-+
-+static void rbio_wait_io(struct btrfs_raid_bio *rbio)
-+{
-+ /* Drop the submitter's count from rbio_begin_io(). */
-+ rbio_dec_io(rbio);
-+ wait_for_completion(&rbio->io_done);
-+}
-+
- static void raid_wait_read_end_io(struct bio *bio)
- {
- struct btrfs_raid_bio *rbio = bio->bi_private;
-@@ -1618,8 +1652,7 @@ static void raid_wait_read_end_io(struct bio *bio)
- }
-
- bio_put(bio);
-- if (atomic_dec_and_test(&rbio->stripes_pending))
-- wake_up(&rbio->io_wait);
-+ rbio_dec_io(rbio);
- }
-
- static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
-@@ -1627,7 +1660,7 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
- {
- struct bio *bio;
-
-- atomic_set(&rbio->stripes_pending, bio_list_size(bio_list));
-+ rbio_begin_io(rbio, bio_list_size(bio_list));
- while ((bio = bio_list_pop(bio_list))) {
- bio->bi_end_io = raid_wait_read_end_io;
-
-@@ -1640,7 +1673,7 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
- submit_bio(bio);
- }
-
-- wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0);
-+ rbio_wait_io(rbio);
- }
-
- static int alloc_rbio_data_pages(struct btrfs_raid_bio *rbio)
-@@ -2328,8 +2361,7 @@ static void raid_wait_write_end_io(struct bio *bio)
- if (bio->bi_status)
- rbio_update_error_bitmap(rbio, bio);
- bio_put(bio);
-- if (atomic_dec_and_test(&rbio->stripes_pending))
-- wake_up(&rbio->io_wait);
-+ rbio_dec_io(rbio);
- }
-
- static void submit_write_bios(struct btrfs_raid_bio *rbio,
-@@ -2337,7 +2369,7 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
- {
- struct bio *bio;
-
-- atomic_set(&rbio->stripes_pending, bio_list_size(bio_list));
-+ rbio_begin_io(rbio, bio_list_size(bio_list));
- while ((bio = bio_list_pop(bio_list))) {
- bio->bi_end_io = raid_wait_write_end_io;
-
-@@ -2444,7 +2476,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
- /* We should have at least one bio assembled. */
- ASSERT(bio_list_size(&bio_list));
- submit_write_bios(rbio, &bio_list);
-- wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0);
-+ rbio_wait_io(rbio);
-
- /* We may have more errors than our tolerance during the read. */
- for (sectornr = 0; sectornr < rbio->stripe_nsectors; sectornr++) {
-@@ -2915,7 +2947,9 @@ static void scrub_rbio(struct btrfs_raid_bio *rbio)
- * and writeback the good content.
- */
- ret = finish_parity_scrub(rbio);
-- wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0);
-+ /* A submission round only began if finish_parity_scrub() succeeded. */
-+ if (ret == 0)
-+ rbio_wait_io(rbio);
- for (sector_nr = 0; sector_nr < rbio->stripe_nsectors; sector_nr++) {
- int found_errors;
-
-diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index 8700910b8dc99..b56f9b958d713 100644
---- a/fs/btrfs/raid56.h
-+++ b/fs/btrfs/raid56.h
-@@ -13,6 +13,7 @@
- #include <linux/bio.h>
- #include <linux/refcount.h>
- #include <linux/workqueue.h>
-+#include <linux/completion.h>
- #include "volumes.h"
-
- struct page;
-@@ -173,9 +174,16 @@ struct btrfs_raid_bio {
-
- refcount_t refs;
-
-+ /*
-+ * In-flight bios of the current submission round, plus one bias
-+ * count held by the submitter and dropped when it starts waiting.
-+ * The final decrement completes io_done; a completion (unlike a
-+ * bare waitqueue) guarantees the completing context is finished
-+ * with the rbio before the waiter can return and free it.
-+ */
- atomic_t stripes_pending;
-
-- wait_queue_head_t io_wait;
-+ struct completion io_done;
-
- /* Bitmap to record which horizontal stripe has data */
- unsigned long dbitmap;
---
-2.47.3
-
+++ /dev/null
-From 279096509d09e88990863f44eea845cc5ef898a8 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 05/12] btrfs: propagate a split bio's error when the failing
- split completes last
-To: linux-btrfs@vger.kernel.org
-
-btrfs_bio_end_io() saves the first error of any split bio in the original
-btrfs_bio's ->status, then loads it into ->bio.bi_status when the last
-split completes -- but only if that last completion itself succeeded:
-
- if (atomic_dec_and_test(&bbio->pending_ios)) {
- /* Load split bio's error which might be set above. */
- if (status == BLK_STS_OK)
- bbio->bio.bi_status = READ_ONCE(bbio->status);
-
-The condition assumes that a failing final completion has already stored
-its error in the original bio at the top of the function. That holds only
-when the bio was never split. For a split, "bbio->bio.bi_status = status"
-is applied to the clone, which is then freed and bbio switched to the
-original; the original's bi_status keeps whatever an earlier, successful
-split left in it, and the error never reaches the caller.
-
-The ordering that loses the error is not rare. A read that fails checksum
-verification completes only after read repair has tried every mirror,
-which takes far longer than the healthy splits of the same bio, so the
-failing split completes last essentially every time.
-
-On a degraded raid56 array the result is silent corruption. Reads are
-split per stripe, so for any read of BTRFS_STRIPE_LEN or more, a sector
-whose reconstruction from a torn stripe fails its checksum is returned to
-userspace as zeros with no error -- while btrfs logs the checksum failure
-and increments the device corruption counter. A 4 KiB read of the same
-sector is not split and correctly returns EIO. Profiles that do not split
-at 64 KiB (single, dup, raid1) are unaffected, which is how this has gone
-unnoticed.
-
-Reproducer: on a raid5 filesystem, tear one stripe row's parity (leaving
-the data intact), withhold one data member of that row and mount degraded.
-Reconstructing the missing column then yields wrong bytes for that column
-while every other column still verifies. Reads of 64 KiB or more over the
-affected range return zeros and succeed; 4 KiB reads return EIO.
-
-Load the saved status unconditionally. It is the first error seen by any
-split, including this one, which is the value the caller wants in either
-case.
-
-Fixes: d48e1dea3931 ("btrfs: fix error propagation of split bios")
-CC: stable@vger.kernel.org # 6.6+
-Assisted-by: Claude:claude-opus-5
-Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
----
- fs/btrfs/bio.c | 11 ++++++++---
- 1 file changed, 8 insertions(+), 3 deletions(-)
-
-diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
-index 2c6234f6182f8..b589cac044271 100644
---- a/fs/btrfs/bio.c
-+++ b/fs/btrfs/bio.c
-@@ -127,9 +127,14 @@ void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
- cmpxchg(&bbio->status, BLK_STS_OK, status);
-
- if (atomic_dec_and_test(&bbio->pending_ios)) {
-- /* Load split bio's error which might be set above. */
-- if (status == BLK_STS_OK)
-- bbio->bio.bi_status = READ_ONCE(bbio->status);
-+ /*
-+ * Load the first error recorded above. For a split bio the
-+ * assignment at the top of this function landed on the clone,
-+ * which has already been freed, so the original's bi_status is
-+ * only correct if it is loaded here -- including when this
-+ * last completion is itself the failing one.
-+ */
-+ bbio->bio.bi_status = READ_ONCE(bbio->status);
-
- if (bbio_has_ordered_extent(bbio)) {
- struct btrfs_ordered_extent *ordered = bbio->ordered;
---
-2.47.3
-
--- /dev/null
+From fa66a56a64eb14a9dd9e0f4197f05aa35efb73ed 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/10] btrfs: raid56: verify reconstructed tree blocks
+To: linux-btrfs@vger.kernel.org
+
+Data sectors recovered from parity are checked against the csum tree
+before they are trusted: recover_vertical() calls verify_one_sector() for
+each rebuilt sector, and a mismatch fails the read. Metadata gets none of
+that. fill_data_csums() returns early for anything that is not a data
+block group, so csum_bitmap is NULL, and verify_one_sector() then returns
+success without looking at anything:
+
+ if (!rbio->csum_bitmap || !rbio->csum_buf)
+ return 0;
+
+So a metadata rbio reconstructs a lost column, marks it uptodate having
+verified nothing, and hands it back. A wrong reconstruction is caught
+much later by validate_extent_buffer(), one layer up, after the block has
+already been returned and cached -- and in the raid6 case, where several
+candidate reconstructions exist, raid56 cannot tell which one is right
+because it has no way to check any of them.
+
+A tree block can be verified, just not a sector at a time: its csum lives
+in its own header and covers the whole nodesize block, so the check has to
+wait until every sector of the block has been recovered. Do it after the
+vertical recovery loop rather than inside it. A tree block never straddles
+a column -- nodesize and BTRFS_STRIPE_LEN are both powers of two with
+nodesize <= BTRFS_STRIPE_LEN, and full stripes are stripe-length aligned,
+so each column starts on a nodesize boundary and tree blocks tile it
+exactly.
+
+Only the blocks the caller asked for are checked. Those are known to be
+live tree blocks; the rest of a stripe may be free space, which has no
+header and would fail every test. For the same reason this runs only when
+rebuilding a read: recover_sectors() is also reached from the
+read-modify-write path, where the sectors actually reconstructed are the
+ones read off the surviving columns and any of them may be free space. A
+reconstruction feeding an RMW's parity therefore stays unverified; knowing
+which ranges hold live metadata is not something this layer can do.
+
+Tested with a 3-device raid5 filesystem with raid5 metadata, 3000 files:
+each device in turn missing and corrupted recovers byte-exactly, and with
+two devices corrupted -- where reconstruction necessarily produces a wrong
+block -- raid56 now rejects it itself:
+
+ raid56: reconstructed tree block 40796160 has bytenr 8993213254959039756,
+ cannot be trusted
+
+Scrub's reads are left out: they cover whole stripes, free space
+included, and scrub verifies the sectors that hold extents itself.
+Checked here, a free slot in a rebuilt stripe failed the whole read,
+which inflated the read error counts, made a replace with -r read the
+source after all, and with nodesize equal to sectorsize left unused
+slots of a replace target unwritten.
+
+---
+ fs/btrfs/raid56.c | 185 ++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 185 insertions(+)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 5ec0ec769a0c8..81d6ec1ab1f13 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -1885,6 +1885,187 @@ static void calculate_block_csum_paddrs(struct btrfs_fs_info *fs_info,
+ btrfs_csum_final(&csum, dest);
+ }
+
++/*
++ * Return the memory holding a recovered sector: the bio's pages when we are
++ * rebuilding a read, the rbio's own stripe pages otherwise.
++ */
++static phys_addr_t *recovered_sector_paddrs(struct btrfs_raid_bio *rbio,
++ int stripe_nr, int sector_nr)
++{
++ if (rbio->operation == BTRFS_RBIO_READ_REBUILD)
++ return sector_paddrs_in_rbio(rbio, stripe_nr, sector_nr, 0);
++ return rbio_stripe_paddrs(rbio, stripe_nr, sector_nr);
++}
++
++/*
++ * Verify one reconstructed tree block.
++ *
++ * Data sectors are verified individually against the csum tree, but a tree
++ * block carries its csum in its own header, covering the whole nodesize
++ * block. So metadata cannot be checked a sector at a time: the check has to
++ * wait until every sector of the block has been recovered, which is why this
++ * runs after the vertical recovery loop rather than inside it.
++ *
++ * A tree block never straddles a column. nodesize and the stripe length are
++ * both powers of two with nodesize <= the stripe length, and a full stripe is
++ * stripe-length aligned, so each column begins on a nodesize boundary and
++ * tree blocks tile it exactly.
++ *
++ * @sector_nr is the first sector of the block within the column.
++ */
++static int verify_one_eb(struct btrfs_raid_bio *rbio, int stripe_nr,
++ int sector_nr)
++{
++ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
++ const u32 sectorsize = fs_info->sectorsize;
++ const u32 sectors_per_tree = fs_info->nodesize >> fs_info->sectorsize_bits;
++ const u32 step = min(sectorsize, PAGE_SIZE);
++ const u64 logical = rbio->bioc->full_stripe_logical +
++ (u64)stripe_nr * rbio->bioc->stripe_len +
++ (u64)sector_nr * sectorsize;
++ u8 on_disk_csum[BTRFS_CSUM_SIZE];
++ u8 calculated_csum[BTRFS_CSUM_SIZE];
++ struct btrfs_csum_ctx csum;
++ phys_addr_t *paddrs;
++ void *kaddr;
++ u64 found_bytenr;
++ bool bad_fsid;
++
++ /*
++ * The header lives at the start of the block. Read what we need from
++ * it before walking the rest: a block whose bytenr or fsid do not
++ * match was not reconstructed into what it claims to be, and there is
++ * no point csumming it.
++ */
++ paddrs = recovered_sector_paddrs(rbio, stripe_nr, sector_nr);
++ kaddr = kmap_local_paddr(paddrs[0]);
++ memcpy(on_disk_csum, ((struct btrfs_header *)kaddr)->csum,
++ fs_info->csum_size);
++ found_bytenr = btrfs_stack_header_bytenr((struct btrfs_header *)kaddr);
++ bad_fsid = memcmp(((struct btrfs_header *)kaddr)->fsid,
++ fs_info->fs_devices->metadata_uuid,
++ BTRFS_FSID_SIZE) != 0;
++ kunmap_local(kaddr);
++
++ if (unlikely(found_bytenr != logical)) {
++ btrfs_warn_rl(fs_info,
++"raid56: reconstructed tree block %llu has bytenr %llu, cannot be trusted",
++ logical, found_bytenr);
++ return -EIO;
++ }
++ if (unlikely(bad_fsid)) {
++ btrfs_warn_rl(fs_info,
++"raid56: reconstructed tree block %llu has the wrong fsid, cannot be trusted",
++ logical);
++ return -EIO;
++ }
++
++ btrfs_csum_init(&csum, fs_info->csum_type);
++ for (int i = 0; i < sectors_per_tree; i++) {
++ paddrs = recovered_sector_paddrs(rbio, stripe_nr, sector_nr + i);
++
++ for (int j = 0; j < rbio->sector_nsteps; j++) {
++ kaddr = kmap_local_paddr(paddrs[j]);
++ /* The csum field itself is not covered by the csum. */
++ if (i == 0 && j == 0)
++ btrfs_csum_update(&csum, kaddr + BTRFS_CSUM_SIZE,
++ step - BTRFS_CSUM_SIZE);
++ else
++ btrfs_csum_update(&csum, kaddr, step);
++ kunmap_local(kaddr);
++ }
++ }
++ btrfs_csum_final(&csum, calculated_csum);
++
++ if (unlikely(memcmp(calculated_csum, on_disk_csum, fs_info->csum_size))) {
++ btrfs_warn_rl(fs_info,
++"raid56: reconstructed tree block %llu fails its csum, cannot be trusted",
++ logical);
++ return -EIO;
++ }
++ return 0;
++}
++
++/*
++ * Verify every tree block this rbio was asked to read, once recovery has
++ * filled in the missing columns.
++ *
++ * Only blocks the caller actually requested are checked: a filesystem read
++ * asks for live tree blocks, whereas the rest of a stripe may be free space,
++ * which has no header to verify and would fail every test here. Scrub reads
++ * whole stripes, free space included, and verifies the sectors that hold
++ * extents itself, so its reads are not checked here.
++ *
++ * Without this, a metadata rbio reconstructs a column and marks it uptodate
++ * having checked nothing -- verify_one_sector() returns success immediately
++ * when there is no csum_bitmap, and metadata never has one (see
++ * fill_data_csums()). A wrong reconstruction would then be handed back to
++ * the caller, and cached, for validate_extent_buffer() to reject much later.
++ */
++static int verify_recovered_ebs(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;
++
++ /*
++ * Data has its own per-sector verification. A mixed block group has
++ * neither: its sectors get no csums (fill_data_csums() skips mixed
++ * groups) and its contents may be file data rather than tree blocks,
++ * so there is nothing here to check either.
++ */
++ if (rbio->bioc->map_type & BTRFS_BLOCK_GROUP_DATA)
++ return 0;
++
++ /*
++ * Only when rebuilding a read. recover_sectors() is also reached from
++ * the read-modify-write path, and there the bio list covers the blocks
++ * being written -- already-verified memory -- while the sectors that
++ * were actually reconstructed are the ones read off the other columns.
++ * Those cannot be checked: any of them may be free space rather than a
++ * live tree block, and free space has no header to verify. Knowing
++ * which ranges hold live metadata is exactly what this layer lacks,
++ * so a reconstruction feeding an RMW's parity stays unverified.
++ */
++ if (rbio->operation != BTRFS_RBIO_READ_REBUILD)
++ return 0;
++
++ /*
++ * A scrub read covers free space too, and scrub verifies what it read
++ * itself. A READ_REBUILD rbio is never merged (rbio_can_merge()), so
++ * its one bio says whose read it is.
++ */
++ if (!bio_list_empty(&rbio->bio_list) &&
++ btrfs_bio(bio_list_peek(&rbio->bio_list))->is_scrub)
++ return 0;
++
++ for (int stripe_nr = 0; stripe_nr < rbio->nr_data; stripe_nr++) {
++ for (int sector_nr = 0;
++ sector_nr + sectors_per_tree <= rbio->stripe_nsectors;
++ sector_nr += sectors_per_tree) {
++ bool requested = true;
++ int ret;
++
++ for (int i = 0; i < sectors_per_tree; i++) {
++ const int index = rbio_sector_index(rbio, stripe_nr,
++ sector_nr + i);
++
++ if (rbio->bio_paddrs[index * rbio->sector_nsteps] ==
++ INVALID_PADDR) {
++ requested = false;
++ break;
++ }
++ }
++ if (!requested)
++ continue;
++
++ ret = verify_one_eb(rbio, stripe_nr, sector_nr);
++ if (ret < 0)
++ return ret;
++ }
++ }
++ return 0;
++}
++
+ static int verify_one_sector(struct btrfs_raid_bio *rbio,
+ int stripe_nr, int sector_nr)
+ {
+@@ -2120,6 +2301,10 @@ static int recover_sectors(struct btrfs_raid_bio *rbio)
+ break;
+ }
+
++ /* Metadata is verified per tree block, once every sector is back. */
++ if (ret == 0)
++ ret = verify_recovered_ebs(rbio);
++
+ out:
+ kfree(pointers);
+ kfree(unmap_array);
+--
+2.47.3
+
+++ /dev/null
-From 01b3569be796c1ca3f9f300c0cbe6c697ff76685 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 06/12] btrfs: raid56: drop cached rbios when their stripes'
- extents are freed
-To: linux-btrfs@vger.kernel.org
-
-A cached rbio keeps an in-memory copy of its full stripe's data
-sectors so that a later sub-stripe write can steal the pages (see
-steal_rbio()) and skip the RMW read. That is only safe while the
-cache and the disk agree. Nothing invalidates cache entries when the
-stripe's extents are freed, so an entry can outlive the data it
-describes: the space is reallocated, a sub-stripe write to the reused
-stripe steals the stale pages, and parity is generated from the
-cache's memory of the stripe's previous life instead of from disk.
-
-If the on-disk content diverged from that memory in the meantime, the
-result is silent, latent damage. The divergence does not require a
-second write: a device error that corrupts a column holding only
-freed data is invisible (no live extent, no csum to fail, nothing for
-scrub to check), but the stale cached copy of that column predates
-the corruption. The poisoned write then produces parity consistent
-with the cache's memory and inconsistent with the actual on-disk
-column. Every read of the live data still passes csum and scrub
-reports nothing, so the loss surfaces only when a device failure
-forces reconstruction -- which XORs the real on-disk garbage against
-parity that remembers different bytes, and hands back trash.
-
-This was found and proven byte-exactly on a raid5 test array: a
-stripe's parity solved uniquely as the XOR of fresh data with the
-PRE-corruption content of a free-space column -- bytes that existed
-nowhere on disk at write time and could only have come from the rbio
-cache. The resulting single-column loss was undetectable by scrub
-and unrecoverable by reconstruction.
-
-Drop cache entries overlapping freed extents at unpin time, when the
-space returns to circulation. The walk is gated on raid56 block
-groups, so filesystems without raid56 never touch it, and the LRU
-list is bounded (RBIO_CACHE_SIZE entries).
-
-The cost of dropping entries was measured on an instrumented stock
-kernel that marks affected entries instead of dropping them, and
-counts a reintroduced RMW full-stripe read whenever a read-skip was
-only possible because of a marked entry. In a worst-case free-heavy
-small-file churn on a 5-device raid5 array with raid5 metadata --
-conditions chosen to flatter the cache, and it delivers, with 87% of
-sub-stripe RMWs skipping their read -- only 1% of those skips (64 of
-6430) were enabled by entries this patch drops, costing 0.04-0.12
-MB/s of extra reads against the workload's own 0.3-0.7 MB/s of
-writes. 93% of the entries the patch drops were evicted without
-ever being stolen again.
-
-Assisted-by: Claude:claude-fable-5
----
- fs/btrfs/extent-tree.c | 10 ++++++++++
- fs/btrfs/raid56.c | 37 +++++++++++++++++++++++++++++++++++++
- fs/btrfs/raid56.h | 1 +
- 3 files changed, 48 insertions(+)
-
-diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
-index 9b0a5c6b96f3c..e9248e52d1dce 100644
---- a/fs/btrfs/extent-tree.c
-+++ b/fs/btrfs/extent-tree.c
-@@ -2868,6 +2868,16 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
- if (return_free_space)
- btrfs_add_free_space(cache, start, len);
-
-+ /*
-+ * The rbio stripe cache may still remember this range's
-+ * pre-free contents; a later sub-stripe write into the
-+ * reused stripes would steal those pages and generate
-+ * parity from them. Drop the stale entries now that the
-+ * extents are gone.
-+ */
-+ if (cache->flags & BTRFS_BLOCK_GROUP_RAID56_MASK)
-+ btrfs_raid56_uncache_range(fs_info, start, len);
-+
- start += len;
- total_unpinned += len;
- space_info = cache->space_info;
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 4453a50866b43..5ec0ec769a0c8 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -464,6 +464,43 @@ static void remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
- spin_unlock(&table->cache_lock);
- }
-
-+/*
-+ * Drop cached rbios whose full stripes overlap [start, start + len).
-+ *
-+ * Called when extents in that range are freed. A cached rbio holds an
-+ * in-memory copy of its stripe's data sectors; once the extents are gone
-+ * the space can be reallocated, and a later sub-stripe write to the same
-+ * stripe would steal the cached pages (see steal_rbio()) and compute
-+ * parity from the cache's memory of the stripe's previous life instead
-+ * of reading the disk. If the on-disk content diverged from that memory
-+ * in the meantime -- for example a device error corrupted a column that
-+ * no longer had live data, so nothing noticed -- the write produces
-+ * parity that disagrees with the on-disk columns, and the stripe is
-+ * latently unreconstructible: every read of the live data passes csum,
-+ * scrub sees nothing wrong, and the loss only surfaces when a device
-+ * failure forces reconstruction. Freed extents' cache entries have no
-+ * value to keep: drop them.
-+ */
-+void btrfs_raid56_uncache_range(struct btrfs_fs_info *info, u64 start, u64 len)
-+{
-+ struct btrfs_stripe_hash_table *table = info->stripe_hash_table;
-+ struct btrfs_raid_bio *rbio;
-+ struct btrfs_raid_bio *tmp;
-+
-+ if (!table)
-+ return;
-+
-+ spin_lock(&table->cache_lock);
-+ list_for_each_entry_safe(rbio, tmp, &table->stripe_cache, stripe_cache) {
-+ const u64 rbio_start = rbio->bioc->full_stripe_logical;
-+ const u64 rbio_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
-+
-+ if (rbio_start < start + len && start < rbio_start + rbio_len)
-+ __remove_rbio_from_cache(rbio);
-+ }
-+ spin_unlock(&table->cache_lock);
-+}
-+
- /*
- * remove everything in the cache
- */
-diff --git a/fs/btrfs/raid56.h b/fs/btrfs/raid56.h
-index b56f9b958d713..be507cceb465d 100644
---- a/fs/btrfs/raid56.h
-+++ b/fs/btrfs/raid56.h
-@@ -290,5 +290,6 @@ 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);
-+void btrfs_raid56_uncache_range(struct btrfs_fs_info *info, u64 start, u64 len);
-
- #endif
---
-2.47.3
-
--- /dev/null
+From b2cd9c85c248e6a127a62319e955f3a7bd40cec7 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/10] btrfs: raid56: keep a reference on a stolen cached rbio
+ until it is dropped
+To: linux-btrfs@vger.kernel.org
+
+lock_stripe_add() steals the pages of a cached rbio for the same full
+stripe, drops the rbio's hash-list reference under the bucket lock, and
+only after releasing that lock calls remove_rbio_from_cache() on it.
+Between those two steps the rbio is held by nothing but the cache
+reference, and anyone who removes it from the cache in that window --
+the cache shrink in cache_rbio(), or btrfs_raid56_uncache_range() when
+the stripe's extents are freed -- frees it. remove_rbio_from_cache()
+then dereferences a freed rbio:
+
+ BUG: kernel NULL pointer dereference, address: 0000000000000008
+ Workqueue: btrfs-rmw rmw_rbio_work
+ RIP: 0010:__remove_rbio_from_cache+0x33/0x180
+ remove_rbio_from_cache+0x41/0x60
+ lock_stripe_add+0xfc/0x460
+ rmw_rbio_work+0x35/0x400
+
+The oops leaves the cache and bucket locks held, and every other RMW
+worker and the transaction thread soft-lock behind them. Seen after
+8h of the device-corruption acceptance suite on 6.18, where freeing of
+extents during read errors made the uncache path frequent; the window
+exists with the plain cache shrink as well.
+
+Keep the hash-list reference across the steal and drop it after the
+cache removal, so a concurrent remover can clear the cache bit and drop
+its own reference but never free the rbio under our feet.
+
+---
+ fs/btrfs/raid56.c | 12 ++++++++++--
+ 1 file changed, 10 insertions(+), 2 deletions(-)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 81d6ec1ab1f13..44877bc3f51b7 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -756,8 +756,14 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
+ list_empty(&cur->plug_list) &&
+ test_bit(RBIO_CACHE_BIT, &cur->flags) &&
+ !test_bit(RBIO_RMW_LOCKED_BIT, &cur->flags)) {
++ /*
++ * Keep the hash-list reference: after the bucket lock
++ * is released nothing but the cache holds cur, and a
++ * concurrent cache removal would free it before the
++ * remove_rbio_from_cache() below runs. The reference
++ * is dropped there, after the cache is done with it.
++ */
+ list_del_init(&cur->hash_list);
+- refcount_dec(&cur->refs);
+
+ steal_rbio(cur, rbio);
+ cache_drop = cur;
+@@ -805,8 +811,10 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
+ list_add(&rbio->hash_list, &h->hash_list);
+ out:
+ spin_unlock(&h->lock);
+- if (cache_drop)
++ if (cache_drop) {
+ remove_rbio_from_cache(cache_drop);
++ free_raid_bio(cache_drop);
++ }
+ if (freeit)
+ free_raid_bio(freeit);
+ return ret;
+--
+2.47.3
+
--- /dev/null
+From 5ee2db49d71535edc02572367ede40092ab9509f 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/10] btrfs: raid56: do not unhash a cached rbio that has
+ rbios plugged on it
+To: linux-btrfs@vger.kernel.org
+
+unlock_stripe() caches the finished rbio with cache_rbio() before it
+retakes the bucket and bio_list locks, and RBIO_RMW_LOCKED_BIT is still
+set at that point. A lock_stripe_add() for the same full stripe that
+runs in that window finds a cached rbio it can neither steal (still RMW
+locked) nor merge with (cached) and plugs itself onto it, which is
+correct: unlock_stripe() then sees the plug list and hands the stripe
+lock on to the plugged rbio.
+
+But if the rbio is removed from the cache in that same window --
+btrfs_raid56_uncache_range() from the commit's unpin, or the cache's own
+shrink in cache_rbio() -- __remove_rbio_from_cache() finds an empty
+bio_list, takes the rbio off the hash list, drops the hash reference and
+hits BUG_ON(!list_empty(&rbio->plug_list)). Seen on a degraded raid5
+under fsstress: the transaction kthread died in that BUG_ON with the
+bucket lock held and the rmw workers spun on it until the machine was
+reset.
+
+An rbio with rbios plugged on it is busy, like one with bios: leave it
+on the hash list and let unlock_stripe() hand the lock on; drop only the
+cache's reference here.
+
+---
+ fs/btrfs/raid56.c | 14 ++++++++++++--
+ 1 file changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 44877bc3f51b7..390ad69a64e0a 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -431,11 +431,21 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
+ * the rbio from the hash_table, and drop
+ * the corresponding ref
+ */
+- if (bio_list_empty(&rbio->bio_list)) {
++ /*
++ * An rbio with no bios is idle only if nothing is plugged on
++ * it either. unlock_stripe() caches the rbio before it retakes
++ * the locks, with RBIO_RMW_LOCKED_BIT still set, so a
++ * lock_stripe_add() in that window can neither steal the pages
++ * nor merge and plugs onto the cached rbio instead. That rbio
++ * is still the stripe's lock owner and unlock_stripe() hands
++ * the lock on to the plugged one; only the cache's reference
++ * goes away here.
++ */
++ if (bio_list_empty(&rbio->bio_list) &&
++ list_empty(&rbio->plug_list)) {
+ if (!list_empty(&rbio->hash_list)) {
+ list_del_init(&rbio->hash_list);
+ refcount_dec(&rbio->refs);
+- ASSERT(list_empty(&rbio->plug_list));
+ }
+ }
+ }
+--
+2.47.3
+
+++ /dev/null
-From d603a281c880d6a7ab5c8dcd7eb2b3054a6b8f63 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 07/12] btrfs: raid56: verify reconstructed tree blocks
-To: linux-btrfs@vger.kernel.org
-
-Data sectors recovered from parity are checked against the csum tree
-before they are trusted: recover_vertical() calls verify_one_sector() for
-each rebuilt sector, and a mismatch fails the read. Metadata gets none of
-that. fill_data_csums() returns early for anything that is not a data
-block group, so csum_bitmap is NULL, and verify_one_sector() then returns
-success without looking at anything:
-
- if (!rbio->csum_bitmap || !rbio->csum_buf)
- return 0;
-
-So a metadata rbio reconstructs a lost column, marks it uptodate having
-verified nothing, and hands it back. A wrong reconstruction is caught
-much later by validate_extent_buffer(), one layer up, after the block has
-already been returned and cached -- and in the raid6 case, where several
-candidate reconstructions exist, raid56 cannot tell which one is right
-because it has no way to check any of them.
-
-A tree block can be verified, just not a sector at a time: its csum lives
-in its own header and covers the whole nodesize block, so the check has to
-wait until every sector of the block has been recovered. Do it after the
-vertical recovery loop rather than inside it. A tree block never straddles
-a column -- nodesize and BTRFS_STRIPE_LEN are both powers of two with
-nodesize <= BTRFS_STRIPE_LEN, and full stripes are stripe-length aligned,
-so each column starts on a nodesize boundary and tree blocks tile it
-exactly.
-
-Only the blocks the caller asked for are checked. Those are known to be
-live tree blocks; the rest of a stripe may be free space, which has no
-header and would fail every test. For the same reason this runs only when
-rebuilding a read: recover_sectors() is also reached from the
-read-modify-write path, where the sectors actually reconstructed are the
-ones read off the surviving columns and any of them may be free space. A
-reconstruction feeding an RMW's parity therefore stays unverified; knowing
-which ranges hold live metadata is not something this layer can do.
-
-Tested with a 3-device raid5 filesystem with raid5 metadata, 3000 files:
-each device in turn missing and corrupted recovers byte-exactly, and with
-two devices corrupted -- where reconstruction necessarily produces a wrong
-block -- raid56 now rejects it itself:
-
- raid56: reconstructed tree block 40796160 has bytenr 8993213254959039756,
- cannot be trusted
-
-Scrub's reads are left out: they cover whole stripes, free space
-included, and scrub verifies the sectors that hold extents itself.
-Checked here, a free slot in a rebuilt stripe failed the whole read,
-which inflated the read error counts, made a replace with -r read the
-source after all, and with nodesize equal to sectorsize left unused
-slots of a replace target unwritten.
-
-Assisted-by: Claude:claude-fable-5
----
- fs/btrfs/raid56.c | 185 ++++++++++++++++++++++++++++++++++++++++++++++
- 1 file changed, 185 insertions(+)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 5ec0ec769a0c8..81d6ec1ab1f13 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -1885,6 +1885,187 @@ static void calculate_block_csum_paddrs(struct btrfs_fs_info *fs_info,
- btrfs_csum_final(&csum, dest);
- }
-
-+/*
-+ * Return the memory holding a recovered sector: the bio's pages when we are
-+ * rebuilding a read, the rbio's own stripe pages otherwise.
-+ */
-+static phys_addr_t *recovered_sector_paddrs(struct btrfs_raid_bio *rbio,
-+ int stripe_nr, int sector_nr)
-+{
-+ if (rbio->operation == BTRFS_RBIO_READ_REBUILD)
-+ return sector_paddrs_in_rbio(rbio, stripe_nr, sector_nr, 0);
-+ return rbio_stripe_paddrs(rbio, stripe_nr, sector_nr);
-+}
-+
-+/*
-+ * Verify one reconstructed tree block.
-+ *
-+ * Data sectors are verified individually against the csum tree, but a tree
-+ * block carries its csum in its own header, covering the whole nodesize
-+ * block. So metadata cannot be checked a sector at a time: the check has to
-+ * wait until every sector of the block has been recovered, which is why this
-+ * runs after the vertical recovery loop rather than inside it.
-+ *
-+ * A tree block never straddles a column. nodesize and the stripe length are
-+ * both powers of two with nodesize <= the stripe length, and a full stripe is
-+ * stripe-length aligned, so each column begins on a nodesize boundary and
-+ * tree blocks tile it exactly.
-+ *
-+ * @sector_nr is the first sector of the block within the column.
-+ */
-+static int verify_one_eb(struct btrfs_raid_bio *rbio, int stripe_nr,
-+ int sector_nr)
-+{
-+ struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
-+ const u32 sectorsize = fs_info->sectorsize;
-+ const u32 sectors_per_tree = fs_info->nodesize >> fs_info->sectorsize_bits;
-+ const u32 step = min(sectorsize, PAGE_SIZE);
-+ const u64 logical = rbio->bioc->full_stripe_logical +
-+ (u64)stripe_nr * rbio->bioc->stripe_len +
-+ (u64)sector_nr * sectorsize;
-+ u8 on_disk_csum[BTRFS_CSUM_SIZE];
-+ u8 calculated_csum[BTRFS_CSUM_SIZE];
-+ struct btrfs_csum_ctx csum;
-+ phys_addr_t *paddrs;
-+ void *kaddr;
-+ u64 found_bytenr;
-+ bool bad_fsid;
-+
-+ /*
-+ * The header lives at the start of the block. Read what we need from
-+ * it before walking the rest: a block whose bytenr or fsid do not
-+ * match was not reconstructed into what it claims to be, and there is
-+ * no point csumming it.
-+ */
-+ paddrs = recovered_sector_paddrs(rbio, stripe_nr, sector_nr);
-+ kaddr = kmap_local_paddr(paddrs[0]);
-+ memcpy(on_disk_csum, ((struct btrfs_header *)kaddr)->csum,
-+ fs_info->csum_size);
-+ found_bytenr = btrfs_stack_header_bytenr((struct btrfs_header *)kaddr);
-+ bad_fsid = memcmp(((struct btrfs_header *)kaddr)->fsid,
-+ fs_info->fs_devices->metadata_uuid,
-+ BTRFS_FSID_SIZE) != 0;
-+ kunmap_local(kaddr);
-+
-+ if (unlikely(found_bytenr != logical)) {
-+ btrfs_warn_rl(fs_info,
-+"raid56: reconstructed tree block %llu has bytenr %llu, cannot be trusted",
-+ logical, found_bytenr);
-+ return -EIO;
-+ }
-+ if (unlikely(bad_fsid)) {
-+ btrfs_warn_rl(fs_info,
-+"raid56: reconstructed tree block %llu has the wrong fsid, cannot be trusted",
-+ logical);
-+ return -EIO;
-+ }
-+
-+ btrfs_csum_init(&csum, fs_info->csum_type);
-+ for (int i = 0; i < sectors_per_tree; i++) {
-+ paddrs = recovered_sector_paddrs(rbio, stripe_nr, sector_nr + i);
-+
-+ for (int j = 0; j < rbio->sector_nsteps; j++) {
-+ kaddr = kmap_local_paddr(paddrs[j]);
-+ /* The csum field itself is not covered by the csum. */
-+ if (i == 0 && j == 0)
-+ btrfs_csum_update(&csum, kaddr + BTRFS_CSUM_SIZE,
-+ step - BTRFS_CSUM_SIZE);
-+ else
-+ btrfs_csum_update(&csum, kaddr, step);
-+ kunmap_local(kaddr);
-+ }
-+ }
-+ btrfs_csum_final(&csum, calculated_csum);
-+
-+ if (unlikely(memcmp(calculated_csum, on_disk_csum, fs_info->csum_size))) {
-+ btrfs_warn_rl(fs_info,
-+"raid56: reconstructed tree block %llu fails its csum, cannot be trusted",
-+ logical);
-+ return -EIO;
-+ }
-+ return 0;
-+}
-+
-+/*
-+ * Verify every tree block this rbio was asked to read, once recovery has
-+ * filled in the missing columns.
-+ *
-+ * Only blocks the caller actually requested are checked: a filesystem read
-+ * asks for live tree blocks, whereas the rest of a stripe may be free space,
-+ * which has no header to verify and would fail every test here. Scrub reads
-+ * whole stripes, free space included, and verifies the sectors that hold
-+ * extents itself, so its reads are not checked here.
-+ *
-+ * Without this, a metadata rbio reconstructs a column and marks it uptodate
-+ * having checked nothing -- verify_one_sector() returns success immediately
-+ * when there is no csum_bitmap, and metadata never has one (see
-+ * fill_data_csums()). A wrong reconstruction would then be handed back to
-+ * the caller, and cached, for validate_extent_buffer() to reject much later.
-+ */
-+static int verify_recovered_ebs(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;
-+
-+ /*
-+ * Data has its own per-sector verification. A mixed block group has
-+ * neither: its sectors get no csums (fill_data_csums() skips mixed
-+ * groups) and its contents may be file data rather than tree blocks,
-+ * so there is nothing here to check either.
-+ */
-+ if (rbio->bioc->map_type & BTRFS_BLOCK_GROUP_DATA)
-+ return 0;
-+
-+ /*
-+ * Only when rebuilding a read. recover_sectors() is also reached from
-+ * the read-modify-write path, and there the bio list covers the blocks
-+ * being written -- already-verified memory -- while the sectors that
-+ * were actually reconstructed are the ones read off the other columns.
-+ * Those cannot be checked: any of them may be free space rather than a
-+ * live tree block, and free space has no header to verify. Knowing
-+ * which ranges hold live metadata is exactly what this layer lacks,
-+ * so a reconstruction feeding an RMW's parity stays unverified.
-+ */
-+ if (rbio->operation != BTRFS_RBIO_READ_REBUILD)
-+ return 0;
-+
-+ /*
-+ * A scrub read covers free space too, and scrub verifies what it read
-+ * itself. A READ_REBUILD rbio is never merged (rbio_can_merge()), so
-+ * its one bio says whose read it is.
-+ */
-+ if (!bio_list_empty(&rbio->bio_list) &&
-+ btrfs_bio(bio_list_peek(&rbio->bio_list))->is_scrub)
-+ return 0;
-+
-+ for (int stripe_nr = 0; stripe_nr < rbio->nr_data; stripe_nr++) {
-+ for (int sector_nr = 0;
-+ sector_nr + sectors_per_tree <= rbio->stripe_nsectors;
-+ sector_nr += sectors_per_tree) {
-+ bool requested = true;
-+ int ret;
-+
-+ for (int i = 0; i < sectors_per_tree; i++) {
-+ const int index = rbio_sector_index(rbio, stripe_nr,
-+ sector_nr + i);
-+
-+ if (rbio->bio_paddrs[index * rbio->sector_nsteps] ==
-+ INVALID_PADDR) {
-+ requested = false;
-+ break;
-+ }
-+ }
-+ if (!requested)
-+ continue;
-+
-+ ret = verify_one_eb(rbio, stripe_nr, sector_nr);
-+ if (ret < 0)
-+ return ret;
-+ }
-+ }
-+ return 0;
-+}
-+
- static int verify_one_sector(struct btrfs_raid_bio *rbio,
- int stripe_nr, int sector_nr)
- {
-@@ -2120,6 +2301,10 @@ static int recover_sectors(struct btrfs_raid_bio *rbio)
- break;
- }
-
-+ /* Metadata is verified per tree block, once every sector is back. */
-+ if (ret == 0)
-+ ret = verify_recovered_ebs(rbio);
-+
- out:
- kfree(pointers);
- kfree(unmap_array);
---
-2.47.3
-
+++ /dev/null
-From 4f6c6b2daa562025c2d9e01e76154a4a49a0498c 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 08/12] btrfs: raid56: keep a reference on a stolen cached rbio
- until it is dropped
-To: linux-btrfs@vger.kernel.org
-
-lock_stripe_add() steals the pages of a cached rbio for the same full
-stripe, drops the rbio's hash-list reference under the bucket lock, and
-only after releasing that lock calls remove_rbio_from_cache() on it.
-Between those two steps the rbio is held by nothing but the cache
-reference, and anyone who removes it from the cache in that window --
-the cache shrink in cache_rbio(), or btrfs_raid56_uncache_range() when
-the stripe's extents are freed -- frees it. remove_rbio_from_cache()
-then dereferences a freed rbio:
-
- BUG: kernel NULL pointer dereference, address: 0000000000000008
- Workqueue: btrfs-rmw rmw_rbio_work
- RIP: 0010:__remove_rbio_from_cache+0x33/0x180
- remove_rbio_from_cache+0x41/0x60
- lock_stripe_add+0xfc/0x460
- rmw_rbio_work+0x35/0x400
-
-The oops leaves the cache and bucket locks held, and every other RMW
-worker and the transaction thread soft-lock behind them. Seen after
-8h of the device-corruption acceptance suite on 6.18, where freeing of
-extents during read errors made the uncache path frequent; the window
-exists with the plain cache shrink as well.
-
-Keep the hash-list reference across the steal and drop it after the
-cache removal, so a concurrent remover can clear the cache bit and drop
-its own reference but never free the rbio under our feet.
-
-Assisted-by: Claude:claude-opus-4-8
----
- fs/btrfs/raid56.c | 12 ++++++++++--
- 1 file changed, 10 insertions(+), 2 deletions(-)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 81d6ec1ab1f13..44877bc3f51b7 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -756,8 +756,14 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
- list_empty(&cur->plug_list) &&
- test_bit(RBIO_CACHE_BIT, &cur->flags) &&
- !test_bit(RBIO_RMW_LOCKED_BIT, &cur->flags)) {
-+ /*
-+ * Keep the hash-list reference: after the bucket lock
-+ * is released nothing but the cache holds cur, and a
-+ * concurrent cache removal would free it before the
-+ * remove_rbio_from_cache() below runs. The reference
-+ * is dropped there, after the cache is done with it.
-+ */
- list_del_init(&cur->hash_list);
-- refcount_dec(&cur->refs);
-
- steal_rbio(cur, rbio);
- cache_drop = cur;
-@@ -805,8 +811,10 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
- list_add(&rbio->hash_list, &h->hash_list);
- out:
- spin_unlock(&h->lock);
-- if (cache_drop)
-+ if (cache_drop) {
- remove_rbio_from_cache(cache_drop);
-+ free_raid_bio(cache_drop);
-+ }
- if (freeit)
- free_raid_bio(freeit);
- return ret;
---
-2.47.3
-
--- /dev/null
+From 1b805ffcffe8c738780a287e7ed786a0d78d62ba 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 08/10] btrfs: raid56: rebuild from Q when a sector rebuilt
+ from P fails its csum
+To: linux-btrfs@vger.kernel.org
+
+A sub-stripe write on RAID6 reads the whole full stripe and verifies its
+data sectors against their csums. A sector that does not match is marked
+failed, and recover_vertical() rebuilds it. With one failed sector in a
+vertical stripe it rebuilds from P, verifies the result, and fails the
+whole write with -EIO if the rebuild does not match either.
+
+P has no csum, so a stale P is not seen as a failure. A write that failed
+on the member holding a data strip and on the member holding P, but
+completed within the profile's tolerance, leaves exactly that: the data
+strip and P stale, and only Q matching what was written. Every later
+sub-stripe write into that full stripe then fails with -EIO. The
+allocator hands the same free space out again, so the next write there
+fails the same way. The same happens on a degraded filesystem when the
+member holding the data strip is missing and P is stale.
+
+Normal reads of the stale data succeed because read repair walks the
+RAID6 mirrors: mirror 2 rebuilds from P, mirror 3 also treats P as failed
+and rebuilds from Q, and each later mirror treats one more data stripe as
+failed (set_rbio_raid6_extra_error()). Scrub repairs it too. The RMW
+path only tries the first of these.
+
+When the one failed data sector of a RAID6 vertical stripe, rebuilt from
+P, does not verify, rebuild it again treating one more stripe as failed,
+in read repair's order: P (a rebuild from Q), then each other data stripe
+(a rebuild from P and Q, which covers a stale data sector that has no
+csum). Use the first rebuild whose data sectors verify. Each try writes
+its rebuild into the extra stripe's sector, so save that sector and put
+it back before the next try.
+
+Only an RMW verifies rebuilt data sectors here (rbio->csum_bitmap is only
+filled there), so read rebuild and parity scrub do not change.
+
+raid6-rmw-stale-parity-test.sh (raid56-wh-harness) makes a data strip
+and P of a full stripe holding csummed data stale, then writes into the
+rest of that stripe. Without this patch the write fails with -EIO; with
+it the write succeeds, the new parity matches the written data, and
+every file reads back, also with members missing. The arms with a stale
+data strip and P where the data member is missing, and with a stale
+csummed data strip plus a stale strip of a nodatasum file, fail the same
+way without the patch and pass with it. The arms with a stale data
+strip and Q, and with two stale csummed data strips, pass either way.
+
+Fixes: 7a3150723061 ("btrfs: raid56: do data csum verification during RMW cycle")
+---
+ fs/btrfs/raid56.c | 115 ++++++++++++++++++++++++++++++++++++++--------
+ 1 file changed, 95 insertions(+), 20 deletions(-)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index 390ad69a64e0a..a4aeb8c385869 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -2230,6 +2230,94 @@ static void recover_vertical_step(struct btrfs_raid_bio *rbio,
+ kunmap_local(unmap_array[stripe_nr]);
+ }
+
++/*
++ * Rebuild the vertical stripe @sector_nr treating @faila and @failb as the
++ * failed stripes (@failb < 0 for one), then verify the rebuilt data sectors
++ * against their csums and mark them uptodate.
++ */
++static int recover_vertical_try(struct btrfs_raid_bio *rbio, int sector_nr,
++ int faila, int failb,
++ void **pointers, void **unmap_array)
++{
++ int ret;
++
++ for (int i = 0; i < rbio->sector_nsteps; i++)
++ recover_vertical_step(rbio, sector_nr, i, faila, failb,
++ pointers, unmap_array);
++ ret = verify_one_sector(rbio, faila, sector_nr);
++ if (ret < 0)
++ return ret;
++ if (failb >= 0) {
++ ret = verify_one_sector(rbio, failb, sector_nr);
++ if (ret < 0)
++ return ret;
++ }
++
++ set_bit(rbio_sector_index(rbio, faila, sector_nr),
++ rbio->stripe_uptodate_bitmap);
++ if (failb >= 0)
++ set_bit(rbio_sector_index(rbio, failb, sector_nr),
++ rbio->stripe_uptodate_bitmap);
++ return 0;
++}
++
++static void copy_vertical_sector(struct btrfs_raid_bio *rbio, int stripe_nr,
++ int sector_nr, void *buf, bool to_buf)
++{
++ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
++ phys_addr_t *paddrs = recovered_sector_paddrs(rbio, stripe_nr, sector_nr);
++
++ for (int i = 0; i < rbio->sector_nsteps; i++) {
++ void *kaddr = kmap_local_paddr(paddrs[i]);
++
++ if (to_buf)
++ memcpy(buf + i * step, kaddr, step);
++ else
++ memcpy(kaddr, buf + i * step, step);
++ kunmap_local(kaddr);
++ }
++}
++
++/*
++ * A single failed data sector of a RAID6 vertical stripe was rebuilt from P,
++ * and the result does not match its csum. Nothing verifies P, nor a data
++ * sector without a csum, so a stale one of those is only found here. Like
++ * read repair (see set_rbio_raid6_extra_error()), treat one more stripe as
++ * failed and rebuild again: first P, which rebuilds from Q, then each other
++ * data stripe, which rebuilds from P and Q.
++ *
++ * Each try overwrites the extra stripe's sector with its own rebuild, so put
++ * the original back before the next one.
++ */
++static int recover_vertical_retry(struct btrfs_raid_bio *rbio, int sector_nr,
++ int faila, void **pointers, void **unmap_array)
++{
++ void *saved;
++ int ret = -EIO;
++
++ saved = kmalloc(rbio->bioc->fs_info->sectorsize, GFP_NOFS);
++ if (!saved)
++ return -ENOMEM;
++
++ for (int extra = rbio->nr_data; extra >= 0; extra--) {
++ if (extra == faila)
++ continue;
++
++ copy_vertical_sector(rbio, extra, sector_nr, saved, true);
++ ret = recover_vertical_try(rbio, sector_nr, min(faila, extra),
++ max(faila, extra), pointers,
++ unmap_array);
++ if (ret == 0) {
++ set_bit(rbio_sector_index(rbio, extra, sector_nr),
++ rbio->error_bitmap);
++ break;
++ }
++ copy_vertical_sector(rbio, extra, sector_nr, saved, false);
++ }
++ kfree(saved);
++ return ret;
++}
++
+ /*
+ * Recover a vertical stripe specified by @sector_nr.
+ * @*pointers are the pre-allocated pointers by the caller, so we don't
+@@ -2241,7 +2329,7 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
+ int found_errors;
+ int faila;
+ int failb;
+- int ret = 0;
++ int ret;
+
+ /*
+ * Now we just use bitmap to mark the horizontal stripes in
+@@ -2263,25 +2351,12 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
+ if (unlikely(found_errors > rbio->bioc->max_errors))
+ return -EIO;
+
+- for (int i = 0; i < rbio->sector_nsteps; i++)
+- recover_vertical_step(rbio, sector_nr, i, faila, failb,
+- pointers, unmap_array);
+- if (faila >= 0) {
+- ret = verify_one_sector(rbio, faila, sector_nr);
+- if (ret < 0)
+- return ret;
+-
+- set_bit(rbio_sector_index(rbio, faila, sector_nr),
+- rbio->stripe_uptodate_bitmap);
+- }
+- if (failb >= 0) {
+- ret = verify_one_sector(rbio, failb, sector_nr);
+- if (ret < 0)
+- return ret;
+-
+- set_bit(rbio_sector_index(rbio, failb, sector_nr),
+- rbio->stripe_uptodate_bitmap);
+- }
++ ret = recover_vertical_try(rbio, sector_nr, faila, failb, pointers,
++ unmap_array);
++ if (ret == -EIO && found_errors == 1 &&
++ (rbio->bioc->map_type & BTRFS_BLOCK_GROUP_RAID6))
++ ret = recover_vertical_retry(rbio, sector_nr, faila, pointers,
++ unmap_array);
+ return ret;
+ }
+
+--
+2.47.3
+
--- /dev/null
+From ea04a5cf3d64c0a78d9dcd2f79ca0e75a1a7b4cb 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 09/10] 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
+own end_io functions, so they never reach btrfs_log_dev_io_error() in
+bio.c, which counts failed bios in the device stats for every other
+profile (and for raid56 reads that map to a single device). The raid56
+end_io functions only record the failure in the rbio's error bitmap.
+
+So a raid56 write that fails on one device within the tolerance is acked
+and leaves that device's strip stale with no trace in btrfs: write_io_errs
+stays 0 and btrfs logs nothing. Failed read-modify-write, rebuild and
+parity scrub reads are not counted either. It has been like this since
+raid56 was added.
+
+Export btrfs_log_dev_io_error() and call it from both raid56 end_io
+functions, for the device the bio was sent to. The device is found by
+the bio's bdev: a write to the replace target uses the source's pages, so
+the pages do not say which device it went to.
+
+Test (raid56-wh-harness raid56-devstats-test.sh): a write failing on one
+member within tolerance (each member in turn; raid6 also each pair)
+raises write_io_errs on exactly the failing members, and a failed
+read-modify-write read raises read_io_errs on that member only; before,
+nothing was counted. With a member absent (degraded) no counter moves,
+and during a replace onto a target that fails writes only the target is
+charged.
+
+Fixes: 53b381b3abeb ("Btrfs: RAID5 and RAID6")
+---
+ fs/btrfs/bio.c | 2 +-
+ fs/btrfs/bio.h | 2 ++
+ fs/btrfs/raid56.c | 22 +++++++++++++++++++++-
+ 3 files changed, 24 insertions(+), 2 deletions(-)
+
+diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
+index fc0b021cdefb1..d51a56c1a9531 100644
+--- a/fs/btrfs/bio.c
++++ b/fs/btrfs/bio.c
+@@ -316,7 +316,7 @@ static void btrfs_check_read_bio(struct btrfs_bio *bbio, struct btrfs_device *de
+ btrfs_bio_end_io(bbio, bbio->bio.bi_status);
+ }
+
+-static void btrfs_log_dev_io_error(const struct bio *bio, struct btrfs_device *dev)
++void btrfs_log_dev_io_error(const struct bio *bio, struct btrfs_device *dev)
+ {
+ blk_status_t sts = bio->bi_status;
+
+diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h
+index bbf362b8668bb..2451d38566d1a 100644
+--- a/fs/btrfs/bio.h
++++ b/fs/btrfs/bio.h
+@@ -13,6 +13,7 @@
+ #include "tree-checker.h"
+
+ struct btrfs_bio;
++struct btrfs_device;
+ struct btrfs_fs_info;
+ struct btrfs_inode;
+
+@@ -121,6 +122,7 @@ void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);
+ #define REQ_BTRFS_CGROUP_PUNT REQ_FS_PRIVATE
+
+ void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num);
++void btrfs_log_dev_io_error(const struct bio *bio, struct btrfs_device *dev);
+ void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace);
+ int btrfs_repair_bbio_failure(struct btrfs_bio *bbio, const struct bvec_iter *orig_iter,
+ u32 length, int mirror_num);
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index a4aeb8c385869..e45e6a6ba2566 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -1695,11 +1695,29 @@ static void rbio_wait_io(struct btrfs_raid_bio *rbio)
+ wait_for_completion(&rbio->io_done);
+ }
+
++/*
++ * Count a failed bio in the stats of the device it went to, as bio.c does for
++ * the other profiles. Look the device up by its bdev: a write to the replace
++ * target uses the source's pages, so the pages do not tell the device.
++ */
++static void rbio_log_dev_io_error(struct btrfs_raid_bio *rbio, struct bio *bio)
++{
++ struct btrfs_io_context *bioc = rbio->bioc;
++
++ for (int i = 0; i < bioc->num_stripes; i++) {
++ if (bioc->stripes[i].dev->bdev == bio->bi_bdev) {
++ btrfs_log_dev_io_error(bio, bioc->stripes[i].dev);
++ return;
++ }
++ }
++}
++
+ static void raid_wait_read_end_io(struct bio *bio)
+ {
+ struct btrfs_raid_bio *rbio = bio->bi_private;
+
+ if (bio->bi_status) {
++ rbio_log_dev_io_error(rbio, bio);
+ rbio_update_error_bitmap(rbio, bio);
+ } else {
+ set_bio_pages_uptodate(rbio, bio);
+@@ -2673,8 +2691,10 @@ static void raid_wait_write_end_io(struct bio *bio)
+ {
+ struct btrfs_raid_bio *rbio = bio->bi_private;
+
+- if (bio->bi_status)
++ if (bio->bi_status) {
++ rbio_log_dev_io_error(rbio, bio);
+ rbio_update_error_bitmap(rbio, bio);
++ }
+ bio_put(bio);
+ rbio_dec_io(rbio);
+ }
+--
+2.47.3
+
+++ /dev/null
-From 4e743a3100a732c24ec778a6693ae25400bab9d7 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 09/12] btrfs: raid56: do not unhash a cached rbio that has
- rbios plugged on it
-To: linux-btrfs@vger.kernel.org
-
-unlock_stripe() caches the finished rbio with cache_rbio() before it
-retakes the bucket and bio_list locks, and RBIO_RMW_LOCKED_BIT is still
-set at that point. A lock_stripe_add() for the same full stripe that
-runs in that window finds a cached rbio it can neither steal (still RMW
-locked) nor merge with (cached) and plugs itself onto it, which is
-correct: unlock_stripe() then sees the plug list and hands the stripe
-lock on to the plugged rbio.
-
-But if the rbio is removed from the cache in that same window --
-btrfs_raid56_uncache_range() from the commit's unpin, or the cache's own
-shrink in cache_rbio() -- __remove_rbio_from_cache() finds an empty
-bio_list, takes the rbio off the hash list, drops the hash reference and
-hits BUG_ON(!list_empty(&rbio->plug_list)). Seen on a degraded raid5
-under fsstress: the transaction kthread died in that BUG_ON with the
-bucket lock held and the rmw workers spun on it until the machine was
-reset.
-
-An rbio with rbios plugged on it is busy, like one with bios: leave it
-on the hash list and let unlock_stripe() hand the lock on; drop only the
-cache's reference here.
-
-Assisted-by: Claude:claude-opus-4-8
----
- fs/btrfs/raid56.c | 14 ++++++++++++--
- 1 file changed, 12 insertions(+), 2 deletions(-)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 44877bc3f51b7..390ad69a64e0a 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -431,11 +431,21 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
- * the rbio from the hash_table, and drop
- * the corresponding ref
- */
-- if (bio_list_empty(&rbio->bio_list)) {
-+ /*
-+ * An rbio with no bios is idle only if nothing is plugged on
-+ * it either. unlock_stripe() caches the rbio before it retakes
-+ * the locks, with RBIO_RMW_LOCKED_BIT still set, so a
-+ * lock_stripe_add() in that window can neither steal the pages
-+ * nor merge and plugs onto the cached rbio instead. That rbio
-+ * is still the stripe's lock owner and unlock_stripe() hands
-+ * the lock on to the plugged one; only the cache's reference
-+ * goes away here.
-+ */
-+ if (bio_list_empty(&rbio->bio_list) &&
-+ list_empty(&rbio->plug_list)) {
- if (!list_empty(&rbio->hash_list)) {
- list_del_init(&rbio->hash_list);
- refcount_dec(&rbio->refs);
-- ASSERT(list_empty(&rbio->plug_list));
- }
- }
- }
---
-2.47.3
-
+++ /dev/null
-From 13a1771e7dc5195969a132513d35cd9685ee471a 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 10/12] btrfs: raid56: rebuild from Q when a sector rebuilt
- from P fails its csum
-To: linux-btrfs@vger.kernel.org
-
-A sub-stripe write on RAID6 reads the whole full stripe and verifies its
-data sectors against their csums. A sector that does not match is marked
-failed, and recover_vertical() rebuilds it. With one failed sector in a
-vertical stripe it rebuilds from P, verifies the result, and fails the
-whole write with -EIO if the rebuild does not match either.
-
-P has no csum, so a stale P is not seen as a failure. A write that failed
-on the member holding a data strip and on the member holding P, but
-completed within the profile's tolerance, leaves exactly that: the data
-strip and P stale, and only Q matching what was written. Every later
-sub-stripe write into that full stripe then fails with -EIO. The
-allocator hands the same free space out again, so the next write there
-fails the same way. The same happens on a degraded filesystem when the
-member holding the data strip is missing and P is stale.
-
-Normal reads of the stale data succeed because read repair walks the
-RAID6 mirrors: mirror 2 rebuilds from P, mirror 3 also treats P as failed
-and rebuilds from Q, and each later mirror treats one more data stripe as
-failed (set_rbio_raid6_extra_error()). Scrub repairs it too. The RMW
-path only tries the first of these.
-
-When the one failed data sector of a RAID6 vertical stripe, rebuilt from
-P, does not verify, rebuild it again treating one more stripe as failed,
-in read repair's order: P (a rebuild from Q), then each other data stripe
-(a rebuild from P and Q, which covers a stale data sector that has no
-csum). Use the first rebuild whose data sectors verify. Each try writes
-its rebuild into the extra stripe's sector, so save that sector and put
-it back before the next try.
-
-Only an RMW verifies rebuilt data sectors here (rbio->csum_bitmap is only
-filled there), so read rebuild and parity scrub do not change.
-
-raid6-rmw-stale-parity-test.sh (raid56-wh-harness) makes a data strip
-and P of a full stripe holding csummed data stale, then writes into the
-rest of that stripe. Without this patch the write fails with -EIO; with
-it the write succeeds, the new parity matches the written data, and
-every file reads back, also with members missing. The arms with a stale
-data strip and P where the data member is missing, and with a stale
-csummed data strip plus a stale strip of a nodatasum file, fail the same
-way without the patch and pass with it. The arms with a stale data
-strip and Q, and with two stale csummed data strips, pass either way.
-
-Fixes: 7a3150723061 ("btrfs: raid56: do data csum verification during RMW cycle")
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/raid56.c | 115 ++++++++++++++++++++++++++++++++++++++--------
- 1 file changed, 95 insertions(+), 20 deletions(-)
-
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 390ad69a64e0a..a4aeb8c385869 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -2230,6 +2230,94 @@ static void recover_vertical_step(struct btrfs_raid_bio *rbio,
- kunmap_local(unmap_array[stripe_nr]);
- }
-
-+/*
-+ * Rebuild the vertical stripe @sector_nr treating @faila and @failb as the
-+ * failed stripes (@failb < 0 for one), then verify the rebuilt data sectors
-+ * against their csums and mark them uptodate.
-+ */
-+static int recover_vertical_try(struct btrfs_raid_bio *rbio, int sector_nr,
-+ int faila, int failb,
-+ void **pointers, void **unmap_array)
-+{
-+ int ret;
-+
-+ for (int i = 0; i < rbio->sector_nsteps; i++)
-+ recover_vertical_step(rbio, sector_nr, i, faila, failb,
-+ pointers, unmap_array);
-+ ret = verify_one_sector(rbio, faila, sector_nr);
-+ if (ret < 0)
-+ return ret;
-+ if (failb >= 0) {
-+ ret = verify_one_sector(rbio, failb, sector_nr);
-+ if (ret < 0)
-+ return ret;
-+ }
-+
-+ set_bit(rbio_sector_index(rbio, faila, sector_nr),
-+ rbio->stripe_uptodate_bitmap);
-+ if (failb >= 0)
-+ set_bit(rbio_sector_index(rbio, failb, sector_nr),
-+ rbio->stripe_uptodate_bitmap);
-+ return 0;
-+}
-+
-+static void copy_vertical_sector(struct btrfs_raid_bio *rbio, int stripe_nr,
-+ int sector_nr, void *buf, bool to_buf)
-+{
-+ const u32 step = min(rbio->bioc->fs_info->sectorsize, PAGE_SIZE);
-+ phys_addr_t *paddrs = recovered_sector_paddrs(rbio, stripe_nr, sector_nr);
-+
-+ for (int i = 0; i < rbio->sector_nsteps; i++) {
-+ void *kaddr = kmap_local_paddr(paddrs[i]);
-+
-+ if (to_buf)
-+ memcpy(buf + i * step, kaddr, step);
-+ else
-+ memcpy(kaddr, buf + i * step, step);
-+ kunmap_local(kaddr);
-+ }
-+}
-+
-+/*
-+ * A single failed data sector of a RAID6 vertical stripe was rebuilt from P,
-+ * and the result does not match its csum. Nothing verifies P, nor a data
-+ * sector without a csum, so a stale one of those is only found here. Like
-+ * read repair (see set_rbio_raid6_extra_error()), treat one more stripe as
-+ * failed and rebuild again: first P, which rebuilds from Q, then each other
-+ * data stripe, which rebuilds from P and Q.
-+ *
-+ * Each try overwrites the extra stripe's sector with its own rebuild, so put
-+ * the original back before the next one.
-+ */
-+static int recover_vertical_retry(struct btrfs_raid_bio *rbio, int sector_nr,
-+ int faila, void **pointers, void **unmap_array)
-+{
-+ void *saved;
-+ int ret = -EIO;
-+
-+ saved = kmalloc(rbio->bioc->fs_info->sectorsize, GFP_NOFS);
-+ if (!saved)
-+ return -ENOMEM;
-+
-+ for (int extra = rbio->nr_data; extra >= 0; extra--) {
-+ if (extra == faila)
-+ continue;
-+
-+ copy_vertical_sector(rbio, extra, sector_nr, saved, true);
-+ ret = recover_vertical_try(rbio, sector_nr, min(faila, extra),
-+ max(faila, extra), pointers,
-+ unmap_array);
-+ if (ret == 0) {
-+ set_bit(rbio_sector_index(rbio, extra, sector_nr),
-+ rbio->error_bitmap);
-+ break;
-+ }
-+ copy_vertical_sector(rbio, extra, sector_nr, saved, false);
-+ }
-+ kfree(saved);
-+ return ret;
-+}
-+
- /*
- * Recover a vertical stripe specified by @sector_nr.
- * @*pointers are the pre-allocated pointers by the caller, so we don't
-@@ -2241,7 +2329,7 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
- int found_errors;
- int faila;
- int failb;
-- int ret = 0;
-+ int ret;
-
- /*
- * Now we just use bitmap to mark the horizontal stripes in
-@@ -2263,25 +2351,12 @@ static int recover_vertical(struct btrfs_raid_bio *rbio, int sector_nr,
- if (unlikely(found_errors > rbio->bioc->max_errors))
- return -EIO;
-
-- for (int i = 0; i < rbio->sector_nsteps; i++)
-- recover_vertical_step(rbio, sector_nr, i, faila, failb,
-- pointers, unmap_array);
-- if (faila >= 0) {
-- ret = verify_one_sector(rbio, faila, sector_nr);
-- if (ret < 0)
-- return ret;
--
-- set_bit(rbio_sector_index(rbio, faila, sector_nr),
-- rbio->stripe_uptodate_bitmap);
-- }
-- if (failb >= 0) {
-- ret = verify_one_sector(rbio, failb, sector_nr);
-- if (ret < 0)
-- return ret;
--
-- set_bit(rbio_sector_index(rbio, failb, sector_nr),
-- rbio->stripe_uptodate_bitmap);
-- }
-+ ret = recover_vertical_try(rbio, sector_nr, faila, failb, pointers,
-+ unmap_array);
-+ if (ret == -EIO && found_errors == 1 &&
-+ (rbio->bioc->map_type & BTRFS_BLOCK_GROUP_RAID6))
-+ ret = recover_vertical_retry(rbio, sector_nr, faila, pointers,
-+ unmap_array);
- return ret;
- }
-
---
-2.47.3
-
--- /dev/null
+From 3b022e96c7a88a5ad5c389f756b75ff8d3dcafa5 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 10/10] 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")
+---
+ fs/btrfs/raid56.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 152 insertions(+)
+
+diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
+index e45e6a6ba2566..1706ec66b05fb 100644
+--- a/fs/btrfs/raid56.c
++++ b/fs/btrfs/raid56.c
+@@ -2742,10 +2742,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;
+
+ /*
+@@ -2774,6 +2917,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);
+ }
+
+ /*
+@@ -2807,11 +2951,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++) {
+@@ -2842,6 +2993,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+ /* Failed write, don't cache for page stealing. */
+ clear_bit(RBIO_CACHE_READY_BIT, &rbio->flags);
+ }
++ bitmap_free(repaired);
+ rbio_orig_end_io(rbio, errno_to_blk_status(ret));
+ }
+
+--
+2.47.3
+
+++ /dev/null
-From bc422dc6bdb326f04e6fe719aa9cb4f09042e60b 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 11/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
-own end_io functions, so they never reach btrfs_log_dev_io_error() in
-bio.c, which counts failed bios in the device stats for every other
-profile (and for raid56 reads that map to a single device). The raid56
-end_io functions only record the failure in the rbio's error bitmap.
-
-So a raid56 write that fails on one device within the tolerance is acked
-and leaves that device's strip stale with no trace in btrfs: write_io_errs
-stays 0 and btrfs logs nothing. Failed read-modify-write, rebuild and
-parity scrub reads are not counted either. It has been like this since
-raid56 was added.
-
-Export btrfs_log_dev_io_error() and call it from both raid56 end_io
-functions, for the device the bio was sent to. The device is found by
-the bio's bdev: a write to the replace target uses the source's pages, so
-the pages do not say which device it went to.
-
-Test (raid56-wh-harness raid56-devstats-test.sh): a write failing on one
-member within tolerance (each member in turn; raid6 also each pair)
-raises write_io_errs on exactly the failing members, and a failed
-read-modify-write read raises read_io_errs on that member only; before,
-nothing was counted. With a member absent (degraded) no counter moves,
-and during a replace onto a target that fails writes only the target is
-charged.
-
-Fixes: 53b381b3abeb ("Btrfs: RAID5 and RAID6")
-Assisted-by: Claude:claude-opus-5-5
----
- fs/btrfs/bio.c | 2 +-
- fs/btrfs/bio.h | 2 ++
- fs/btrfs/raid56.c | 22 +++++++++++++++++++++-
- 3 files changed, 24 insertions(+), 2 deletions(-)
-
-diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
-index b589cac044271..863043cd01117 100644
---- a/fs/btrfs/bio.c
-+++ b/fs/btrfs/bio.c
-@@ -318,7 +318,7 @@ static void btrfs_check_read_bio(struct btrfs_bio *bbio, struct btrfs_device *de
- btrfs_bio_end_io(bbio, bbio->bio.bi_status);
- }
-
--static void btrfs_log_dev_io_error(const struct bio *bio, struct btrfs_device *dev)
-+void btrfs_log_dev_io_error(const struct bio *bio, struct btrfs_device *dev)
- {
- blk_status_t sts = bio->bi_status;
-
-diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h
-index bbf362b8668bb..2451d38566d1a 100644
---- a/fs/btrfs/bio.h
-+++ b/fs/btrfs/bio.h
-@@ -13,6 +13,7 @@
- #include "tree-checker.h"
-
- struct btrfs_bio;
-+struct btrfs_device;
- struct btrfs_fs_info;
- struct btrfs_inode;
-
-@@ -121,6 +122,7 @@ void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);
- #define REQ_BTRFS_CGROUP_PUNT REQ_FS_PRIVATE
-
- void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num);
-+void btrfs_log_dev_io_error(const struct bio *bio, struct btrfs_device *dev);
- void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace);
- int btrfs_repair_bbio_failure(struct btrfs_bio *bbio, const struct bvec_iter *orig_iter,
- u32 length, int mirror_num);
-diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index a4aeb8c385869..e45e6a6ba2566 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -1695,11 +1695,29 @@ static void rbio_wait_io(struct btrfs_raid_bio *rbio)
- wait_for_completion(&rbio->io_done);
- }
-
-+/*
-+ * Count a failed bio in the stats of the device it went to, as bio.c does for
-+ * the other profiles. Look the device up by its bdev: a write to the replace
-+ * target uses the source's pages, so the pages do not tell the device.
-+ */
-+static void rbio_log_dev_io_error(struct btrfs_raid_bio *rbio, struct bio *bio)
-+{
-+ struct btrfs_io_context *bioc = rbio->bioc;
-+
-+ for (int i = 0; i < bioc->num_stripes; i++) {
-+ if (bioc->stripes[i].dev->bdev == bio->bi_bdev) {
-+ btrfs_log_dev_io_error(bio, bioc->stripes[i].dev);
-+ return;
-+ }
-+ }
-+}
-+
- static void raid_wait_read_end_io(struct bio *bio)
- {
- struct btrfs_raid_bio *rbio = bio->bi_private;
-
- if (bio->bi_status) {
-+ rbio_log_dev_io_error(rbio, bio);
- rbio_update_error_bitmap(rbio, bio);
- } else {
- set_bio_pages_uptodate(rbio, bio);
-@@ -2673,8 +2691,10 @@ static void raid_wait_write_end_io(struct bio *bio)
- {
- struct btrfs_raid_bio *rbio = bio->bi_private;
-
-- if (bio->bi_status)
-+ if (bio->bi_status) {
-+ rbio_log_dev_io_error(rbio, bio);
- rbio_update_error_bitmap(rbio, bio);
-+ }
- bio_put(bio);
- rbio_dec_io(rbio);
- }
---
-2.47.3
-
+++ /dev/null
-From a4b35a2e9704dbbb331f8931774d6d433c4bffeb 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 12/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 e45e6a6ba2566..1706ec66b05fb 100644
---- a/fs/btrfs/raid56.c
-+++ b/fs/btrfs/raid56.c
-@@ -2742,10 +2742,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;
-
- /*
-@@ -2774,6 +2917,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);
- }
-
- /*
-@@ -2807,11 +2951,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++) {
-@@ -2842,6 +2993,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
- /* Failed write, don't cache for page stealing. */
- clear_bit(RBIO_CACHE_READY_BIT, &rbio->flags);
- }
-+ bitmap_free(repaired);
- rbio_orig_end_io(rbio, errno_to_blk_status(ret));
- }
-
---
-2.47.3
-
-From 7ec955fbc4dd0c0ae0a87ad4f7d26a03277e9f5d Mon Sep 17 00:00:00 2001
+From 83d98c04f4708f23ff40246812a81a879839b181 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:01 -0400
+Date: Fri, 6 Nov 2026 05:48:15 -0500
Subject: [PATCH 00/12] btrfs: raid56 scrub and device replace with unrepairable data
To: linux-btrfs@vger.kernel.org
3 files changed, 700 insertions(+), 60 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
prerequisite-patch-id: b8b4a66a0e1de9b1976b16c26f8c5972ce30b1b8
prerequisite-patch-id: 173b1a1df563e2792318f2be7d1f8ae885566355
prerequisite-patch-id: b96f5525980fd5dc9349f7854e7fafc21d6b260a
-From 611f3c63bf6e68e1dff48605c738cbcfeaaf29ea Mon Sep 17 00:00:00 2001
+From 2e352b4e2262bf7bf73651c4c29c757f076cc17d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 02:32:16 -0400
Subject: [PATCH 01/12] btrfs: scrub: check raid56 parity of the rows without
A sector without an extent that could be neither read nor rebuilt makes
its row bad as well: there is nothing to compute the row's parity from.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 43 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 7 deletions(-)
-From 31e50e6cc975d985369dd5583acde2591b449a5b Mon Sep 17 00:00:00 2001
+From 69627a3e9d9bfaacfbaa544871480ac421b51639 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 02:32:16 -0400
Subject: [PATCH 02/12] btrfs: scrub: copy raid56 parity of unrepairable rows
fail on unrepaired data does: a replace that carries on past such a row
would otherwise leave its P/Q unwritten on the target.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 68 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 65 insertions(+), 3 deletions(-)
-From 78d758e1da37e1d8a5ed6c1365f2469f0b90a0a4 Mon Sep 17 00:00:00 2001
+From 89240c5a59ac9844fb79af9e905a801e87ac6647 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 02:32:17 -0400
Subject: [PATCH 03/12] btrfs: scrub: copy unrepaired raid56 data sectors to
"btrfs: scrub: check raid56 parity of the rows without unrepaired data"
does not depend on it.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
-From 676b778f2899780d1d45897344ab401971975679 Mon Sep 17 00:00:00 2001
+From 810de2ca25f453fc514c0e4caabb07d93b72e9f8 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 20:33:38 -0400
Subject: [PATCH 04/12] btrfs: scrub: copy every sector of raid56 data stripes
are written and only the blocks that were unrecoverable before the
replace return -EIO.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 85 insertions(+), 2 deletions(-)
-From 79f1ea957a49d17a2b0df67f16edc724db80aaa8 Mon Sep 17 00:00:00 2001
+From e882e3ea75e2fde264352fb003b7297098cdef29 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 20:33:38 -0400
Subject: [PATCH 05/12] btrfs: scrub: only avoid the replace source device for
over bad data and copies exactly as much bad parity as a replace
without -r.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
-From 1c237ec66b90d58a38df79c78cba01e59e401267 Mon Sep 17 00:00:00 2001
+From 2d18337429512a4584356deef9456b191422ea8a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 21:06:45 -0400
Subject: [PATCH 06/12] btrfs: scrub: read raid56 sectors without an extent
target sectors holding rebuilt bytes that carried another device's
damage. With this change they lose none, like replaces without -r.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
-From cf3a5686fa15382a4f3c661ca473ca51d80f9623 Mon Sep 17 00:00:00 2001
+From 363b13af1eb6abbece97da39023f0c669668199b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 3 Jul 2024 21:00:18 -0400
Subject: [PATCH 07/12] btrfs: don't abort raid56 data scrub on first
-From 3b9f88ff5f4f9171f022f53417905aaf9e11b978 Mon Sep 17 00:00:00 2001
+From 665648e5c5d9ee4c54a2e2c274f6212a400eff1d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 21 Oct 2026 03:59:11 -0400
Subject: [PATCH 08/12] btrfs: scrub: do not write raid56 parity in a read-only
parity, the scrub rewrote it, and a member image changed.
Fixes: 5a6ac9eacb49 ("Btrfs, raid56: support parity scrub on raid56")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/raid56.c | 8 +++++++-
fs/btrfs/raid56.h | 6 +++++-
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index b02c0d533342c..216012c88ad7f 100644
+index e704b31670d2b..9fe3e5ad71deb 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2494,7 +2494,8 @@ static void rmw_rbio_work_locked(struct work_struct *work)
+@@ -2505,7 +2505,8 @@ static void rmw_rbio_work_locked(struct work_struct *work)
struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
struct btrfs_io_context *bioc,
struct btrfs_device *scrub_dev,
{
struct btrfs_fs_info *fs_info = bioc->fs_info;
struct btrfs_raid_bio *rbio;
-@@ -2525,6 +2526,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+@@ -2536,6 +2537,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
ASSERT_RBIO_STRIPE(i < rbio->real_stripes, rbio, i);
bitmap_copy(&rbio->dbitmap, dbitmap, stripe_nsectors);
return rbio;
}
-@@ -2700,6 +2702,10 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2711,6 +2713,10 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
q_paddr = INVALID_PADDR;
}
-From b659dc5350db5bd2dcd0597bcb64b0182422278e Mon Sep 17 00:00:00 2001
+From b675cd725e399bb978af033461c21e33058e7cf6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 13:43:04 -0400
Subject: [PATCH 09/12] btrfs: scrub: rebuild a raid6 data stripe that both P
running dev-replace still gets the parity copy.
Fixes: 5a6ac9eacb49 ("Btrfs, raid56: support parity scrub on raid56")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/raid56.c | 229 ++++++++++++++++++++++++++++++++++++++++++----
fs/btrfs/raid56.h | 8 ++
3 files changed, 238 insertions(+), 20 deletions(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 216012c88ad7f..13f70a4165297 100644
+index 9fe3e5ad71deb..d618c754f38ba 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -9,6 +9,7 @@
bitmap_free(rbio->stripe_uptodate_bitmap);
kfree(rbio->stripe_pages);
kfree(rbio->bio_paddrs);
-@@ -2504,6 +2506,11 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+@@ -2515,6 +2517,11 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
rbio = alloc_rbio(fs_info, bioc);
if (IS_ERR(rbio))
return NULL;
bio_list_add(&rbio->bio_list, bio);
/*
* This is a special bio which is used to hold the completion handler
-@@ -2573,16 +2580,13 @@ static int alloc_rbio_essential_pages(struct btrfs_raid_bio *rbio)
+@@ -2584,16 +2591,13 @@ static int alloc_rbio_essential_pages(struct btrfs_raid_bio *rbio)
return 0;
}
ASSERT(step_nr < rbio->sector_nsteps);
-@@ -2602,36 +2606,166 @@ static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
+@@ -2613,36 +2617,166 @@ static bool verify_one_parity_step(struct btrfs_raid_bio *rbio,
xor_gen(pointers[nr_data], pointers + 1, nr_data - 1, step);
}
}
static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
-@@ -2647,6 +2781,9 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2658,6 +2792,9 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
phys_addr_t q_paddr = INVALID_PADDR;
struct bio_list bio_list;
bool is_replace = false;
int ret;
bio_list_init(&bio_list);
-@@ -2687,12 +2824,27 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2698,12 +2835,27 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
pointers[rbio->real_stripes - 1] = kmap_local_paddr(q_paddr);
}
kunmap_local(pointers[nr_data]);
__free_page(phys_to_page(p_paddr));
-@@ -2708,12 +2860,32 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2719,12 +2871,32 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
/*
* After a transaction abort or another filesystem error, write
/*
* time to start writing. Make bios for everything from the
* higher layers (the bio_list in our rbio) and our p/q. Ignore
-@@ -2944,6 +3116,23 @@ void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio)
+@@ -2955,6 +3127,23 @@ void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio)
start_async_work(rbio, scrub_rbio_work_locked);
}
-From 31742d9026ead87e06df4ed3028d6f209af68b8b Mon Sep 17 00:00:00 2001
+From 3bdeb4e44df0e1f4bbddddcc77383b8288b4942c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 16:15:58 -0400
Subject: [PATCH 10/12] btrfs: scrub: count raid56 parity mismatches as
another filesystem error, which writes nothing back
(btrfs_can_submit_repair_write()).
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/raid56.c | 51 +++++++++++++++++++++++++++++++++++++++++++----
fs/btrfs/raid56.h | 5 ++++-
3 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 13f70a4165297..27b189a7fbeb4 100644
+index d618c754f38ba..e3777f8af6b31 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2497,7 +2497,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+@@ -2508,7 +2508,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
struct btrfs_io_context *bioc,
struct btrfs_device *scrub_dev,
unsigned long *dbitmap, int stripe_nsectors,
{
struct btrfs_fs_info *fs_info = bioc->fs_info;
struct btrfs_raid_bio *rbio;
-@@ -2534,6 +2534,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
+@@ -2545,6 +2545,7 @@ struct btrfs_raid_bio *raid56_parity_alloc_scrub_rbio(struct bio *bio,
bitmap_copy(&rbio->dbitmap, dbitmap, stripe_nsectors);
rbio->scrub_readonly = readonly;
return rbio;
}
-@@ -2768,6 +2769,37 @@ static int verify_one_parity_sector(struct btrfs_raid_bio *rbio,
+@@ -2779,6 +2780,37 @@ static int verify_one_parity_sector(struct btrfs_raid_bio *rbio,
return -1;
}
static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
{
struct btrfs_io_context *bioc = rbio->bioc;
-@@ -2782,6 +2814,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2793,6 +2825,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
struct bio_list bio_list;
bool is_replace = false;
unsigned long read_errors = 0;
unsigned long rebuilt = 0;
u8 rebuilt_stripe[BITS_PER_LONG];
int ret;
-@@ -2826,11 +2859,20 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2837,11 +2870,20 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
/*
* Rows with a read error were rebuilt by recover_scrub_rbio(): do not
bitmap_clear(rbio->error_bitmap, 0, rbio->nr_sectors);
-@@ -2845,6 +2887,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2856,6 +2898,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
rebuilt_stripe[sectornr] = stripe;
}
}
-From 17bd70d878da91e41a87a12f8802f01e010aa203 Mon Sep 17 00:00:00 2001
+From f2007666c39f1d24fb4806bc12d38d08deb3e3aa Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 22:15:15 -0400
Subject: [PATCH 11/12] btrfs: scrub: name the device a raid56 data sector was
member, always the predicted stripes[0].
Fixes: 0096580713ff ("btrfs: scrub: introduce error reporting functionality for scrub_stripe")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 31 +++++++------------------------
1 file changed, 7 insertions(+), 24 deletions(-)
-From 7ec955fbc4dd0c0ae0a87ad4f7d26a03277e9f5d Mon Sep 17 00:00:00 2001
+From 83d98c04f4708f23ff40246812a81a879839b181 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 22:15:16 -0400
Subject: [PATCH 12/12] btrfs: scrub: count the raid56 data repairs made by a
keeps that check next to the own-scrub test.
Fixes: 1009254bf22a ("btrfs: scrub: use scrub_stripe to implement RAID56 P/Q scrub")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 107 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 104 insertions(+), 3 deletions(-)
-From 76eb4edbade0c6ba280af99ef5e91f204e04d6d4 Mon Sep 17 00:00:00 2001
+From fb0dade563cf4400faf384e6478eb40305e775e3 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:05 -0400
+Date: Fri, 6 Nov 2026 05:48:17 -0500
Subject: [PATCH 0/9] btrfs: read policies and per-device read stats (Kai Krakow's series)
To: linux-btrfs@vger.kernel.org
6 files changed, 510 insertions(+), 32 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From d71e118b9173507fe36a00a13a74f7b06119d206 Mon Sep 17 00:00:00 2001
+From d2ba4d2c53282f3d54bcc364f0ada121c17ebb02 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 11 Jul 2026 00:44:51 +0200
Subject: [PATCH 1/9] btrfs: add io read stats per device to devinfo
BTRFS_ATTR_PTR(devid, fsid),
BTRFS_ATTR_PTR(devid, in_fs_metadata),
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index ce78a9441c64f..1ee88bb257ac1 100644
+index 3d4ef6725de0e..ea8461bc7d82c 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6682,6 +6682,15 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6694,6 +6694,15 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
else
num_stripes = map->num_stripes;
switch (policy) {
default:
/* Shouldn't happen, just warn and use pid instead of failing */
-@@ -6717,14 +6726,29 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6729,14 +6738,29 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
for (tolerance = 0; tolerance < 2; tolerance++) {
if (map->stripes[preferred_mirror].dev->bdev &&
(tolerance || map->stripes[preferred_mirror].dev != srcdev))
* and the io error handling code will clean up eventually
*/
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 75b1179776c80..d065cec44e547 100644
+index 891bc2432870a..281ce92af1822 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -217,6 +217,14 @@ struct btrfs_device {
-From 59bb2938019d6749f1eb2244d592bacb2d5ca6ca Mon Sep 17 00:00:00 2001
+From 73f9b169786d3abbad108db8ce63b4b6edecab65 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 13 Dec 2025 18:34:36 +0100
Subject: [PATCH 2/9] btrfs: move read policies out of experimental
#endif
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 1ee88bb257ac1..983f4d7910bc6 100644
+index ea8461bc7d82c..1d30b6a99b4d7 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -1293,7 +1293,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
+@@ -1295,7 +1295,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
fs_devices->latest_dev = latest_dev;
fs_devices->total_rw_bytes = 0;
fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_REGULAR;
fs_devices->rr_min_contig_read = BTRFS_DEFAULT_RR_MIN_CONTIG_READ;
fs_devices->read_devid = latest_dev->devid;
fs_devices->read_policy = btrfs_read_policy_to_enum(btrfs_get_mod_read_policy(),
-@@ -1309,7 +1309,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
+@@ -1311,7 +1311,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
}
#else
fs_devices->read_policy = BTRFS_READ_POLICY_PID;
return 0;
}
-@@ -6593,7 +6593,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
+@@ -6605,7 +6605,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
return len;
}
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
for (int index = first; index < first + num_stripes; index++) {
-@@ -6661,7 +6661,7 @@ static int btrfs_read_rr(const struct btrfs_chunk_map *map, int first, int num_s
+@@ -6673,7 +6673,7 @@ static int btrfs_read_rr(const struct btrfs_chunk_map *map, int first, int num_s
read_cycle = total_reads / min_reads_per_dev;
return stripes[read_cycle % num_stripes].num;
}
static int find_live_mirror(struct btrfs_fs_info *fs_info,
struct btrfs_chunk_map *map, int first,
-@@ -6701,14 +6701,14 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6713,14 +6713,14 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
case BTRFS_READ_POLICY_PID:
preferred_mirror = first + (current->pid % num_stripes);
break;
if (dev_replace_is_ongoing &&
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index d065cec44e547..fc9bc3f462795 100644
+index 281ce92af1822..8e888f2e0a1f3 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -334,12 +334,12 @@ enum btrfs_chunk_allocation_policy {
-From 336671af9065554471666f16177c5bb3ab8c94c0 Mon Sep 17 00:00:00 2001
+From 3e4fac65c6c3ffa2f56255b250abbd83c77bedcf Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Fri, 25 Apr 2025 21:46:52 +0200
Subject: [PATCH 3/9] btrfs: add in-flight queue read policy
int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 983f4d7910bc6..f94e9a2f58e3b 100644
+index 1d30b6a99b4d7..e54100aae37df 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -35,6 +35,10 @@
#define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
BTRFS_BLOCK_GROUP_RAID10 | \
BTRFS_BLOCK_GROUP_RAID56_MASK)
-@@ -6594,6 +6598,50 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
+@@ -6606,6 +6610,50 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
}
#ifdef CONFIG_BTRFS_READ_POLICIES
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
for (int index = first; index < first + num_stripes; index++) {
-@@ -6705,6 +6753,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6717,6 +6765,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
case BTRFS_READ_POLICY_RR:
preferred_mirror = btrfs_read_rr(map, first, num_stripes);
break;
preferred_mirror = btrfs_read_preferred(map, first, num_stripes);
break;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index fc9bc3f462795..e81d80273254c 100644
+index 8e888f2e0a1f3..5c514dbb23884 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -337,6 +337,8 @@ enum btrfs_read_policy {
-From e2cbe223f5f6d86fd739745b8ba86f84b582883e Mon Sep 17 00:00:00 2001
+From fa4f23204bf16cb4ea0414b777988d6798abd761 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Thu, 9 Jul 2026 12:35:14 +0200
Subject: [PATCH 4/9] btrfs: move age io stat out of
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index f94e9a2f58e3b..42d537ef1b67f 100644
+index e54100aae37df..cee81fabe8a56 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6730,14 +6730,17 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6742,14 +6742,17 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
else
num_stripes = map->num_stripes;
switch (policy) {
default:
-@@ -6789,17 +6792,19 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6801,17 +6804,19 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
}
out:
/* we couldn't find one that doesn't fail. Just return something
* and the io error handling code will clean up eventually
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index e81d80273254c..5b94161023664 100644
+index 5c514dbb23884..283ca70777bc9 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -218,10 +218,10 @@ struct btrfs_device {
-From 63b6f0773c9843cb6af29e4fb0cfa240b9fd58fd Mon Sep 17 00:00:00 2001
+From c13710a35849be014e5f30f2ac1cf07e353f9465 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Thu, 9 Jul 2026 12:27:18 +0200
Subject: [PATCH 5/9] btrfs: break queue read ties by mirror age
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 42d537ef1b67f..c14768795cda1 100644
+index cee81fabe8a56..dbf33e8bd3e12 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6613,28 +6613,48 @@ static unsigned int part_in_flight(struct block_device *part)
+@@ -6625,28 +6625,48 @@ static unsigned int part_in_flight(struct block_device *part)
return inflight;
}
-From c5a0115e99bd21233fd97e891cb651f5e03d077e Mon Sep 17 00:00:00 2001
+From a8ef24e95145c4f15597204870eaa4268d201456 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Thu, 9 Jul 2026 13:10:10 +0200
Subject: [PATCH 6/9] btrfs: add read latency health stats to per-device io
BTRFS_ATTR(devid, read_stats, btrfs_devinfo_read_stats_show);
#endif /* CONFIG_BTRFS_PER_DEVICE_IO_STATS */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index c14768795cda1..d7bbe94175c2d 100644
+index dbf33e8bd3e12..372c54c212461 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -35,9 +35,12 @@
#define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
BTRFS_BLOCK_GROUP_RAID10 | \
-@@ -6662,6 +6665,77 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
+@@ -6674,6 +6677,77 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
return best_stripe;
}
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
for (int index = first; index < first + num_stripes; index++) {
-@@ -6762,6 +6836,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6774,6 +6848,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
}
#endif /* CONFIG_BTRFS_READ_POLICIES || CONFIG_BTRFS_PER_DEVICE_IO_STATS */
default:
/* Shouldn't happen, just warn and use pid instead of failing */
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 5b94161023664..c06dc6b33c839 100644
+index 283ca70777bc9..d4290428d2746 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -224,6 +224,21 @@ struct btrfs_device {
-From 115e32a72555b6abce8a4ee8715fb71ce28976aa Mon Sep 17 00:00:00 2001
+From 933d763ddff40722bb4c6614d6c1ce5cae13e55c Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Wed, 8 Jul 2026 16:38:51 +0200
Subject: [PATCH 7/9] btrfs: add queue-adaptive read policy
BTRFS_ATTR(devid, read_stats, btrfs_devinfo_read_stats_show);
#endif /* CONFIG_BTRFS_PER_DEVICE_IO_STATS */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index d7bbe94175c2d..245ae1ef7b363 100644
+index 372c54c212461..9fdcb16c46469 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -36,11 +36,9 @@
#define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
BTRFS_BLOCK_GROUP_RAID10 | \
-@@ -6665,9 +6663,8 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
+@@ -6677,9 +6675,8 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
return best_stripe;
}
#define BTRFS_READ_HEALTH_RECHECK_INTERVAL HZ
#define BTRFS_READ_HEALTH_MIN_SAMPLE_IOS 256ULL
-@@ -6675,6 +6672,15 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
+@@ -6687,6 +6684,15 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
* Refresh the cached windowed avg read latency for the current candidates.
* The avg is a delta against the previous checkpoint, not a lifetime average,
* so unrelated bulk reads can only skew the current window.
*/
static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
int num_stripes)
-@@ -6730,11 +6736,129 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
+@@ -6742,11 +6748,129 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
atomic64_set(&device->health_avg_ns, div64_u64(delta_wait, delta_ios));
atomic64_set(&device->health_check_ios, read_ios);
atomic64_set(&device->health_check_wait, read_wait);
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
-@@ -6836,10 +6960,6 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6848,10 +6972,6 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
}
#endif /* CONFIG_BTRFS_READ_POLICIES || CONFIG_BTRFS_PER_DEVICE_IO_STATS */
switch (policy) {
default:
/* Shouldn't happen, just warn and use pid instead of failing */
-@@ -6858,6 +6978,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
+@@ -6870,6 +6990,10 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
preferred_mirror = btrfs_read_earliest(fs_info, map, first,
num_stripes);
break;
preferred_mirror = btrfs_read_preferred(map, first, num_stripes);
break;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index c06dc6b33c839..211b406ab3413 100644
+index d4290428d2746..4d281da89ac94 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -225,6 +225,14 @@ struct btrfs_device {
-From 03489adc8d7f8a8fba8c8c48b642acdef4573c64 Mon Sep 17 00:00:00 2001
+From 8a440b21ffeb0a45c2e26e0866175fbf581e3092 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sun, 12 Jul 2026 14:15:19 +0200
Subject: [PATCH 8/9] btrfs: scale adaptive queue guard with latency
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 245ae1ef7b363..5cbec0f704129 100644
+index 9fdcb16c46469..52483d9988f72 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6663,7 +6663,8 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
+@@ -6675,7 +6675,8 @@ static int btrfs_read_earliest(struct btrfs_fs_info *fs_info,
return best_stripe;
}
#define BTRFS_READ_HEALTH_RECHECK_INTERVAL HZ
#define BTRFS_READ_HEALTH_MIN_SAMPLE_IOS 256ULL
-@@ -6758,14 +6759,14 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
+@@ -6770,14 +6771,14 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
* so it can never be stale from a different mirror pairing on a larger
* pool. If the in-flight winner is not derived-slow, done. If it is,
* it's only trusted when its in-flight lead over the best non-slow
*/
static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
struct btrfs_chunk_map *map, int first,
-@@ -6781,6 +6782,8 @@ static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
+@@ -6793,6 +6794,8 @@ static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
u64 best_healthy_inflight = U64_MAX;
u64 best_healthy_age = 0;
int best_healthy_stripe = -1;
btrfs_update_read_health(map, first, num_stripes);
-@@ -6848,7 +6851,21 @@ static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
+@@ -6860,7 +6863,21 @@ static int btrfs_read_queue_adaptive(struct btrfs_fs_info *fs_info,
return best_stripe;
if (best_healthy_stripe < 0)
return best_stripe; /* every candidate derived-slow, no alternative */
-From 76eb4edbade0c6ba280af99ef5e91f204e04d6d4 Mon Sep 17 00:00:00 2001
+From fb0dade563cf4400faf384e6478eb40305e775e3 Mon Sep 17 00:00:00 2001
From: Kai Krakow <kai@kaishome.de>
Date: Sat, 18 Jul 2026 18:15:38 +0200
Subject: [PATCH 9/9] btrfs: count unstable read health snapshots
BTRFS_ATTR(devid, read_stats, btrfs_devinfo_read_stats_show);
#endif /* CONFIG_BTRFS_PER_DEVICE_IO_STATS */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index 5cbec0f704129..63b646073e423 100644
+index 52483d9988f72..ae2bf25f3130b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6709,6 +6709,10 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
+@@ -6721,6 +6721,10 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
checked_jiffies)
continue;
/*
* ios is updated before nsecs. Bracket the wait read to reject a
* completion that could pair newer wait time with an older io count.
-@@ -6716,8 +6720,12 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
+@@ -6728,8 +6732,12 @@ static void btrfs_update_read_health(struct btrfs_chunk_map *map, int first,
read_ios_before = part_stat_read(device->bdev, ios[READ]);
read_wait = part_stat_read(device->bdev, nsecs[READ]);
read_ios = part_stat_read(device->bdev, ios[READ]);
checked_ios = atomic64_read(&device->health_check_ios);
checked_wait = atomic64_read(&device->health_check_wait);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 211b406ab3413..0234e95d845a0 100644
+index 4d281da89ac94..6c707e2bb73b0 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -230,6 +230,12 @@ struct btrfs_device {
-From 72e09512671c6dbee47d35aad0fa6f98073fcb4e Mon Sep 17 00:00:00 2001
+From eed1056fffd707affeac38415f2abe5f8d9f8e12 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:01 -0400
+Date: Fri, 6 Nov 2026 05:48:15 -0500
Subject: [PATCH 0/4] btrfs: read repair and scrub after a transaction abort
To: linux-btrfs@vger.kernel.org
4 files changed, 56 insertions(+), 3 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 13a9bbefab5769fb053c1cc67534ee62761840a5 Mon Sep 17 00:00:00 2001
+From c109be9feb88a61103c0d57bb50b452a30e5fa15 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/4] btrfs: give the read repair bio an end_io for submit
Fixes: 7609afac6775 ("btrfs: handle checksum validation and repair at the storage layer")
Cc: stable@vger.kernel.org # 6.6+
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/bio.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
-From a4071d1bdf4f3024c37b6c213fc462bf8383c4c0 Mon Sep 17 00:00:00 2001
+From 13969538d7fcfa9fcde07a6fbbe22d39e9aa0709 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/4] btrfs: look up a repair read's csums in the same root as
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(+)
-From e3d9b5c617267b110c72f9294b3d5462697bdf0f Mon Sep 17 00:00:00 2001
+From e8210eab80ce0bad9006169433522b6438511cca 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/4] btrfs: do not write back a read repair after a
Fixes: 8ceaad6cd6e7 ("btrfs: do not ASSERT() when the fs flips RO inside btrfs_repair_io_failure()")
Fixes: 9b2839451dfc ("btrfs: introduce a new shutdown state")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/bio.c | 2 +-
fs/btrfs/fs.h | 13 +++++++++++++
-From 72e09512671c6dbee47d35aad0fa6f98073fcb4e Mon Sep 17 00:00:00 2001
+From eed1056fffd707affeac38415f2abe5f8d9f8e12 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/4] btrfs: scrub: do not write back repairs after a
skipped too, and its copy to a dev-replace target still goes out.
Fixes: 54765392a1b9 ("btrfs: scrub: introduce helper to queue a stripe for scrub")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/raid56.c | 9 +++++++++
fs/btrfs/scrub.c | 6 +++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 7dd937fa0c262..b02c0d533342c 100644
+index a8a8004bb14c7..e704b31670d2b 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2700,6 +2700,14 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2711,6 +2711,14 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
q_paddr = INVALID_PADDR;
}
/*
* time to start writing. Make bios for everything from the
* higher layers (the bio_list in our rbio) and our p/q. Ignore
-@@ -2715,6 +2723,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
+@@ -2726,6 +2734,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
goto cleanup;
}
-From 002da63fa0320576de844ad398efc2d2586a69df Mon Sep 17 00:00:00 2001
+From 28c07811477669dff1d815cb59e1e1b56f3baa68 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:02 -0400
+Date: Fri, 6 Nov 2026 05:48:15 -0500
Subject: [PATCH 0/3] btrfs: block group reclaim fixes for a full filesystem
To: linux-btrfs@vger.kernel.org
4 files changed, 124 insertions(+), 3 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 56bbc2412451d2750d4432b24c03f191e8ee6b79 Mon Sep 17 00:00:00 2001
+From ca6a08b6b6f2e4245aed613f8294f3a32e3eeb09 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 24 Sep 2026 02:21:12 -0400
Subject: [PATCH 1/3] btrfs: do not reclaim block groups on an errored
hit ENOSPC and aborted, the reclaim worker sat in that wait for good. The
wait is fixed where it is; the worker has nothing to do there either way.
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 4 ++++
1 file changed, 4 insertions(+)
-From 9e8e0abcbcb4feb8eea8cc1ae090a218739b6bc7 Mon Sep 17 00:00:00 2001
+From 631ee219a55e87f483ea49a572529ab30ef1da3d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 13:04:19 -0400
Subject: [PATCH 2/3] btrfs: log block group reclaim at debug level
Errors are still logged with btrfs_err() as before.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
-From 002da63fa0320576de844ad398efc2d2586a69df Mon Sep 17 00:00:00 2001
+From 28c07811477669dff1d815cb59e1e1b56f3baa68 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 04:02:52 -0400
Subject: [PATCH 3/3] btrfs: back off block group reclaim after repeated ENOSPC
/sys/fs/btrfs/<uuid>/allocation/<type>/reclaim_backoffs counts the
backoffs, and the start of one is logged at debug level ("reclaim: ...").
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 94 +++++++++++++++++++++++++++++++++++++++++-
fs/btrfs/block-group.h | 1 +
-From 4d9e701c741188892031ed8989b6824e2ee59411 Mon Sep 17 00:00:00 2001
+From 0d75f39b65f3fa3ba0eadd5ff1dedaa2d5948c67 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:06 -0400
+Date: Fri, 6 Nov 2026 05:48:17 -0500
Subject: [PATCH 0/2] btrfs: reflink: two fixes for copying inline extents into the page cache
To: linux-btrfs@vger.kernel.org
1 file changed, 18 insertions(+), 2 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From cc69842d79ecb04b150b2b84c9983390b568a6f7 Mon Sep 17 00:00:00 2001
+From 8148cc56f72ab4dd003b57bdd4cc5b1401cf968f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Mon, 26 Oct 2026 15:26:35 -0400
Subject: [PATCH 1/2] btrfs: reflink: zero the right part of the folio after
copy does.
Fixes: 3115deb381e9 ("btrfs: reflink: make copy_inline_to_page() to be subpage compatible")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/reflink.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
-From 4d9e701c741188892031ed8989b6824e2ee59411 Mon Sep 17 00:00:00 2001
+From 0d75f39b65f3fa3ba0eadd5ff1dedaa2d5948c67 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Mon, 26 Oct 2026 15:26:36 -0400
Subject: [PATCH 2/2] btrfs: reflink: undo delalloc if inline extent
read gets it from disk.
Fixes: 05a5a7621ce6 ("Btrfs: implement full reflink support for inline extents")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/reflink.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
-From 1a00c361d1af739637dd7663f72bd20a7a66dcc7 Mon Sep 17 00:00:00 2001
+From 480444bfe90d6ebb487cc5533719d4ef95c34132 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:05 -0400
+Date: Fri, 6 Nov 2026 05:48:17 -0500
Subject: [PATCH 00/10] btrfs: dev-replace error accounting, resume and failure handling, and an abort option
To: linux-btrfs@vger.kernel.org
7 files changed, 190 insertions(+), 29 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From b6aab469cf1d43ba27bdedec68ac943f6e2aa84d Mon Sep 17 00:00:00 2001
+From 24fc24aefd4bc5f5743f7cbdddc67c60657e4c8f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 01:19:17 -0400
Subject: [PATCH 01/10] btrfs: commit the canceled state when a device replace
reaches the disk. A failure to commit is only logged: the replace has
already failed, and its return value is the scrub error.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/dev-replace.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
-index cdfe093e5c5c4..e28a0e6806bcd 100644
+index 3c48cc714fef2..68aaf39020a51 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
-@@ -978,6 +978,22 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
+@@ -977,6 +977,22 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
if (src_device->bdev)
bdev_allow_freeze(src_device->bdev);
btrfs_rm_dev_replace_unblocked(fs_info);
-From 96b87030db6ae7e4eedbe275dd02be2d651c7a35 Mon Sep 17 00:00:00 2001
+From f391d3ff6d63ff433dfcb94679fa88a1a3eb419d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 04:07:33 -0400
Subject: [PATCH 02/10] btrfs: scrub: do not count write errors twice, or on
it maintains is unchanged.
Fixes: ec1f3a207cdf3 ("btrfs: scrub: update device stats when an error is detected")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 3 ---
1 file changed, 3 deletions(-)
-From b5b7853cd89b39ce2145822b01402ef1ce852c81 Mon Sep 17 00:00:00 2001
+From 8a2fb848ff33317d5f00604bf727ce8cd78ecd62 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 04:07:34 -0400
Subject: [PATCH 03/10] btrfs: dev-replace: count uncorrectable read errors
the replace, so that the sectors of the batch that aborts it are counted
as well.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
-From ef9040540b2392e1d3e3f7d563302ead2a54f901 Mon Sep 17 00:00:00 2001
+From 13bc21e764b63c201af7ea76abea6afae622f988 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 13:58:22 -0400
Subject: [PATCH 04/10] btrfs: dev-replace: do not warn when a resumed replace
The failure is already logged and recorded as a canceled replace. Drop
the WARN_ON.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/dev-replace.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
-index e28a0e6806bcd..ee16b80d7de9b 100644
+index 68aaf39020a51..b19e6536ac327 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
-@@ -1337,8 +1337,7 @@ static int btrfs_dev_replace_kthread(void *data)
+@@ -1336,8 +1336,7 @@ static int btrfs_dev_replace_kthread(void *data)
dev_replace->committed_cursor_left,
btrfs_device_get_total_bytes(dev_replace->srcdev),
&dev_replace->scrub_progress, false, true);
-From adbf4100993da32d4dd535d34d0825e474368bb0 Mon Sep 17 00:00:00 2001
+From 93f0be8dc0c6a0ed49eb0f669aec105019238ff5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 04:07:34 -0400
Subject: [PATCH 05/10] btrfs: dev-replace: count write errors to the target
writes are submitted.
Fixes: e02ee89baa66c ("btrfs: scrub: switch scrub_simple_mirror() to scrub_stripe infrastructure")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
-From 26025d2bbc6648b956e2a0cab9b3676adac28cf5 Mon Sep 17 00:00:00 2001
+From ba95b697f5bbd63ca50aa9cda1045c1ec8fcd34c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 29 Oct 2026 12:17:20 -0400
Subject: [PATCH 06/10] btrfs: dev-replace: do not skip the rest of a chunk
btrfs_dec_block_group_ro() anyway.
Fixes: 1a1a8b732c7e9 ("Btrfs: fix race setting block group back to RW mode during device replace")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/scrub.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
-From 5cd2203a007a4dd165929ee550000955aead9279 Mon Sep 17 00:00:00 2001
+From cb21c83bd66c030ebf21f22fad584190c74f42fd Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 04:07:34 -0400
Subject: [PATCH 07/10] btrfs: dev-replace: report the progress of a canceled
only when the copy of that chunk is complete, so a replace that stops
part way through a chunk is reported at the start of that chunk.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/dev-replace.c | 10 +++++++++-
fs/btrfs/fs.h | 2 ++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
-index ee16b80d7de9b..a48c5daae2302 100644
+index b19e6536ac327..cf774f9114d5c 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -65,6 +65,7 @@
static int btrfs_dev_replace_kthread(void *data);
int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
-@@ -941,6 +942,9 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
+@@ -940,6 +941,9 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
}
down_write(&dev_replace->rwsem);
dev_replace->replace_state =
scrub_ret ? BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED
: BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED;
-@@ -1084,9 +1088,11 @@ static u64 btrfs_dev_replace_progress(struct btrfs_fs_info *fs_info)
+@@ -1083,9 +1087,11 @@ static u64 btrfs_dev_replace_progress(struct btrfs_fs_info *fs_info)
switch (dev_replace->replace_state) {
case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:
case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED:
ret = 1000;
break;
-@@ -1170,6 +1176,8 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
+@@ -1169,6 +1175,8 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR;
tgt_device = dev_replace->tgtdev;
src_device = dev_replace->srcdev;
-From 3df39f4186e993b659a4eff8853d24557404acc0 Mon Sep 17 00:00:00 2001
+From cfc2c59bdeaa14024310d30598f6bb6f76f0e74b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 16 Oct 2026 13:02:21 -0400
Subject: [PATCH 08/10] btrfs: dev-replace: optionally abort on uncorrectable
This depends on the counting of uncorrectable read errors added by
"btrfs: dev-replace: count uncorrectable read errors".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/dev-replace.c | 32 ++++++++++++++++++++++++--------
fs/btrfs/fs.h | 2 ++
5 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
-index a48c5daae2302..50c2e53c148a4 100644
+index cf774f9114d5c..c3e88f9729a66 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -81,6 +81,7 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
dev_replace->replace_state = btrfs_dev_replace_replace_state(eb, ptr);
dev_replace->time_started = btrfs_dev_replace_time_started(eb, ptr);
dev_replace->time_stopped =
-@@ -422,7 +426,7 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
+@@ -421,7 +425,7 @@ int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
else
btrfs_set_dev_replace_src_devid(eb, ptr, (u64)-1);
btrfs_set_dev_replace_cont_reading_from_srcdev_mode(eb, ptr,
btrfs_set_dev_replace_replace_state(eb, ptr,
dev_replace->replace_state);
btrfs_set_dev_replace_time_started(eb, ptr, dev_replace->time_started);
-@@ -592,7 +596,7 @@ bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
+@@ -591,7 +595,7 @@ bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
const char *tgtdev_name, u64 srcdevid, const char *srcdev_name,
{
struct btrfs_root *root = fs_info->dev_root;
struct btrfs_trans_handle *trans;
-@@ -660,14 +664,17 @@ static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
+@@ -659,14 +663,17 @@ static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
}
dev_replace->cont_reading_from_srcdev_mode = read_src;
/*
* from now on, the writes to the srcdev are all duplicated to
-@@ -750,9 +757,19 @@ static int btrfs_check_replace_dev_names(struct btrfs_ioctl_dev_replace_args *ar
+@@ -749,9 +756,19 @@ static int btrfs_check_replace_dev_names(struct btrfs_ioctl_dev_replace_args *ar
int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info,
struct btrfs_ioctl_dev_replace_args *args)
{
case BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS:
case BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_AVOID:
break;
-@@ -765,8 +782,7 @@ int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info,
+@@ -764,8 +781,7 @@ int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info,
ret = btrfs_dev_replace_start(fs_info, args->start.tgtdev_name,
args->start.srcdevid,
-From 8536334bdfdc30f8f18c85d8867eeb414dbd3ec0 Mon Sep 17 00:00:00 2001
+From ca6bd1e590349479ccfb229fbf6de054303e1124 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 29 Oct 2026 12:17:21 -0400
Subject: [PATCH 09/10] btrfs: mount a single device filesystem with a device
Fixes: bc27d6f0aa0e4 ("btrfs: scan but don't register device on single device filesystem")
Fixes: a5b8a5f9f8355 ("btrfs: support cloned-device mount capability")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/volumes.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index ce78a9441c64f..4c3106acb295e 100644
+index 3d4ef6725de0e..456becaa77cf0 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -586,6 +586,27 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
+@@ -588,6 +588,27 @@ static int btrfs_free_stale_devices(dev_t devt, struct btrfs_device *skip_device
return ret;
}
static struct btrfs_fs_devices *find_fsid_by_device(
struct btrfs_super_block *disk_super,
dev_t devt, bool *same_fsid_diff_dev)
-@@ -644,6 +665,8 @@ static struct btrfs_fs_devices *find_fsid_by_device(
+@@ -646,6 +667,8 @@ static struct btrfs_fs_devices *find_fsid_by_device(
/* New device. */
if (fsid_fs_devices == NULL) {
return NULL;
} else {
/* sb::fsid is already used create a new temp_fsid. */
*same_fsid_diff_dev = true;
-@@ -1460,8 +1483,15 @@ static bool btrfs_skip_registration(struct btrfs_super_block *disk_super,
+@@ -1462,8 +1485,15 @@ static bool btrfs_skip_registration(struct btrfs_super_block *disk_super,
mutex_unlock(&fs_devices->device_list_mutex);
}
-From 1a00c361d1af739637dd7663f72bd20a7a66dcc7 Mon Sep 17 00:00:00 2001
+From 480444bfe90d6ebb487cc5533719d4ef95c34132 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 29 Oct 2026 17:52:59 -0400
Subject: [PATCH 10/10] btrfs: scrub: stop scrub and device replace when the
replace goes on until it completes.
Fixes: 1acd6831d9877 ("Btrfs: avoid risk of a deadlock in btrfs_handle_error")
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/messages.c | 13 +++++++------
fs/btrfs/scrub.c | 18 ++++++++++++++++++
-From 8a5168fc52bb4f4c8a63561b47b1264a7a003a04 Mon Sep 17 00:00:00 2001
+From 3865255228933287e3a8da2aaa0357822864c342 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:06 -0400
+Date: Fri, 6 Nov 2026 05:48:17 -0500
Subject: [PATCH 0/1] btrfs: resize: allow shrinking a missing device
To: linux-btrfs@vger.kernel.org
1 file changed, 28 insertions(+), 4 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
--
2.47.3
-From 8a5168fc52bb4f4c8a63561b47b1264a7a003a04 Mon Sep 17 00:00:00 2001
+From 3865255228933287e3a8da2aaa0357822864c342 Mon Sep 17 00:00:00 2001
From: Qu Wenruo <wqu@suse.com>
Date: Mon, 18 Nov 2019 15:05:25 +0800
Subject: [PATCH 1/1] btrfs: resize: allow shrinking a missing device
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index ac070c745b0eb..b7ad8289108a4 100644
+index 215e3220df7fa..09d13fbea6382 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1033,6 +1033,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
-From 1944ff74ed890d045c8d8f7346c44c519f6a2dee Mon Sep 17 00:00:00 2001
+From 294d230e458ac952577f5edc9d25770679c636c1 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
-Date: Sat, 31 Oct 2026 01:04:02 -0400
-Subject: [RFC PATCH 00/85] btrfs: close the raid56 write hole for datacow with stripe-exclusive allocation
+Date: Fri, 6 Nov 2026 05:48:15 -0500
+Subject: [RFC PATCH 00/86] btrfs: close the raid56 write hole for datacow with stripe-exclusive allocation
To: linux-btrfs@vger.kernel.org
This series closes the raid56 write hole for datacow data by changing
The harness, logs and test catalog are available on request.
-Zygo Blaxell (85):
+Zygo Blaxell (86):
btrfs: add btrfs_claim_free_stripe_run() for stripe-exclusive
allocation
btrfs: add open stripe run tracking for stripe-exclusive allocation
(debug_meta part)
btrfs: stripe_alloc: keep a stripe in the rbio cache until its run has
written all of it (debug_meta part)
+ btrfs: stripe_alloc: drop the extract hooks of the stripe_alloc
+ properties
fs/btrfs/block-group.c | 3870 ++++++++++++++++++++++++++++-
fs/btrfs/block-group.h | 313 ++-
fs/btrfs/messages.c | 3 +
fs/btrfs/ordered-data.c | 126 +
fs/btrfs/ordered-data.h | 14 +
- fs/btrfs/props.c | 154 ++
+ fs/btrfs/props.c | 140 ++
fs/btrfs/props.h | 1 +
fs/btrfs/qgroup.c | 12 +
fs/btrfs/qgroup.h | 3 +
fs/btrfs/zoned.c | 10 -
fs/btrfs/zoned.h | 3 -
include/trace/events/btrfs.h | 60 +
- 43 files changed, 10876 insertions(+), 146 deletions(-)
+ 43 files changed, 10862 insertions(+), 146 deletions(-)
-base-commit: bf921b86bdf225f19ffd41533f5c779fba99012e
prerequisite-patch-id: d27f13acdb7e1fb211a9524027f3f1c8c119f80b
prerequisite-patch-id: 3ba444b908adb7eb7dd36a0bac6a3816516935c4
prerequisite-patch-id: 9eebec1e5af9c3767f7de46e5a2406a7d140b135
-From 81d6ce66c3eec1d688dde8c89f22d519a2a9784f Mon Sep 17 00:00:00 2001
+From 91c74628bae365b6d8f5628cc974099aafd8ff56 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
-Subject: [RFC PATCH 01/85] btrfs: add btrfs_claim_free_stripe_run() for
+Subject: [RFC PATCH 01/86] btrfs: add btrfs_claim_free_stripe_run() for
stripe-exclusive allocation
To: linux-btrfs@vger.kernel.org
relative geometry, bitmap entries, and non-power-of-two stripe widths.
The raid56 stripe allocation policy will be its first non-test user.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/free-space-cache.c | 165 +++++++++++++++++++++++
fs/btrfs/free-space-cache.h | 2 +
-From 54e8674b89c106739d94508eee48be798fca3d58 Mon Sep 17 00:00:00 2001
+From 00c9b45ed15d7316686132c812bc9942244ba2ff Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
-Subject: [RFC PATCH 02/85] btrfs: add open stripe run tracking for
+Subject: [RFC PATCH 02/86] btrfs: add open stripe run tracking for
stripe-exclusive allocation
To: linux-btrfs@vger.kernel.org
Exercised by a new sanity self-test; the raid56 stripe allocation
policy and the commit hook will be the first non-test users.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 343 ++++++++++++++++++++++++++++++
fs/btrfs/block-group.h | 26 +++
u64 bytenr);
void btrfs_dec_nocow_writers(struct btrfs_block_group *bg);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index c628c5081d923..ccefc67fcbd68 100644
+index 6afcd6ca2a8a8..164cda154f66e 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2803,6 +2803,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
-From 5c0d8a2033b534af23e2bad0e41dd8635374693d Mon Sep 17 00:00:00 2001
+From 3aed6f7719229a17fa8a2e28f1297fe44a5a1d78 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
-Subject: [RFC PATCH 03/85] btrfs: add the stripe_alloc allocation policy for
+Subject: [RFC PATCH 03/86] btrfs: add the stripe_alloc allocation policy for
raid56 data
To: linux-btrfs@vger.kernel.org
__btrfs_handle_fs_error() wakes the drain waiters, after the full barrier
wake_up_var() needs when the condition is not set under a lock.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 268 ++++++++++++++++++++++--------
fs/btrfs/block-group.h | 20 ++-
-From a5e9eaa5277931ed08c3260641b01c767d505fa6 Mon Sep 17 00:00:00 2001
+From e4bb83290aface63b197b12c5ef9b0a8d1aa0619 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
-Subject: [RFC PATCH 04/85] btrfs: stripe_alloc: control the policy with a
+Subject: [RFC PATCH 04/86] btrfs: stripe_alloc: control the policy with a
filesystem property
To: linux-btrfs@vger.kernel.org
property change made after the context was created would be undone
without its enable or disable work.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 70 ++++++++++++++++++++++++++
fs/btrfs/block-group.h | 3 ++
void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg);
void btrfs_release_data_reloc_bg(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index ccefc67fcbd68..b1df5fd84a94f 100644
+index 164cda154f66e..dbaef84feefc3 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -47,6 +47,7 @@
-From 5dd1fc6bf065a109a19c30107069f65664b96424 Mon Sep 17 00:00:00 2001
+From 46c71836e61902b340cf4367124633c173166229 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
-Subject: [RFC PATCH 05/85] btrfs: report stripe run data IO through the
+Subject: [RFC PATCH 05/86] btrfs: report stripe run data IO through the
ordered extent lifecycle
To: linux-btrfs@vger.kernel.org
- Preallocated extents never issue data IO and report at insertion;
this also covers relocation's data inode preallocations.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 51 ++++++++++++++++++++++++++++++++++++++
fs/btrfs/block-group.h | 4 +++
const struct extent_buffer *eb);
int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b071ed59a583f..5803f5d95d654 100644
+index abaa334714566..3230a5f54f7e0 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3398,7 +3398,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
ordered_extent->disk_bytenr,
ordered_extent->disk_num_bytes, true);
/*
-@@ -9198,6 +9198,17 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9195,6 +9195,17 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
min_size, 0, *alloc_hint, &ins, true, false);
if (ret)
break;
/*
* We've reserved this space, and thus converted it from
-@@ -9220,8 +9231,8 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9217,8 +9228,8 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
btrfs_dec_block_group_reservations(fs_info, ins.objectid);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
-From 90328f8ca40d0895a8e06a8885909979e47d6eee Mon Sep 17 00:00:00 2001
+From 5a34f8f8c7596f6822cc20cf229f54bb4ee0dbe5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:26 -0400
-Subject: [RFC PATCH 06/85] btrfs: retire stripe runs at commit and gate
+Subject: [RFC PATCH 06/86] btrfs: retire stripe runs at commit and gate
stripe_alloc
To: linux-btrfs@vger.kernel.org
file waits for up to max_extent_size of IO that the allocation had already
committed to.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 144 +++++++++++++++++++-----------
fs/btrfs/block-group.h | 8 +-
}
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 5803f5d95d654..b66dd823053f1 100644
+index 3230a5f54f7e0..e8ddf098d2d39 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1869,6 +1869,18 @@ static int can_nocow_file_extent(struct btrfs_path *path,
/* Only partially filled stripes remain: nothing left to claim. */
ret = btrfs_alloc_from_open_stripe(cache, sectorsize,
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index d265fac023e58..c2e9a4fd69d3b 100644
+index cd7dff5ba59b6..f25350b7e5fd6 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -367,6 +367,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
/* wait for commit against the current transaction to become unblocked
* when this is done, it is safe to start a new transaction, but the current
* transaction might not be fully on disk.
-@@ -2426,6 +2452,27 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2421,6 +2447,27 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
wait_event(cur_trans->pending_wait,
atomic_read(&cur_trans->pending_ordered) == 0);
-From 38248cd7451a2ab3525d133fa661462db65c9f4f Mon Sep 17 00:00:00 2001
+From 263e48f3a677953c4d7e9f9b0af41797fb6c6c9e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:27 -0400
-Subject: [RFC PATCH 07/85] btrfs: account stripe_alloc trapped free space for
+Subject: [RFC PATCH 07/86] btrfs: account stripe_alloc trapped free space for
honest statfs
To: linux-btrfs@vger.kernel.org
allocation cluster the legacy allocator set up are returned to the group
before the scan, when arming and at the commit-time rescan.
-Assisted-by: Claude:claude-opus-4-8
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 164 ++++++++++++++++++++++-
fs/btrfs/block-group.h | 19 +++
NULL,
};
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index c2e9a4fd69d3b..4f781df772202 100644
+index f25350b7e5fd6..b3f4b186935e8 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
-@@ -2684,6 +2684,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2679,6 +2679,12 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
if (unlikely(ret))
goto scrub_continue;
-From 0e2243bd9a29d331bf39433f9651464ef445416f Mon Sep 17 00:00:00 2001
+From 5641d16585fad171cb99fd54410279a844f75a4f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:27 -0400
-Subject: [RFC PATCH 08/85] btrfs: stripe_alloc: keep an open run per size band
+Subject: [RFC PATCH 08/86] btrfs: stripe_alloc: keep an open run per size band
to trap less
To: linux-btrfs@vger.kernel.org
the cache) and a later small allocation backfills it, so fewer stripes are
claimed before the free space is exhausted.
-Assisted-by: Claude:claude-opus-4-8
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 146 ++++++++++++++++++++++--------
fs/btrfs/block-group.h | 13 ++-
-From 38f0f97adcd4fa6d4d124e8bc7846a41b974a7db Mon Sep 17 00:00:00 2001
+From d084d3cd17b754cd68a4f2c1eb3bd76afa293339 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:27 -0400
-Subject: [RFC PATCH 09/85] btrfs: stripe_alloc: grow the frontier run instead
+Subject: [RFC PATCH 09/86] btrfs: stripe_alloc: grow the frontier run instead
of stranding its tail
To: linux-btrfs@vger.kernel.org
the relocation-class case doubles as a check that a claim adjacent to
another class's run never grows it.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 42 +++++++++++++++++++---
fs/btrfs/tests/free-space-tests.c | 60 +++++++++++++++++--------------
-From 9a0221ec59bc5466fff131a68edd4fe72da935d1 Mon Sep 17 00:00:00 2001
+From 97651f55b054c50a0c57077a878b691906403647 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:29 -0400
-Subject: [RFC PATCH 10/85] btrfs: raid56: batch stripe_alloc partial writes
+Subject: [RFC PATCH 10/86] btrfs: raid56: batch stripe_alloc partial writes
into full-stripe writes
To: linux-btrfs@vger.kernel.org
sent down, and the park timer cancelled, before the raid56 workqueue is
destroyed.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 292 ++++++++++++++++++++++--------------
fs/btrfs/block-group.h | 3 +
int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info);
void btrfs_disable_stripe_alloc(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index b1df5fd84a94f..28f360e84f110 100644
+index dbaef84feefc3..c16c4e8fe3cba 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3846,6 +3846,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
btrfs_stop_all_workers(fs_info);
btrfs_free_block_groups(fs_info);
fail_alloc:
-@@ -4608,6 +4609,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
+@@ -4604,6 +4605,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
* submit after we stop all workers.
*/
invalidate_and_check_btree_folios(fs_info);
}
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 7dd937fa0c262..71ff75c8c93ff 100644
+index a8a8004bb14c7..3aea63a986742 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -21,6 +21,7 @@
spin_unlock(&cur->bio_list_lock);
freeit = rbio;
ret = 1;
-@@ -1031,6 +1312,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
+@@ -1024,6 +1305,7 @@ static struct btrfs_raid_bio *alloc_rbio(struct btrfs_fs_info *fs_info,
spin_lock_init(&rbio->bio_list_lock);
INIT_LIST_HEAD(&rbio->stripe_cache);
INIT_LIST_HEAD(&rbio->hash_list);
btrfs_get_bioc(bioc);
rbio->bioc = bioc;
rbio->nr_pages = num_pages;
-@@ -1721,12 +2003,15 @@ static void raid_unplug(struct blk_plug_cb *cb, bool from_schedule)
+@@ -1714,12 +1996,15 @@ static void raid_unplug(struct blk_plug_cb *cb, bool from_schedule)
free_raid_bio(cur);
continue;
}
kfree(plug);
}
-@@ -2472,8 +2757,11 @@ static void rmw_rbio_work(struct work_struct *work)
+@@ -2483,8 +2768,11 @@ static void rmw_rbio_work(struct work_struct *work)
struct btrfs_raid_bio *rbio;
rbio = container_of(work, struct btrfs_raid_bio, work);
-From 72dcaf543ee045269a9d09cc1b25887fa6227e0d Mon Sep 17 00:00:00 2001
+From aa7183b5ec88b2f9cef35f6a12b00e7959adcef1 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:31 -0400
-Subject: [RFC PATCH 11/85] btrfs: stripe_alloc: private per-inode stripe runs
+Subject: [RFC PATCH 11/86] btrfs: stripe_alloc: private per-inode stripe runs
for log-active inodes
To: linux-btrfs@vger.kernel.org
instead so every open run, slotted or private, is closed and drained
under invariant I2 (no open run survives a transaction commit).
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 154 ++++++++++++++++++++++++++++++++++++-----
fs/btrfs/block-group.h | 11 +++
u64 num_bytes);
void btrfs_open_stripe_write_done_run(struct btrfs_open_stripe_run *run,
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
-index f7aa0d1451851..a3aab18d60337 100644
+index 0782f917fcccb..7515ed6b90ba6 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -87,6 +87,16 @@ enum {
/*
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index b66dd823053f1..3190191b41d6d 100644
+index e8ddf098d2d39..80efdd9f3014b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1070,7 +1070,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
spin_lock_init(&ei->lock);
ei->outstanding_extents = 0;
-@@ -9278,7 +9280,7 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9275,7 +9277,7 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
* sized chunks.
*/
cur_bytes = min(cur_bytes, last_alloc);
min_size, 0, *alloc_hint, &ins, true, false);
if (ret)
break;
-@@ -10115,7 +10117,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10112,7 +10114,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
}
}
-From bc8976c3642036cfdb102312af296f4c31450d4f Mon Sep 17 00:00:00 2001
+From 3bd13f8c8d842412359afc83ed36b8a6ff169245 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:38 -0400
-Subject: [RFC PATCH 12/85] btrfs: raid56: pad sub-stripe writes to full
+Subject: [RFC PATCH 12/86] btrfs: raid56: pad sub-stripe writes to full
stripes in open runs
To: linux-btrfs@vger.kernel.org
its bits in under that lock, and a lost pad bit would leave rows out of
the write while the cached stripe marks their zero-filled pages up to date.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 43 ++++++++++++++++++
fs/btrfs/block-group.h | 3 ++
int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info);
void btrfs_disable_stripe_alloc(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 71ff75c8c93ff..49c1163bc1f28 100644
+index 3aea63a986742..1fc098bf87be2 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -45,6 +45,15 @@
/*
* Set when an unplug callback finished merging this rbio's submission
* batch: the submitter has no more bios coming. A sync rbio past this
-@@ -1688,7 +1697,12 @@ static int rmw_assemble_write_bios(struct btrfs_raid_bio *rbio,
+@@ -1681,7 +1690,12 @@ static int rmw_assemble_write_bios(struct btrfs_raid_bio *rbio,
continue;
if (stripe < rbio->nr_data) {
if (paddrs == NULL)
continue;
} else {
-@@ -2643,6 +2657,79 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+@@ -2636,6 +2650,79 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
}
}
/*
* To determine if we need to read any sector from the disk.
* Should only be utilized in RMW path, to skip cached rbio.
-@@ -2684,8 +2771,15 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2677,8 +2764,15 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
/*
* Either full stripe write, or we have every data sector already
* cached, can go to write path immediately.
-From cebc5592ab68c4ab3067f4c832a57fdea905722c Mon Sep 17 00:00:00 2001
+From 08f51801f9a1ce325cc194543944d65f761d793c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:43 -0400
-Subject: [RFC PATCH 13/85] btrfs: raid56: expose parking statistics in sysfs
+Subject: [RFC PATCH 13/86] btrfs: raid56: expose parking statistics in sysfs
To: linux-btrfs@vger.kernel.org
/sys/fs/btrfs/<uuid>/stripe_park_stats reports lifetime counters for
capture -- so any future retuning (or an adaptive deadline) can argue
from measurements instead of taste.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/fs.h | 14 ++++++++++++++
fs/btrfs/raid56.c | 16 ++++++++++++++++
struct mutex scrub_lock;
atomic_t scrubs_running;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 49c1163bc1f28..a9fac8fc28e4f 100644
+index 1fc098bf87be2..1c524bde24a4d 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -62,6 +62,9 @@
start_async_work(rbio, rmw_rbio_work_locked);
}
if (rearm)
-@@ -2727,6 +2738,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2720,6 +2731,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
spin_lock(&rbio->bio_list_lock);
bitmap_set(&rbio->dbitmap, 0, rbio->stripe_nsectors);
spin_unlock(&rbio->bio_list_lock);
return true;
}
-@@ -2780,6 +2792,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2773,6 +2785,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
*/
if (!rbio_is_full(rbio) && !rmw_try_pad_full(rbio) &&
need_read_stripe_sectors(rbio)) {
-From f1536f5012fef160581f7103b7a4f43224eea5c7 Mon Sep 17 00:00:00 2001
+From ac8d30533e5e2b20b485521e3a63711cad6c5607 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:45 -0400
-Subject: [RFC PATCH 14/85] btrfs: stripe_alloc: count open stripe run
+Subject: [RFC PATCH 14/86] btrfs: stripe_alloc: count open stripe run
remainders against data reservations
To: linux-btrfs@vger.kernel.org
(8532 blocks) and tree 'c' 30% (62371 blocks) to silent writeback
allocation failure as trapping compounded.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 51 +++++++++++++++++++++++++++++++++++++++++-
fs/btrfs/block-group.h | 8 +++++++
-From 406db25e00c5ace70157c961876b333ff0ff9752 Mon Sep 17 00:00:00 2001
+From b1343709a8f47bd2f20eb0768db80fc4b21191f7 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:46 -0400
-Subject: [RFC PATCH 15/85] btrfs: stripe_alloc: pessimistic data reservation
+Subject: [RFC PATCH 15/86] btrfs: stripe_alloc: pessimistic data reservation
margin
To: linux-btrfs@vger.kernel.org
delalloc drains the counter (charges are gated on the policy,
releases are not, and the counter clamps at zero).
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 6 ++++
fs/btrfs/btrfs_inode.h | 3 ++
}
}
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
-index a3aab18d60337..663e925b14300 100644
+index 7515ed6b90ba6..93c256a68c242 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -423,6 +423,8 @@ static inline bool is_data_inode(const struct btrfs_inode *inode)
spinlock_t swapfile_pins_lock;
struct rb_root swapfile_pins;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 3190191b41d6d..d27cc1155adf9 100644
+index 80efdd9f3014b..82221e32a8a67 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5099,6 +5099,7 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
-From c53ebde40f2c1d2e7ff3320305c45c77e825b408 Mon Sep 17 00:00:00 2001
+From 9e70c7e8da076da5b8de44253b8dbe64ff7cb688 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:47 -0400
-Subject: [RFC PATCH 16/85] btrfs: stripe_alloc: claim fully-free stripes that
+Subject: [RFC PATCH 16/86] btrfs: stripe_alloc: claim fully-free stripes that
span free space entries
To: linux-btrfs@vger.kernel.org
taken, so a failed allocation cannot lose it from the cache; without a
spare it is added after the lock as before.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 1 +
fs/btrfs/block-group.h | 12 ++
-From 59646fb2be214b885116d4fc5277664960250167 Mon Sep 17 00:00:00 2001
+From 8dfdd56cc3889c9bb9dcdcfd8ca00ac44a2645a6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:47 -0400
-Subject: [RFC PATCH 17/85] btrfs: stripe_alloc: warn when raid56 metadata is
+Subject: [RFC PATCH 17/86] btrfs: stripe_alloc: warn when raid56 metadata is
not covered
To: linux-btrfs@vger.kernel.org
its own, and a filesystem can be converted to raid1c3/raid1c4 metadata
without unmounting.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
-From 4d1558d6fa3ff13a54ef69beecb2ededd8816d3b Mon Sep 17 00:00:00 2001
+From 4e62481e9d68003cf9dd6acaed025a6df09a29e4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:48 -0400
-Subject: [RFC PATCH 18/85] btrfs: stripe_alloc: report read-modify-write of
+Subject: [RFC PATCH 18/86] btrfs: stripe_alloc: report read-modify-write of
uncovered stripes
To: linux-btrfs@vger.kernel.org
Silent when stripe_alloc is off: there the whole filesystem works this
way and the user has asked for nothing else.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/raid56.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index a9fac8fc28e4f..2b54bb70f6d2f 100644
+index 1c524bde24a4d..27cba16c34120 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2766,6 +2766,27 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+@@ -2759,6 +2759,27 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
return false;
}
static void rmw_rbio(struct btrfs_raid_bio *rbio)
{
struct bio_list bio_list;
-@@ -2811,6 +2832,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2804,6 +2825,10 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
goto out;
}
-From 387b1af89ded50a341b2da77ee25fa3809e10ea1 Mon Sep 17 00:00:00 2001
+From 8fbba78bdcbbebf2247086b1441a90543b3c15fa Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:50 -0400
-Subject: [RFC PATCH 19/85] btrfs: stripe_alloc: tunable park deadlines, and
+Subject: [RFC PATCH 19/86] btrfs: stripe_alloc: tunable park deadlines, and
say why padding declined
To: linux-btrfs@vger.kernel.org
No behaviour change at the defaults.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 22 ++++++++++++++++++++--
fs/btrfs/disk-io.c | 2 ++
return ret;
}
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 28f360e84f110..0b23e576ed4ed 100644
+index c16c4e8fe3cba..67776888ea3e1 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2805,6 +2805,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
/* Private scrub information */
struct mutex scrub_lock;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 2b54bb70f6d2f..b92712b13294b 100644
+index 27cba16c34120..c0fa12005206f 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -67,8 +67,6 @@
spin_lock(&table->parked_lock);
if (test_bit(RBIO_PARKED_BIT,
-@@ -2813,10 +2818,17 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -2806,10 +2811,17 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
*/
if (!rbio_is_full(rbio) && !rmw_try_pad_full(rbio) &&
need_read_stripe_sectors(rbio)) {
-From b7418073639203b116bc9ee2e125879e4cab1733 Mon Sep 17 00:00:00 2001
+From bd6ea24e29f154a33046ab8fd96ec4c427350b95 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:51 -0400
-Subject: [RFC PATCH 20/85] btrfs: stripe_alloc: trace why padding declined, at
+Subject: [RFC PATCH 20/86] btrfs: stripe_alloc: trace why padding declined, at
the moment it declined
To: linux-btrfs@vger.kernel.org
directly whether the frontier had already run past the stripe when the
write showed up.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 19 +++++++++++++++-
fs/btrfs/block-group.h | 23 ++++++++++++++++++-
/*
* Park deadlines, ms (sysfs); 0 disables parking for that class. See
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index b92712b13294b..e54f73cb641f4 100644
+index c0fa12005206f..bec90a0cd5d91 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2688,20 +2688,40 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2681,20 +2681,40 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
const u64 stripe_start = rbio->bioc->full_stripe_logical;
const u32 sectorsize = fs_info->sectorsize;
const u64 stripe_len = (u64)rbio->nr_data * rbio->bioc->stripe_len;
const int stripe_nr = i / rbio->stripe_nsectors;
const int sectornr = i % rbio->stripe_nsectors;
u64 logical = stripe_start + stripe_nr * BTRFS_STRIPE_LEN +
-@@ -2709,8 +2729,19 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2702,8 +2722,19 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
continue;
-From 6820ba5fd5d604cec20c20bd0d632ddc9337b2d7 Mon Sep 17 00:00:00 2001
+From f7452696e902783738a4a20ee50ba4e0da4efb5c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:52 -0400
-Subject: [RFC PATCH 21/85] btrfs: stripe_alloc: complete parked writes on
+Subject: [RFC PATCH 21/86] btrfs: stripe_alloc: complete parked writes on
allocation coverage, not clocks
To: linux-btrfs@vger.kernel.org
New sysfs stripe_park_stats counters: unparked_ready (parks completed by
the coverage test) and stuck (parks forced at the cap).
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 41 +++++++++++++++-
fs/btrfs/block-group.h | 2 +
test_bit(BTRFS_ORDERED_COMPLETE,
&entry->flags),
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index e54f73cb641f4..da8abb516afb8 100644
+index bec90a0cd5d91..07d9d54de751f 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -65,6 +65,13 @@
-From ac7145c02402d97f770bed05d22d3fa320599eaf Mon Sep 17 00:00:00 2001
+From 2bbf52c0fc405c1bacba2eccb695eb6b0b210f15 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:53 -0400
-Subject: [RFC PATCH 22/85] btrfs: stripe_alloc: track per-sector liveness and
+Subject: [RFC PATCH 22/86] btrfs: stripe_alloc: track per-sector liveness and
pad from the map
To: linux-btrfs@vger.kernel.org
refusal reasons, which only the frontier oracle produced, go; padding now
declines only for NO_RUN and UNCOVERED.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 262 ++++++++++++++++++++++++++++++------
fs/btrfs/block-group.h | 11 +-
* given a cluster, put all of its extents back into the free space
* cache. If a block group is passed, this function will only free
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index da8abb516afb8..a9068fca6b240 100644
+index 07d9d54de751f..910c6f7794ffb 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2175,6 +2175,7 @@ void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc)
+@@ -2168,6 +2168,7 @@ void raid56_parity_write(struct bio *bio, struct btrfs_io_context *bioc)
rbio->operation = BTRFS_RBIO_WRITE;
rbio_add_bio(rbio, bio);
/*
* Don't plug on full rbios, just get them out the door
* as quickly as we can
-@@ -2757,75 +2758,78 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+@@ -2750,75 +2751,78 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
}
/*
-From d8b93fda68ac47db25b073220c90b369ab09170b Mon Sep 17 00:00:00 2001
+From 3e8bbdf9b5376b1d44357109ea6c80a93081b8a9 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:54 -0400
-Subject: [RFC PATCH 23/85] btrfs: stripe_alloc: count claimable whole-stripe
+Subject: [RFC PATCH 23/86] btrfs: stripe_alloc: count claimable whole-stripe
supply directly
To: linux-btrfs@vger.kernel.org
both "remove" the same tail and hand out the same extent. A self-test
claims the same tail twice.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 31 ++++-
fs/btrfs/block-group.h | 10 ++
-From d5cf72426bd3a1acbbf21e2f210ac5e87cb8f7a4 Mon Sep 17 00:00:00 2001
+From 44f60282aef09621633a26ba337d93e605b94571 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:55 -0400
-Subject: [RFC PATCH 24/85] btrfs: raid56: adaptive park deadline from the
+Subject: [RFC PATCH 24/86] btrfs: raid56: adaptive park deadline from the
parked-rbio backlog
To: linux-btrfs@vger.kernel.org
change: a shortened park still pads or reads exactly as it would have, only
sooner.
-Assisted-by: Claude:claude-opus-4-8
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/fs.h | 5 +++++
fs/btrfs/raid56.c | 21 +++++++++++++++++++++
/* Private scrub information */
struct mutex scrub_lock;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index a9068fca6b240..f27215f8a4017 100644
+index 910c6f7794ffb..bbb4308a16cfd 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -717,6 +717,7 @@ static void rbio_unpark_locked(struct btrfs_raid_bio *rbio)
-From 961fd368e3fbfa54791cc92b36e3305cfd29ea95 Mon Sep 17 00:00:00 2001
+From 99655819fc7d9a4e0234e1e51f76e147ad75387b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:56 -0400
-Subject: [RFC PATCH 25/85] btrfs: stripe_alloc: gate data admission on
+Subject: [RFC PATCH 25/86] btrfs: stripe_alloc: gate data admission on
claimable whole-stripe supply
To: linux-btrfs@vger.kernel.org
reservation path does not: a live device shrink must fail cleanly at
its reservation rather than grow the data space_info).
-Assisted-by: Claude:claude-opus-4-8
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 46 ++++++-
fs/btrfs/delalloc-space.c | 20 ++-
/* Block groups and devices containing active swapfiles. */
spinlock_t swapfile_pins_lock;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index d27cc1155adf9..1f2a1677aa10a 100644
+index 82221e32a8a67..7f769ad8db3a3 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -9952,6 +9952,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -9949,6 +9949,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
u64 num_bytes, ram_bytes, disk_num_bytes;
struct btrfs_key ins;
bool extent_reserved = false;
struct extent_map *em;
ssize_t ret;
-@@ -10093,7 +10094,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10090,7 +10091,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
* We don't use the higher-level delalloc space functions because our
* num_bytes and disk_num_bytes are different.
*/
if (ret)
goto out_unlock;
ret = btrfs_qgroup_reserve_data(inode, &data_reserved, start, num_bytes);
-@@ -10121,6 +10123,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10118,6 +10120,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
ret = btrfs_reserve_extent(root, inode, disk_num_bytes, disk_num_bytes,
disk_num_bytes, 0, 0, &ins, true, true);
if (ret)
goto out_delalloc_release;
extent_reserved = true;
-@@ -10169,6 +10173,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10166,6 +10170,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
if (ret < 0)
btrfs_qgroup_free_data(inode, data_reserved, start, num_bytes, NULL);
out_free_data_space:
-From 77979a1e01f45f2e6b9651e1c4ec9aba3388680d Mon Sep 17 00:00:00 2001
+From c21d5c6a51c2e7e314066171616c5b1cdc4acecf Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:16 -0400
-Subject: [RFC PATCH 26/85] btrfs: stripe_alloc: show per-group trapped bytes
+Subject: [RFC PATCH 26/86] btrfs: stripe_alloc: show per-group trapped bytes
in the space info dump
To: linux-btrfs@vger.kernel.org
available bytes. A group whose trapped bytes have not been counted yet
(stripe_unusable_ready not set) prints 0 and the old available figure.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/space-info.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
-From ab3d1172e1ef05b4aaec29389ca173379fab47b6 Mon Sep 17 00:00:00 2001
+From 449dfd26d389c92042e6e72599917c28ca818c9d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:19 -0400
-Subject: [RFC PATCH 27/85] btrfs: stripe_alloc: count whole stripes stranded
+Subject: [RFC PATCH 27/86] btrfs: stripe_alloc: count whole stripes stranded
behind live runs as trapped
To: linux-btrfs@vger.kernel.org
The scan does not restore the stripe_meta margin and reserve when
stripe_alloc was disabled after it started.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 86 +++++++++++++++++++++++++++++++------
fs/btrfs/block-group.h | 12 ++++++
-From 42a2d55cf0d1a42daf2b0e52b1dbfea8c106ff5d Mon Sep 17 00:00:00 2001
+From a1db622df6f181b4a34b828ccadcac14a4ed7434 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:20 -0400
-Subject: [RFC PATCH 28/85] btrfs: stripe_alloc: count nocow run lifecycles and
+Subject: [RFC PATCH 28/86] btrfs: stripe_alloc: count nocow run lifecycles and
stranded stripes in sysfs
To: linux-btrfs@vger.kernel.org
dead. The free path only clears bits under bg->stripe_run_lock.
nocow_run_dead_closed counts the closes.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 10 ++++++++--
fs/btrfs/fs.h | 11 +++++++++++
-From a970426e4778810f1fb11a61d9893f9d6867fdd3 Mon Sep 17 00:00:00 2001
+From c7a11a6c2872b3c59ae249619b6e0c797ed3556f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:25 -0400
-Subject: [RFC PATCH 29/85] btrfs: stripe_alloc: say at mount whether the
+Subject: [RFC PATCH 29/86] btrfs: stripe_alloc: say at mount whether the
policy is on
To: linux-btrfs@vger.kernel.org
Nothing is printed when the policy is off, which keeps the common mount
quiet and makes the absence of the line mean exactly one thing.
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/super.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
-From 1093cc1e885e8804cfc10e1528014a38e29c772c Mon Sep 17 00:00:00 2001
+From d1660f5c53c2e3cb9739fe7f32b0372bead413e0 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 00:57:50 -0400
-Subject: [RFC PATCH 30/85] btrfs: stripe_alloc: keep relocation's stripe runs
+Subject: [RFC PATCH 30/86] btrfs: stripe_alloc: keep relocation's stripe runs
until relocation ends
To: linux-btrfs@vger.kernel.org
The open stripe self-test frees the runs it leaves retained, as unmount
does.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 65 ++++++++++++++++++++++++++++++++++++++----
fs/btrfs/fs.h | 3 ++
-From 3f01056e9cf437ba083971c5e9d7abb87546e572 Mon Sep 17 00:00:00 2001
+From 72003bdac03adebdff243a2808103f9ba8b42255 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 12:14:49 -0400
-Subject: [RFC PATCH 31/85] btrfs: stripe_alloc: keep a stripe in the rbio
+Subject: [RFC PATCH 31/86] btrfs: stripe_alloc: keep a stripe in the rbio
cache until its run has written all of it
To: linux-btrfs@vger.kernel.org
run lock is held, since the run and its group can be freed once it is
dropped.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 157 ++++++++++++++++++++++++++++++++++++++--
fs/btrfs/block-group.h | 6 +-
static bool can_finish_ordered_extent(struct btrfs_ordered_extent *ordered,
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index f27215f8a4017..4b8854370ce1b 100644
+index bbb4308a16cfd..ea237b4a346a1 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -72,6 +72,17 @@
spin_unlock(&table->cache_lock);
}
-@@ -1291,6 +1398,10 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
+@@ -1294,6 +1401,10 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t status)
rbio->csum_buf = NULL;
rbio->csum_bitmap = NULL;
-From 7aaa8f1b809d96dec4c7d6efc27bc42289439e50 Mon Sep 17 00:00:00 2001
+From 57145e6448f6a9da02b0452044f7927d4c0bf680 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 2 Oct 2026 02:41:44 -0400
-Subject: [RFC PATCH 32/85] btrfs: stripe_alloc: pad a stripe's allocated
+Subject: [RFC PATCH 32/86] btrfs: stripe_alloc: pad a stripe's allocated
sectors whose write is still to come
To: linux-btrfs@vger.kernel.org
the inode lives) and are excluded. padded_unwritten in stripe_park_stats
counts the pads that zeroed such sectors.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 47 +++++++++++++++++++++++++-----------------
fs/btrfs/block-group.h | 1 +
* Data read-modify-writes in a covered block group, parked or
* not; zero with allow_rmw empty. rmw_reads counts only the
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 4b8854370ce1b..9245585a371b0 100644
+index ea237b4a346a1..da1307598f21b 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -2905,7 +2905,9 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2898,7 +2898,9 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
const u32 nsectors = rbio->nr_data * rbio->stripe_nsectors;
struct btrfs_stripe_pad_info info;
unsigned long *dead;
bool ok = false;
int i;
-@@ -2913,10 +2915,14 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2906,10 +2908,14 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
return false;
dead = bitmap_zalloc(nsectors, GFP_NOFS);
trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
stripe_len, 0, 0, nsectors,
info.run_start, info.run_end,
-@@ -2934,11 +2940,10 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2927,11 +2933,10 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
covered++;
/*
*/
for (i = 0; i < nsectors; i++) {
if (rbio->bio_paddrs[i * rbio->sector_nsteps] != INVALID_PADDR)
-@@ -2956,10 +2961,13 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2949,10 +2954,13 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
info.reason);
goto out;
}
if (!ok)
return false;
-@@ -2994,6 +3002,8 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -2987,6 +2995,8 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
bitmap_set(&rbio->dbitmap, 0, rbio->stripe_nsectors);
spin_unlock(&rbio->bio_list_lock);
atomic64_inc(&fs_info->stripe_park_stats.padded);
-From 450ed7f4243375fd35744e4305ce5e50f60c1ace Mon Sep 17 00:00:00 2001
+From da01defef21f07a729ba14e509b3f4098055f495 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 12:26:45 -0400
-Subject: [RFC PATCH 33/85] btrfs: stripe_alloc: count refused rbio pins and
+Subject: [RFC PATCH 33/86] btrfs: stripe_alloc: count refused rbio pins and
track rbio cache high water
To: linux-btrfs@vger.kernel.org
stripe_park_stats also has rbio_pin_swept and rbio_pin_commit_requests.
-Assisted-by: Claude:claude-opus-5-5
-Assisted-by: Claude:claude-fable-5
---
fs/btrfs/fs.h | 19 ++++++
fs/btrfs/raid56.c | 136 +++++++++++++++++++++++++++++++++++++++--
atomic64_t written_not_live;
} stripe_park_stats;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 9245585a371b0..3c702231c6f44 100644
+index da1307598f21b..7ac5d6479cf4a 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -80,8 +80,20 @@
spin_lock(&rbio->bio_list_lock);
/* bump our ref if we were not in the list before */
-@@ -3086,6 +3212,8 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -3079,6 +3205,8 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
* count that should be zero.
*/
atomic64_inc(&fs_info->stripe_park_stats.data_rmw);
BTRFS_ATTR(, stripe_park_stats, btrfs_stripe_park_stats_show);
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index 4f781df772202..6bbcf42121461 100644
+index b3f4b186935e8..c97e37951c2af 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -23,6 +23,7 @@
#include "space-info.h"
#include "fs.h"
#include "accessors.h"
-@@ -2472,6 +2473,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2467,6 +2468,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
* no-op when no stripe runs exist.
*/
btrfs_retire_open_stripes(fs_info, cur_trans);
-From f0c935dc1c822c96b7756632d5820b5e2ff3e3b9 Mon Sep 17 00:00:00 2001
+From c39dfd7b5e531bb483c4b6ef6c46084795188c73 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 10 Oct 2026 00:19:18 -0400
-Subject: [RFC PATCH 34/85] btrfs: stripe_alloc: skip RAID5/6 groups that are
+Subject: [RFC PATCH 34/86] btrfs: stripe_alloc: skip RAID5/6 groups that are
mapped as RAID1/RAID1C3
To: linux-btrfs@vger.kernel.org
cannot use them. The full-stripe widths the admission charge is taken
over leave these groups out, as their full stripe is one sector.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 25 ++++++++++++++----
fs/btrfs/block-group.h | 27 ++++++++++++++++++++
remainders. Claimed out of the free
space cache but not yet allocated;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index ce78a9441c64f..ae2d0a814d63e 100644
+index 3d4ef6725de0e..c0a75b974b8d6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -6593,6 +6593,27 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
+@@ -6605,6 +6605,27 @@ unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
return len;
}
static int btrfs_read_preferred(struct btrfs_chunk_map *map, int first, int num_stripes)
{
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index 75b1179776c80..bce6134218f48 100644
+index 891bc2432870a..fd057a44447bd 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
-@@ -803,6 +803,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev,
+@@ -802,6 +802,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev,
void btrfs_free_device(struct btrfs_device *device);
unsigned long btrfs_full_stripe_len(struct btrfs_fs_info *fs_info,
u64 logical);
-From e8b09057e186e8145de34006de1d726882937c03 Mon Sep 17 00:00:00 2001
+From 857157c303f240edee21f9f6b144fa8628c2e330 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 25 Oct 2026 06:27:49 -0400
-Subject: [RFC PATCH 35/85] btrfs: stripe_alloc: do not count a writeback
+Subject: [RFC PATCH 35/86] btrfs: stripe_alloc: do not count a writeback
ENOSPC drop's give-back as supply
To: linux-btrfs@vger.kernel.org
The counter is in sysfs (bytes_stripe_quarantine), in the space info
dump, and in the data writeback ENOSPC line; each drop logs the new total.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 12 +++++-
fs/btrfs/extent-tree.c | 13 +++++++
void btrfs_stripe_unmanaged_sync(struct btrfs_block_group *block_group);
void btrfs_block_group_rescan_stripe_unusable(struct btrfs_block_group *block_group);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 1f2a1677aa10a..5a36404d62d8f 100644
+index 7f769ad8db3a3..afa0ea5db0400 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1360,6 +1360,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
-From c5e7e44d3b410638918e88d8cc9f97918b558c48 Mon Sep 17 00:00:00 2001
+From 95957351e9567cf88b15e3a0158b266b9b950e03 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:39 -0400
-Subject: [RFC PATCH 36/85] btrfs: stripe_alloc: isolate nodatacow and
+Subject: [RFC PATCH 36/86] btrfs: stripe_alloc: isolate nodatacow and
preallocated extents by stripe
To: linux-btrfs@vger.kernel.org
runs, which is safe -- an extent that lands in a shared stripe simply
stays force-COWed when write-in-place arrives.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 6 ++--
fs/btrfs/block-group.h | 10 +++++++
struct extent_buffer *buf, bool full_backref);
int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 5a36404d62d8f..56e516441be7e 100644
+index afa0ea5db0400..336478ad199b4 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1072,7 +1072,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
if (ret < 0) {
*ret_alloc_size = cur_len;
return ret;
-@@ -9293,8 +9293,9 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
+@@ -9290,8 +9290,9 @@ int btrfs_prealloc_file_range(struct inode *inode, int mode,
* sized chunks.
*/
cur_bytes = min(cur_bytes, last_alloc);
if (ret)
break;
/*
-@@ -10133,7 +10134,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
+@@ -10130,7 +10131,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
}
ret = btrfs_reserve_extent(root, inode, disk_num_bytes, disk_num_bytes,
-From a69e33446c5071f8b1ec51725680c0c6018d6b13 Mon Sep 17 00:00:00 2001
+From 682cce8d9316608aa650220109edf31475ea6771 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:20 -0400
-Subject: [RFC PATCH 37/85] btrfs: stripe_alloc: count nocow run lifecycles and
+Subject: [RFC PATCH 37/86] btrfs: stripe_alloc: count nocow run lifecycles and
stranded stripes in sysfs (allow_rmw part)
To: linux-btrfs@vger.kernel.org
stripe" is in, instead of with the rest of "btrfs: stripe_alloc: count
nocow run lifecycles and stranded stripes in sysfs".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 2 ++
1 file changed, 2 insertions(+)
-From 0d4a5956944659eaf614e92e4457eb4818133dbd Mon Sep 17 00:00:00 2001
+From 59f2a99e3339f631c6f62c0629534ad35947b668 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 12:14:49 -0400
-Subject: [RFC PATCH 38/85] btrfs: stripe_alloc: keep a stripe in the rbio
+Subject: [RFC PATCH 38/86] btrfs: stripe_alloc: keep a stripe in the rbio
cache until its run has written all of it (allow_rmw part)
To: linux-btrfs@vger.kernel.org
stripe" is in, instead of with the rest of "btrfs: stripe_alloc: keep a
stripe in the rbio cache until its run has written all of it".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 2 ++
1 file changed, 2 insertions(+)
-From 7aae3e102d63ae77c7c24d64c3d472708641092b Mon Sep 17 00:00:00 2001
+From 49d8dca3a2558a961dfec04e2cb791b1f53579b5 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 2 Oct 2026 02:41:44 -0400
-Subject: [RFC PATCH 39/85] btrfs: stripe_alloc: pad a stripe's allocated
+Subject: [RFC PATCH 39/86] btrfs: stripe_alloc: pad a stripe's allocated
sectors whose write is still to come (allow_rmw part)
To: linux-btrfs@vger.kernel.org
stripe" is in, instead of with the rest of "btrfs: stripe_alloc: pad a
stripe's allocated sectors whose write is still to come".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 1 +
1 file changed, 1 insertion(+)
-From 0437ebeb84516f0d77b626d5ec03d23100ca56a5 Mon Sep 17 00:00:00 2001
+From d687d8628a81c64bdb86b015f8272a4bd87275bc Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:40 -0400
-Subject: [RFC PATCH 40/85] btrfs: stripe_alloc: allow-rmw policy, and
+Subject: [RFC PATCH 40/86] btrfs: stripe_alloc: allow-rmw policy, and
write-in-place for isolated nocow extents
To: linux-btrfs@vger.kernel.org
EXTENT_DATA_REF item (the leaf had no room to grow the item) has none, and
counts as not owned.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 240 ++++++++++++++++++++++++++++++++++++++++-
fs/btrfs/block-group.h | 12 +++
{
clear_and_wake_up_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 56e516441be7e..60c44c371d6bd 100644
+index 336478ad199b4..0af674f204dbc 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1888,9 +1888,19 @@ static int can_nocow_file_extent(struct btrfs_path *path,
int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 3c702231c6f44..1dea8aa3ef539 100644
+index 7ac5d6479cf4a..6df54ae555c9b 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1000,8 +1000,11 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
-From cafd58d8083939417609bbb04bd6816fef59f62f Mon Sep 17 00:00:00 2001
+From c97275bdab83c1ae6c22c46b80489208154dd8da Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:50 -0400
-Subject: [RFC PATCH 41/85] btrfs: stripe_alloc: tunable park deadlines, and
+Subject: [RFC PATCH 41/86] btrfs: stripe_alloc: tunable park deadlines, and
say why padding declined (allow_rmw part)
To: linux-btrfs@vger.kernel.org
isolated nocow extents" is in, instead of with the rest of "btrfs:
stripe_alloc: tunable park deadlines, and say why padding declined".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/raid56.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 1dea8aa3ef539..169e1cccd73cd 100644
+index 6df54ae555c9b..f458014e85792 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1022,7 +1022,7 @@ static bool rbio_try_park(struct btrfs_raid_bio *rbio)
-From ee51d53e1180106cedb240a3133381863b5ef054 Mon Sep 17 00:00:00 2001
+From 71b9db1fb04d771cba8479b664e1e5d7a727129a Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:53 -0400
-Subject: [RFC PATCH 42/85] btrfs: stripe_alloc: track per-sector liveness and
+Subject: [RFC PATCH 42/86] btrfs: stripe_alloc: track per-sector liveness and
pad from the map (allow_rmw part)
To: linux-btrfs@vger.kernel.org
isolated nocow extents" is in, instead of with the rest of "btrfs:
stripe_alloc: track per-sector liveness and pad from the map".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
-From 17c29738aeed56dea82bcc78e661387c315c5e27 Mon Sep 17 00:00:00 2001
+From e465e48a55b7342b8de92ccde32c6821ec9a93a6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:41 -0400
-Subject: [RFC PATCH 43/85] btrfs: stripe_alloc: persist nocow runs across
+Subject: [RFC PATCH 43/86] btrfs: stripe_alloc: persist nocow runs across
commits and remounts
To: linux-btrfs@vger.kernel.org
inode's own and the write falls back to COW, which a NOWAIT write refuses
with -EAGAIN.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 336 +++++++++++++++++++++++++++++-
fs/btrfs/block-group.h | 14 +-
atomic64_t reloc_run_retained;
atomic64_t reloc_run_released;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 60c44c371d6bd..8b7fd4704349a 100644
+index 0af674f204dbc..cc1dabf910591 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1900,7 +1900,8 @@ static int can_nocow_file_extent(struct btrfs_path *path,
-From fc70bed6ee5389cfaa680f350387c570fae0567d Mon Sep 17 00:00:00 2001
+From fb1ac0bc8a7a5c3ec104e094b0dd80f887cffa08 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:45 -0400
-Subject: [RFC PATCH 44/85] btrfs: stripe_alloc: count open stripe run
+Subject: [RFC PATCH 44/86] btrfs: stripe_alloc: count open stripe run
remainders against data reservations (allow_rmw part)
To: linux-btrfs@vger.kernel.org
instead of with the rest of "btrfs: stripe_alloc: count open stripe run
remainders against data reservations".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 1 +
1 file changed, 1 insertion(+)
-From d7415060a9e2c225a14c877d1d6e26568a78b984 Mon Sep 17 00:00:00 2001
+From 4e250f77964d8705199ed51f1e3148fe0225b6b6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:06 -0400
-Subject: [RFC PATCH 45/85] btrfs: stripe_alloc: hand groups full of trapped
+Subject: [RFC PATCH 45/86] btrfs: stripe_alloc: hand groups full of trapped
free space to the reclaim worker
To: linux-btrfs@vger.kernel.org
The stripe_meta block group part of this change moved to
"btrfs: stripe_meta: extend stripe reclaim to metadata block groups".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 94 +++++++++++++++++++++++++++++++++++--
fs/btrfs/block-group.h | 4 +-
-From 5597aa5fed5c31b4b3138152b8fcae6cdc20e028 Mon Sep 17 00:00:00 2001
+From 50dfc82d544d4c26e6fd40d75a509389993027da Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:19 -0400
-Subject: [RFC PATCH 46/85] btrfs: stripe_alloc: count whole stripes stranded
+Subject: [RFC PATCH 46/86] btrfs: stripe_alloc: count whole stripes stranded
behind live runs as trapped (reclaim part)
To: linux-btrfs@vger.kernel.org
to the reclaim worker" is in, instead of with the rest of "btrfs:
stripe_alloc: count whole stripes stranded behind live runs as trapped".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/free-space-cache.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
-From 47e107d59d085279c4b94662f59a916745cce5c7 Mon Sep 17 00:00:00 2001
+From 4c21fe03a1a989245bdb2bcc7fdc33b7fde4fbf6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 29 Sep 2026 05:29:38 -0400
-Subject: [RFC PATCH 47/85] btrfs: stripe_alloc: compact mostly live groups
+Subject: [RFC PATCH 47/86] btrfs: stripe_alloc: compact mostly live groups
instead of skipping them
To: linux-btrfs@vger.kernel.org
The stripe_meta block group part of this change moved to
"btrfs: stripe_meta: extend stripe reclaim to metadata block groups".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 42 +++++-
fs/btrfs/disk-io.c | 1 +
btrfs_dec_block_group_ro(bg);
btrfs_debug(fs_info, "deferring reclaim of chunk %llu", bg->start);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 0b23e576ed4ed..7a882a47829c4 100644
+index 67776888ea3e1..0d7906bea0c61 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2806,6 +2806,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
NULL,
};
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index ae2d0a814d63e..c9f81b0975fe0 100644
+index c0a75b974b8d6..ea98cef92dc3d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -3737,7 +3737,8 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
+@@ -3749,7 +3749,8 @@ static int btrfs_relocate_chunk_finish(struct btrfs_fs_info *fs_info,
return ret;
}
{
struct btrfs_block_group *block_group;
int ret;
-@@ -3764,7 +3765,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
+@@ -3776,7 +3777,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
/* step one, relocate all the extents inside this chunk */
btrfs_scrub_pause(fs_info);
btrfs_scrub_continue(fs_info);
if (ret) {
/*
-@@ -3776,6 +3777,10 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
+@@ -3788,6 +3789,10 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
return ret;
}
block_group = btrfs_lookup_block_group(fs_info, chunk_offset);
if (!block_group)
return -ENOENT;
-@@ -3791,6 +3796,25 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
+@@ -3803,6 +3808,25 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
return ret;
}
{
struct btrfs_root *chunk_root = fs_info->chunk_root;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
-index bce6134218f48..f57b73ae996bc 100644
+index fd057a44447bd..89cd915ea503e 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
-@@ -787,6 +787,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
+@@ -786,6 +786,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info);
int btrfs_pause_balance(struct btrfs_fs_info *fs_info);
int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset,
bool verbose);
-From ce90272a1e42dbd3b8cb55d8caf659b53f2218c4 Mon Sep 17 00:00:00 2001
+From 1f926d1edc4c12784201a0d0c816a2e8aebdf62f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 00:57:50 -0400
-Subject: [RFC PATCH 48/85] btrfs: stripe_alloc: keep relocation's stripe runs
+Subject: [RFC PATCH 48/86] btrfs: stripe_alloc: keep relocation's stripe runs
until relocation ends (reclaim part)
To: linux-btrfs@vger.kernel.org
in, instead of with the rest of "btrfs: stripe_alloc: keep relocation's
stripe runs until relocation ends".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/sysfs.c | 4 ++++
1 file changed, 4 insertions(+)
-From 5e7bdfed533872a8dcf42c0bf0c61093e904e7d0 Mon Sep 17 00:00:00 2001
+From a74d8a8889f6062bd6270534d16c60bb3971c3bb Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 13:04:19 -0400
-Subject: [RFC PATCH 49/85] btrfs: stripe_alloc: log compaction and trapped
+Subject: [RFC PATCH 49/86] btrfs: stripe_alloc: log compaction and trapped
bytes in the reclaim log
To: linux-btrfs@vger.kernel.org
relocation, and an octopus replace stalled behind a reclaim the log did not
explain.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
-From b2f61eea4161613ad769f238ca4e3a577933db32 Mon Sep 17 00:00:00 2001
+From 63a86ba3758d8eeef11e9488730609861f0989c1 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 20 Oct 2026 14:41:37 -0400
-Subject: [RFC PATCH 50/85] btrfs: stripe_alloc: add stripe_reclaim_now to
+Subject: [RFC PATCH 50/86] btrfs: stripe_alloc: add stripe_reclaim_now to
reclaim stripes on demand
To: linux-btrfs@vger.kernel.org
The stripe_meta block group part of this change moved to
"btrfs: stripe_meta: extend stripe reclaim to metadata block groups".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 164 +++++++++++++++++++++++++++++++++++-
fs/btrfs/block-group.h | 7 ++
-From 09ecfab617ebaa1cb76f626ebe7c752342436e7f Mon Sep 17 00:00:00 2001
+From 01ac2f5d66a2cedb2a963aa277dec37f79138e03 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 04:02:52 -0400
-Subject: [RFC PATCH 51/85] btrfs: stripe_alloc: back off stripe reclaim after
+Subject: [RFC PATCH 51/86] btrfs: stripe_alloc: back off stripe reclaim after
repeated ENOSPC
To: linux-btrfs@vger.kernel.org
(reclaim_backoffs +1), then resumed. stripe-reclaim-test and
stripe-reclaim-now-test pass.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 9 ++++++---
fs/btrfs/free-space-cache.c | 34 +++++++++++++++++++++++++++++++++-
-From c76ecce44b21c74f5e253d032b848547a34165c8 Mon Sep 17 00:00:00 2001
+From be59354e5d64390d55076dadfa9d50a33705e205 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:31 -0400
-Subject: [RFC PATCH 52/85] btrfs: stripe_alloc: settle a logged extent's
+Subject: [RFC PATCH 52/86] btrfs: stripe_alloc: settle a logged extent's
stripes at log commit
To: linux-btrfs@vger.kernel.org
for IO: the log commit fails anyway, and the ordered extents in flight are
only torn down at unmount.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 81 ++++++++++++++++++++++++++++++++++++++++++
fs/btrfs/block-group.h | 2 ++
-From e1e8599602e0ab71282791410e7db2f0b3e9a6ac Mon Sep 17 00:00:00 2001
+From fe00cd985222e2044dbbdf7537f041c3de0b9fb4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:45 -0400
-Subject: [RFC PATCH 53/85] btrfs: stripe_alloc: count open stripe run
+Subject: [RFC PATCH 53/86] btrfs: stripe_alloc: count open stripe run
remainders against data reservations (fsync part)
To: linux-btrfs@vger.kernel.org
instead of with the rest of "btrfs: stripe_alloc: count open stripe run
remainders against data reservations".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
-From 480cf210e8b628cc824e3a754f3cd900cd781327 Mon Sep 17 00:00:00 2001
+From b07a15be4643a5f02ade5fa34c71b21ac5862b76 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:40 -0400
-Subject: [RFC PATCH 54/85] btrfs: stripe_alloc: allow-rmw policy, and
+Subject: [RFC PATCH 54/86] btrfs: stripe_alloc: allow-rmw policy, and
write-in-place for isolated nocow extents (fsync part)
To: linux-btrfs@vger.kernel.org
instead of with the rest of "btrfs: stripe_alloc: allow-rmw policy, and
write-in-place for isolated nocow extents".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 11 +++++++++++
1 file changed, 11 insertions(+)
-From 026d160272731cde3642ea1c7017802fbc51ee70 Mon Sep 17 00:00:00 2001
+From 0af3d9a23c6653f46f0354b39bc74df134d0c020 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:37 -0400
-Subject: [RFC PATCH 55/85] btrfs: stripe_alloc: carry an inode's log tail
+Subject: [RFC PATCH 55/86] btrfs: stripe_alloc: carry an inode's log tail
forward at fsync
To: linux-btrfs@vger.kernel.org
a NOCOW write) with the other delalloc bits, so the data space it reserved
is released when the range is later written NOCOW.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
-Assisted-by: Claude:claude-opus-5
---
fs/btrfs/block-group.c | 90 ++++++++++++++++++++-
fs/btrfs/block-group.h | 4 +-
int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info);
void btrfs_disable_stripe_alloc(struct btrfs_fs_info *fs_info);
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
-index 663e925b14300..8cb09b291597a 100644
+index 93c256a68c242..048206318a1cf 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -140,6 +140,31 @@ enum {
* Before we acquired the inode's lock and the mmap lock, someone may
* have dirtied more pages in the target range. We need to make sure
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 8b7fd4704349a..d183371910b3d 100644
+index cc1dabf910591..55f452b4aa4a3 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8144,6 +8144,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
-From b4a377a8995decd762e20496278a30ecf10bf7b8 Mon Sep 17 00:00:00 2001
+From d03d936d4aa8f739960a6f041fbc6f5a7ff7caec Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:40 -0400
-Subject: [RFC PATCH 56/85] btrfs: stripe_alloc: allow-rmw policy, and
+Subject: [RFC PATCH 56/86] btrfs: stripe_alloc: allow-rmw policy, and
write-in-place for isolated nocow extents (fsync part 2)
To: linux-btrfs@vger.kernel.org
of with the rest of "btrfs: stripe_alloc: allow-rmw policy, and
write-in-place for isolated nocow extents".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/defrag.c | 3 +++
1 file changed, 3 insertions(+)
-From ad5d2f9e6baf74ded8f1bb164aad9080b98aaf69 Mon Sep 17 00:00:00 2001
+From 88333ddcbb17e2719bdf7f50194a3f9438f9a864 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 6 Oct 2026 00:11:38 -0400
-Subject: [RFC PATCH 57/85] btrfs: stripe_alloc: share LOG data runs per log
+Subject: [RFC PATCH 57/86] btrfs: stripe_alloc: share LOG data runs per log
transaction
To: linux-btrfs@vger.kernel.org
so a sysfs change cannot leave an fsync waiting for a run only the commit
it blocks would provide.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 228 +++++++++++++++++++++++++++++++++--------
fs/btrfs/defrag.c | 6 ++
carry_one_range(inode, copy->range[i].start,
copy->range[i].len,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 7a882a47829c4..cb7f04ec8916f 100644
+index 0d7906bea0c61..870e8dd6b6eed 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2805,6 +2805,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
-From ef656afade0bf10d89629245f8a45c562c1e52b7 Mon Sep 17 00:00:00 2001
+From 60ee9f16b32d870f6697479787185b97b32f0119 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:27 -0400
-Subject: [RFC PATCH 58/85] btrfs: add a write-hole invariant checker to the
+Subject: [RFC PATCH 58/86] btrfs: add a write-hole invariant checker to the
raid56 write path
To: linux-btrfs@vger.kernel.org
enable left unsubmitted. A mount-time enable has nothing in flight.
close_ctree() flushes the worker.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 90 ++++++++++++++++++++++++++++++++++++++++++
fs/btrfs/block-group.h | 16 ++++++++
u64 bytenr);
void btrfs_dec_nocow_writers(struct btrfs_block_group *bg);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index cb7f04ec8916f..ad4046b12d011 100644
+index 870e8dd6b6eed..e5c3ebca75dd6 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2805,6 +2805,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
fs_info->stripe_log_data_shared = true;
fs_info->stripe_park_timeout_ms = BTRFS_RBIO_PARK_TIMEOUT_MS;
fs_info->stripe_compact = 10;
-@@ -4504,6 +4505,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
+@@ -4500,6 +4501,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
*/
btrfs_run_delayed_iputs(fs_info);
struct work_struct async_reclaim_work;
struct work_struct async_data_reclaim_work;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 169e1cccd73cd..3f469d62d5d46 100644
+index f458014e85792..e1886e245d2f2 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3196,6 +3196,16 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -3189,6 +3189,16 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
int sectornr;
int ret = 0;
-From 1fb94c6dc46ba944ff8863f08acd8156ff904eae Mon Sep 17 00:00:00 2001
+From 586833ca872bd8e8504fc4a3d14a3af7f0c99849 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:48 -0400
-Subject: [RFC PATCH 59/85] btrfs: stripe_alloc: report read-modify-write of
+Subject: [RFC PATCH 59/86] btrfs: stripe_alloc: report read-modify-write of
uncovered stripes (debug part)
To: linux-btrfs@vger.kernel.org
stripe_park_stats, which goes with the series' other debug statistics.
The warning itself is in that patch.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/fs.h | 1 +
fs/btrfs/raid56.c | 1 +
/* Stripes pinned in the rbio cache (rbio_needs_pin()). */
atomic64_t rbio_pinned;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 3f469d62d5d46..05e2952ac074a 100644
+index e1886e245d2f2..546ae059589b8 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3185,6 +3185,7 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3178,6 +3178,7 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
!(rbio->bioc->map_type & BTRFS_BLOCK_GROUP_METADATA))
return;
-From 587a154b50c77423901bc29f0991dd3053fe0bf1 Mon Sep 17 00:00:00 2001
+From 0429c058a3ee097eb8dc5ac4ebc77027b726637b Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:25 -0400
-Subject: [RFC PATCH 60/85] btrfs: stripe_alloc: say at mount whether the
+Subject: [RFC PATCH 60/86] btrfs: stripe_alloc: say at mount whether the
policy is on (debug part)
To: linux-btrfs@vger.kernel.org
with the rest of "btrfs: stripe_alloc: say at mount whether the policy
is on".
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
-From 4496c53dc0e42c3833b3c135678720b10a79ffdd Mon Sep 17 00:00:00 2001
+From 3f162beaab34bc056ac90e9c7f79f7083c0e6f72 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:40 -0400
-Subject: [RFC PATCH 61/85] btrfs: stripe_alloc: allow-rmw policy, and
+Subject: [RFC PATCH 61/86] btrfs: stripe_alloc: allow-rmw policy, and
write-in-place for isolated nocow extents (debug part)
To: linux-btrfs@vger.kernel.org
instead of with the rest of "btrfs: stripe_alloc: allow-rmw policy, and
write-in-place for isolated nocow extents".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
-From 369c9857cc08bba5420a2a23f8db57d28900f4a4 Mon Sep 17 00:00:00 2001
+From 4877b92652be53ab750ba537f4613f67fb164e4c Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 30 Sep 2026 18:07:52 -0400
-Subject: [RFC PATCH 62/85] btrfs: stripe_alloc: attribute each data
+Subject: [RFC PATCH 62/86] btrfs: stripe_alloc: attribute each data
read-modify-write to why padding declined
To: linux-btrfs@vger.kernel.org
The cost is a byte of state per rbio and a few counter increments per
RMW, plus one block group lookup for NO_RUN RMWs.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 17 +++++++++--
fs/btrfs/block-group.h | 17 +++++++++++
atomic64_t congestion_short;
/* Stripes pinned in the rbio cache (rbio_needs_pin()). */
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 05e2952ac074a..91780dae429aa 100644
+index 546ae059589b8..d1142d64e2c0a 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -22,6 +22,7 @@
/*
* Set when a parked rbio carries (or merged) a REQ_SYNC bio: a waiter
* is blocked on it, so deadlines stay authoritative and neither the
-@@ -3027,6 +3031,65 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
+@@ -3020,6 +3024,65 @@ static void submit_write_bios(struct btrfs_raid_bio *rbio,
}
}
/*
* Try to avoid the RMW read phase of a sub-stripe write by zero-filling the
* uncovered data sectors. Legal only where the stripe's run says a sector
-@@ -3049,6 +3112,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3042,6 +3105,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
bool ok = false;
int i;
if (!btrfs_test_opt(fs_info, STRIPE_ALLOC))
return false;
-@@ -3061,6 +3125,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3054,6 +3118,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
}
if (!btrfs_stripe_run_pad_mask(fs_info, stripe_start, stripe_len, dead,
unwritten, &info)) {
trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
stripe_len, 0, 0, nsectors,
info.run_start, info.run_end,
-@@ -3089,6 +3154,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3082,6 +3147,7 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
if (!test_bit(i, dead)) {
atomic64_inc(&fs_info->stripe_park_stats.pad_decline_uncovered);
info.reason = BTRFS_STRIPE_PAD_UNCOVERED;
trace_btrfs_stripe_pad_decline(fs_info, stripe_start,
stripe_len, 0, covered,
nsectors,
-@@ -3109,6 +3175,8 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
+@@ -3102,6 +3168,8 @@ static bool rmw_try_pad_full(struct btrfs_raid_bio *rbio)
if (!ok)
return false;
if (alloc_rbio_data_pages(rbio) < 0)
return false;
-@@ -3237,6 +3305,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
+@@ -3230,6 +3298,7 @@ static void rmw_rbio(struct btrfs_raid_bio *rbio)
atomic64_inc(&fs_info->stripe_park_stats.data_rmw);
if (!(rbio->bioc->map_type & BTRFS_BLOCK_GROUP_DATA))
atomic64_inc(&fs_info->stripe_park_stats.meta_rmw_reads);
-From 1b40736d13f7ed5208eaa5fa4f31b5ee0cd2330b Mon Sep 17 00:00:00 2001
+From 92f980554a87ea36fce399fbbb8eb6d2ce6cb7be Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 30 Sep 2026 18:07:56 -0400
-Subject: [RFC PATCH 63/85] btrfs: stripe_alloc: optionally audit data
+Subject: [RFC PATCH 63/86] btrfs: stripe_alloc: optionally audit data
read-modify-writes against the committed extent tree
To: linux-btrfs@vger.kernel.org
debug/stripe_rmw_audit_stats, with data_rmw_audited so a reader can
tell an audit that found nothing from one that never ran.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 2 +
fs/btrfs/block-group.h | 2 +
* LOG-class data runs. Set (the default): runs are shared per
* (subvolume, log_transid); a log commit seals the stripe holding the
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 91780dae429aa..b892e085ac07a 100644
+index d1142d64e2c0a..24f13a6871616 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -23,6 +23,7 @@
/* set when additional merges to this rbio are not allowed */
#define RBIO_RMW_LOCKED_BIT 1
-@@ -3036,6 +3037,13 @@ static void rbio_record_pad(struct btrfs_raid_bio *rbio,
+@@ -3029,6 +3030,13 @@ static void rbio_record_pad(struct btrfs_raid_bio *rbio,
{
rbio->pad_reason = info->reason;
rbio->pad_norun = info->norun;
}
static_assert(BTRFS_STRIPE_PAD_NR_REASONS + 1 ==
-@@ -3043,6 +3051,320 @@ static_assert(BTRFS_STRIPE_PAD_NR_REASONS + 1 ==
+@@ -3036,6 +3044,320 @@ static_assert(BTRFS_STRIPE_PAD_NR_REASONS + 1 ==
static_assert(BTRFS_STRIPE_NORUN_NR ==
ARRAY_SIZE(((struct btrfs_fs_info *)0)->stripe_park_stats.data_rmw_norun));
/*
* Attribute a read-modify-write to why padding declined for this rbio. With
* allow_rmw empty, a data RMW in a stripe_alloc group is expected in two
-@@ -3088,6 +3410,8 @@ static void rbio_count_rmw_reason(struct btrfs_raid_bio *rbio)
+@@ -3081,6 +3403,8 @@ static void rbio_count_rmw_reason(struct btrfs_raid_bio *rbio)
/* Disjoint from the frontier count, so the two can be summed. */
if (reloc_writer && idx != BTRFS_STRIPE_PAD_UNCOVERED)
atomic64_inc(&fs_info->stripe_park_stats.data_rmw_reloc_writer);
-From 33f8c600f9ebddf923072c8eeb67f27a471ecfca Mon Sep 17 00:00:00 2001
+From 11e5a2444ce6562a9cb3efa58645731d339243b4 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 17:46:19 -0400
-Subject: [RFC PATCH 64/85] btrfs: stripe_alloc: break rbio pins and open
+Subject: [RFC PATCH 64/86] btrfs: stripe_alloc: break rbio pins and open
stripe runs down by run class
To: linux-btrfs@vger.kernel.org
btrfs_stripe_run_incomplete() becomes a wrapper around
btrfs_stripe_run_incomplete_class(), which also says which run's class.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 70 ++++++++++++++++++++++++++++++++++--------
fs/btrfs/block-group.h | 3 ++
enum btrfs_stripe_run_class *class);
u64 btrfs_stripe_run_stranded_stripes(struct btrfs_block_group *bg, u32 *freep,
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index b892e085ac07a..e1fee64396457 100644
+index 24f13a6871616..ea85d8e41e01a 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -796,22 +796,34 @@ void btrfs_rbio_unpin_stale(struct btrfs_fs_info *fs_info)
-From a57dba490e9d9cc8b4703be67e5e9ed983beb924 Mon Sep 17 00:00:00 2001
+From 9431221b38c0f86e016a6fc31c226cd88334597f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 19:13:11 -0400
-Subject: [RFC PATCH 65/85] btrfs: stripe_alloc: count and log ordered extents
+Subject: [RFC PATCH 65/86] btrfs: stripe_alloc: count and log ordered extents
that end with sectors unwritten
To: linux-btrfs@vger.kernel.org
unwritten_on_end and unwritten_on_end_bytes count only the logged ones, so
any increase there is worth a look.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 27 ++++++++++++++---
fs/btrfs/block-group.h | 5 ++--
-From b8a1eee6f055ac803c5063beebc831789e0126ec Mon Sep 17 00:00:00 2001
+From c408bbeff9075e15022a2ecdee002da9a65d7b1e Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 25 Oct 2026 04:48:50 -0400
-Subject: [RFC PATCH 66/85] btrfs: stripe_alloc: log the space counters when
+Subject: [RFC PATCH 66/86] btrfs: stripe_alloc: log the space counters when
data writeback hits ENOSPC
To: linux-btrfs@vger.kernel.org
The line and the walk share one rate limit, so a burst of failures cannot
flood the log with group lines.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/extent-tree.c | 34 +++++++++++++++++++++++++++++-----
fs/btrfs/space-info.c | 39 +++++++++++++++++++++++++++++++++++++++
-From fd2541deae3f19661fd8e5a03f1981574b6343b1 Mon Sep 17 00:00:00 2001
+From c1081b79df36a55c35469e6b3e3e0d15f05672ed Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 25 Oct 2026 06:27:49 -0400
-Subject: [RFC PATCH 67/85] btrfs: stripe_alloc: do not count a writeback
+Subject: [RFC PATCH 67/86] btrfs: stripe_alloc: do not count a writeback
ENOSPC drop's give-back as supply (debug part)
To: linux-btrfs@vger.kernel.org
hits ENOSPC" is in, instead of with the rest of "btrfs: stripe_alloc: do
not count a writeback ENOSPC drop's give-back as supply".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/extent-tree.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
-From 6e3a00f579397c6232636f8f734f1c18db50aef7 Mon Sep 17 00:00:00 2001
+From 6324127f015a6ecedfdc61729084f838a2b83cff Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:58 -0400
-Subject: [RFC PATCH 68/85] btrfs: stripe_meta: allocate tree blocks by whole
+Subject: [RFC PATCH 68/86] btrfs: stripe_meta: allocate tree blocks by whole
stripes
To: linux-btrfs@vger.kernel.org
both release every open run before the block groups are freed, reporting
any run that still counts bytes in flight.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 395 ++++++++++++++++++++++++++++--
fs/btrfs/block-group.h | 14 ++
spin_unlock(&block_rsv->lock);
spin_unlock(&sinfo->lock);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index ad4046b12d011..a7339ea5b0028 100644
+index e5c3ebca75dd6..a54c687aee50a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3853,6 +3853,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
btrfs_free_block_groups(fs_info);
fail_alloc:
btrfs_mapping_tree_free(fs_info);
-@@ -4625,6 +4626,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
+@@ -4621,6 +4622,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
* accounting appear to be wrong because there's pending reserved bytes,
* so make sure we do the block group cleanup afterwards.
*/
nstripes = stripe_unusable_nstripes(bg);
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index e1fee64396457..c2ba1f3e7a25c 100644
+index ea85d8e41e01a..2d60d202201ab 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3581,6 +3581,8 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+@@ -3574,6 +3574,8 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
{
struct btrfs_fs_info *fs_info = rbio->bioc->fs_info;
if (!btrfs_test_opt(fs_info, STRIPE_ALLOC))
return;
-@@ -3590,6 +3592,21 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3583,6 +3585,21 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
return;
atomic64_inc(&fs_info->stripe_park_stats.meta_rmw);
return ret;
}
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index 6bbcf42121461..aa251b32b1dcf 100644
+index c97e37951c2af..b217566a6c9ba 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -23,6 +23,7 @@
ret2 = btrfs_wait_extents(fs_info, dirty_pages);
if (ret)
-@@ -2664,6 +2672,16 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
+@@ -2659,6 +2667,16 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
goto scrub_continue;
}
-From aa8b778a51434b49ca822ad7c66f8e0e5eeb2bef Mon Sep 17 00:00:00 2001
+From 9c56fb1e257e76510e957a6b667bdecd01a9650d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 12:14:49 -0400
-Subject: [RFC PATCH 69/85] btrfs: stripe_alloc: keep a stripe in the rbio
+Subject: [RFC PATCH 69/86] btrfs: stripe_alloc: keep a stripe in the rbio
cache until its run has written all of it (stripe_meta part)
To: linux-btrfs@vger.kernel.org
with the rest of "btrfs: stripe_alloc: keep a stripe in the rbio cache
until its run has written all of it".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 1 +
1 file changed, 1 insertion(+)
-From 9e00bb532a627618364cd9b43a1c833dbd3d0da9 Mon Sep 17 00:00:00 2001
+From edd54a44ead7e5cf1c54d68bb572fa83d08a312f Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 10 Oct 2026 00:19:18 -0400
-Subject: [RFC PATCH 70/85] btrfs: stripe_alloc: skip RAID5/6 groups that are
+Subject: [RFC PATCH 70/86] btrfs: stripe_alloc: skip RAID5/6 groups that are
mapped as RAID1/RAID1C3 (stripe_meta part)
To: linux-btrfs@vger.kernel.org
of "btrfs: stripe_alloc: skip RAID5/6 groups that are mapped as
RAID1/RAID1C3".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/extent-tree.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
-From f338d88054a75420a22b7013958b392a3103a579 Mon Sep 17 00:00:00 2001
+From d9ee4a59d2396e04fdff11ceab00f8518f4cbc2d Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 22 Oct 2026 16:47:05 -0400
-Subject: [RFC PATCH 71/85] btrfs: stripe_meta: extend stripe reclaim to
+Subject: [RFC PATCH 71/86] btrfs: stripe_meta: extend stripe reclaim to
metadata block groups
To: linux-btrfs@vger.kernel.org
The comments that name the groups reclaim handles now name both.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 26 +++++++++++++++-----------
fs/btrfs/free-space-cache.c | 2 +-
* start forces that group. See btrfs_stripe_reclaim_now().
*/
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
-index c9f81b0975fe0..9f689c4c9d7f8 100644
+index ea98cef92dc3d..6c2a9e391dae7 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
-@@ -3802,7 +3802,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
+@@ -3814,7 +3814,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset, bool v
}
/*
-From 5caf207efa50dc5d51f7e0a120f22301e3329f2c Mon Sep 17 00:00:00 2001
+From 938f111753c327badb8b7755c40c5c527fd291ec Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:12 -0400
-Subject: [RFC PATCH 72/85] btrfs: stripe_meta: hold back whole stripes so tree
+Subject: [RFC PATCH 72/86] btrfs: stripe_meta: hold back whole stripes so tree
blocks always land and trapped groups can be reclaimed
To: linux-btrfs@vger.kernel.org
legacy allocator placed in it are written by that commit into partly used
stripes. That one commit's exposure is inherent.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
-Assisted-by: Claude:claude-fable-5-1
---
fs/btrfs/block-group.c | 98 ++++++++++++++++++++++++++++++++++---
fs/btrfs/disk-io.c | 7 ++-
}
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index a7339ea5b0028..d4b6de361fb3c 100644
+index a54c687aee50a..593f94f9c42de 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3148,17 +3148,22 @@ int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info)
-From 1c27225353cf83f9b418f297ce1f028332aec02d Mon Sep 17 00:00:00 2001
+From bfbfb1226c79d44594119db0f4b66d4377d27709 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:18:19 -0400
-Subject: [RFC PATCH 73/85] btrfs: stripe_alloc: count whole stripes stranded
+Subject: [RFC PATCH 73/86] btrfs: stripe_alloc: count whole stripes stranded
behind live runs as trapped (stripe_meta part)
To: linux-btrfs@vger.kernel.org
is in, instead of with the rest of "btrfs: stripe_alloc: count whole
stripes stranded behind live runs as trapped".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/space-info.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
-From 11c8a7cfaaf14db5bbb2009c829b7848197f6073 Mon Sep 17 00:00:00 2001
+From 4dc2b5434dc5670dbe67d0799ed435e1d926ff38 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 25 Oct 2026 06:27:49 -0400
-Subject: [RFC PATCH 74/85] btrfs: stripe_alloc: do not count a writeback
+Subject: [RFC PATCH 74/86] btrfs: stripe_alloc: do not count a writeback
ENOSPC drop's give-back as supply (stripe_meta part)
To: linux-btrfs@vger.kernel.org
is in, instead of with the rest of "btrfs: stripe_alloc: do not count a
writeback ENOSPC drop's give-back as supply".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/space-info.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
-From dbd6acf9aefead735973a3e9b9f70ad05488289b Mon Sep 17 00:00:00 2001
+From 4aebc7adc2abe26338ad70da8523e2a78d5faeaa Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 20 Sep 2026 01:33:09 -0400
-Subject: [RFC PATCH 75/85] btrfs: stripe_meta: cover raid56 system chunks
+Subject: [RFC PATCH 75/86] btrfs: stripe_meta: cover raid56 system chunks
To: linux-btrfs@vger.kernel.org
The chunk tree lives in system chunks, which carry no METADATA bit, so the
The "does not cover raid56 system chunks" warning has nothing left to
warn about and goes.
-Assisted-by: Claude:claude-fable-5-1
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 76 +++++++++++++++++++++++-------------------
fs/btrfs/extent-tree.c | 23 ++++++-------
(bg->flags & BTRFS_BLOCK_GROUP_RAID56_MASK) &&
!test_bit(BLOCK_GROUP_FLAG_RAID56_MIRRORED, &bg->runtime_flags);
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index c2ba1f3e7a25c..1afccd067b8a9 100644
+index 2d60d202201ab..d9c1dddda6aa2 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3593,12 +3593,11 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3586,12 +3586,11 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
atomic64_inc(&fs_info->stripe_park_stats.meta_rmw);
/*
-From 370ac4e55a9ea07cc456c2c1c135419bbf020b7c Mon Sep 17 00:00:00 2001
+From fcec7b1f4c096d708ede6e6f0560e51ec54f8a82 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 10 Oct 2026 00:19:18 -0400
-Subject: [RFC PATCH 76/85] btrfs: stripe_alloc: skip RAID5/6 groups that are
+Subject: [RFC PATCH 76/86] btrfs: stripe_alloc: skip RAID5/6 groups that are
mapped as RAID1/RAID1C3 (stripe_meta part 2)
To: linux-btrfs@vger.kernel.org
system chunks" is in, instead of with the rest of "btrfs: stripe_alloc:
skip RAID5/6 groups that are mapped as RAID1/RAID1C3".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/extent-tree.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
-From 94620d2830c64ef9b046fec2180d7e5807226a7f Mon Sep 17 00:00:00 2001
+From 30a6372518d70d023dc844a8363d559870d11366 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sun, 4 Oct 2026 23:16:03 -0400
-Subject: [RFC PATCH 77/85] btrfs: stripe_alloc: give each log commit its own
+Subject: [RFC PATCH 77/86] btrfs: stripe_alloc: give each log commit its own
metadata stripe run
To: linux-btrfs@vger.kernel.org
seconds they warn once and dump the group's runs (every run class) and
keep waiting. Only a filesystem error ends them.
-Assisted-by: Claude:claude-opus-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/block-group.c | 240 ++++++++++++++++++++++++++++++++++++-----
fs/btrfs/block-group.h | 23 ++++
struct btrfs_inode *inode,
enum btrfs_stripe_run_class class,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index d4b6de361fb3c..322daea247db4 100644
+index 593f94f9c42de..8eb61d7c08845 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2806,6 +2806,11 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
-From 0d3c2f28add6021e5c01082d66129e49e828b6bd Mon Sep 17 00:00:00 2001
+From 5fa12d371d598711448219bc1f51ae1a64a59071 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Tue, 6 Oct 2026 00:11:38 -0400
-Subject: [RFC PATCH 78/85] btrfs: stripe_alloc: share LOG data runs per log
+Subject: [RFC PATCH 78/86] btrfs: stripe_alloc: share LOG data runs per log
transaction (stripe_meta part)
To: linux-btrfs@vger.kernel.org
instead of with the rest of "btrfs: stripe_alloc: share LOG data runs
per log transaction".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/disk-io.c | 5 +++--
fs/btrfs/sysfs.c | 16 ++++++++++++++--
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
-index 322daea247db4..27faf262898f7 100644
+index 8eb61d7c08845..a91fc9e510ba2 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2807,8 +2807,9 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
-From 4a7162b0186b5c8ba3f17157c595750d9ea0d43b Mon Sep 17 00:00:00 2001
+From 3503c569a88848171f7cb71ce813480571483b79 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Fri, 9 Oct 2026 19:13:11 -0400
-Subject: [RFC PATCH 79/85] btrfs: stripe_alloc: count and log ordered extents
+Subject: [RFC PATCH 79/86] btrfs: stripe_alloc: count and log ordered extents
that end with sectors unwritten (debug_meta part)
To: linux-btrfs@vger.kernel.org
They append the unwritten_on_end counters to the stripe_run_stats list
after the log seal counters, which that patch adds to it.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/sysfs.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
-From f7823fb8ab4d325a71cd00fb2d68f9b909d51aca Mon Sep 17 00:00:00 2001
+From 707fe91a973591b6fd0fda9835579e34b72bf5d3 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:49 -0400
-Subject: [RFC PATCH 80/85] btrfs: raid56: say whether a metadata
+Subject: [RFC PATCH 80/86] btrfs: raid56: say whether a metadata
read-modify-write is a write hole
To: linux-btrfs@vger.kernel.org
it does not block: commit_root_sem is taken with a trylock and the search
uses path->nowait. A block not in memory is counted as meta_rmw_unknown.
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/fs.h | 14 +++
fs/btrfs/raid56.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++
/* Stripes pinned in the rbio cache (rbio_needs_pin()). */
atomic64_t rbio_pinned;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
-index 1afccd067b8a9..b3fdffa6c1418 100644
+index d9c1dddda6aa2..42c3251de77e5 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
-@@ -3573,6 +3573,219 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
+@@ -3566,6 +3566,219 @@ static bool need_read_stripe_sectors(struct btrfs_raid_bio *rbio)
return false;
}
/*
* Count and audit a metadata or system read-modify-write
* (audit_uncovered_rmw()), and warn if it lands in a raid56 group that
-@@ -3592,6 +3805,7 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
+@@ -3585,6 +3798,7 @@ static void report_uncovered_rmw(struct btrfs_raid_bio *rbio)
return;
atomic64_inc(&fs_info->stripe_park_stats.meta_rmw);
-From 00221b3dedbc3abae5c2ebc91a652c8a06aac067 Mon Sep 17 00:00:00 2001
+From 012fa07665108a367d81cb925e22517923672122 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:50 -0400
-Subject: [RFC PATCH 81/85] btrfs: stripe_alloc: tunable park deadlines, and
+Subject: [RFC PATCH 81/86] btrfs: stripe_alloc: tunable park deadlines, and
say why padding declined (debug_meta part)
To: linux-btrfs@vger.kernel.org
instead of with the rest of "btrfs: stripe_alloc: tunable park
deadlines, and say why padding declined".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/sysfs.c | 8 ++++++++
1 file changed, 8 insertions(+)
-From b1c2f116b1f03bf020ea758261f07a89fc4712ab Mon Sep 17 00:00:00 2001
+From 51404c85145db5076d18209f9e2ee6d400e0ca78 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:51 -0400
-Subject: [RFC PATCH 82/85] btrfs: stripe_alloc: trace why padding declined, at
+Subject: [RFC PATCH 82/86] btrfs: stripe_alloc: trace why padding declined, at
the moment it declined (debug_meta part)
To: linux-btrfs@vger.kernel.org
instead of with the rest of "btrfs: stripe_alloc: trace why padding
declined, at the moment it declined".
-Assisted-by: Claude:claude-fable-5
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/sysfs.c | 2 ++
1 file changed, 2 insertions(+)
-From 8c1af409d04fb26378e23b6a5045ed85b488a890 Mon Sep 17 00:00:00 2001
+From 9fc871e8ec173756d47d6e347872999e3e8eb3d6 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Wed, 30 Sep 2026 18:07:52 -0400
-Subject: [RFC PATCH 83/85] btrfs: stripe_alloc: attribute each data
+Subject: [RFC PATCH 83/86] btrfs: stripe_alloc: attribute each data
read-modify-write to why padding declined (debug_meta part)
To: linux-btrfs@vger.kernel.org
It also drops the pad_decline_live and pad_decline_unallocated counters:
these hunks remove their last readers.
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/fs.h | 9 +--------
fs/btrfs/sysfs.c | 28 ++++++++++++++++++++++++----
-From e63b3c7abf59fc929a99c3ca00ff3ea8be776366 Mon Sep 17 00:00:00 2001
+From c04e21622d6428d9d3665a10b7ef961d87581e79 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Sat, 19 Sep 2026 13:17:55 -0400
-Subject: [RFC PATCH 84/85] btrfs: raid56: adaptive park deadline from the
+Subject: [RFC PATCH 84/86] btrfs: raid56: adaptive park deadline from the
parked-rbio backlog (debug_meta part)
To: linux-btrfs@vger.kernel.org
with the rest of "btrfs: raid56: adaptive park deadline from the
parked-rbio backlog".
-Assisted-by: Claude:claude-opus-4-8
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/sysfs.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
-From 1944ff74ed890d045c8d8f7346c44c519f6a2dee Mon Sep 17 00:00:00 2001
+From 1ad774c8163bd5e040f4e6900194207e2ea1b392 Mon Sep 17 00:00:00 2001
From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Date: Thu, 1 Oct 2026 12:14:49 -0400
-Subject: [RFC PATCH 85/85] btrfs: stripe_alloc: keep a stripe in the rbio
+Subject: [RFC PATCH 85/86] btrfs: stripe_alloc: keep a stripe in the rbio
cache until its run has written all of it (debug_meta part)
To: linux-btrfs@vger.kernel.org
hole" is in, instead of with the rest of "btrfs: stripe_alloc: keep a
stripe in the rbio cache until its run has written all of it".
-Assisted-by: Claude:claude-opus-5-5
---
fs/btrfs/sysfs.c | 4 ++++
1 file changed, 4 insertions(+)
--- /dev/null
+From 294d230e458ac952577f5edc9d25770679c636c1 Mon Sep 17 00:00:00 2001
+From: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
+Date: Wed, 4 Nov 2026 15:07:35 -0500
+Subject: [RFC PATCH 86/86] btrfs: stripe_alloc: drop the extract hooks of the
+ stripe_alloc properties
+To: linux-btrfs@vger.kernel.org
+
+The stripe_alloc and stripe_alloc_allow_rmw property handlers are not
+inheritable. The only caller of a handler's extract hook is
+btrfs_inode_inherit_props(), and it skips handlers that are not
+inheritable before it calls the hook, so prop_stripe_alloc_extract() and
+prop_stripe_rmw_extract() were dead code that only returned NULL.
+Remove them and leave .extract unset in both handlers. This also keeps
+the stripe_alloc handlers independent of the extract() prototype.
+
+Also move prop_compression_extract() up, next to
+prop_compression_ignore(): the stripe_alloc handler functions were
+added between the two, splitting the compression property's hooks. Now
+they follow the compression hooks, just before the handler table.
+
+No functional change.
+
+---
+ fs/btrfs/props.c | 42 ++++++++++++++----------------------------
+ 1 file changed, 14 insertions(+), 28 deletions(-)
+
+diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
+index 741ccacb42f84..01f8c8a23d556 100644
+--- a/fs/btrfs/props.c
++++ b/fs/btrfs/props.c
+@@ -418,6 +418,20 @@ static bool prop_compression_ignore(const struct btrfs_inode *inode)
+ return false;
+ }
+
++static const char *prop_compression_extract(const struct btrfs_inode *inode)
++{
++ switch (inode->prop_compress) {
++ case BTRFS_COMPRESS_ZLIB:
++ case BTRFS_COMPRESS_LZO:
++ case BTRFS_COMPRESS_ZSTD:
++ return btrfs_compress_type2str(inode->prop_compress);
++ default:
++ break;
++ }
++
++ return NULL;
++}
++
+ /*
+ * The "stripe_alloc" property is filesystem-wide policy: stripe-exclusive
+ * (raid56 write hole safe) data allocation. It lives on the top-level
+@@ -463,12 +477,6 @@ static int prop_stripe_alloc_apply(struct btrfs_inode *inode,
+ return btrfs_enable_stripe_alloc(fs_info);
+ }
+
+-static const char *prop_stripe_alloc_extract(const struct btrfs_inode *inode)
+-{
+- /* Not inheritable; nothing regenerates the value from inode state. */
+- return NULL;
+-}
+-
+ static int prop_stripe_rmw_validate(const struct btrfs_inode *inode,
+ const char *value, size_t len)
+ {
+@@ -497,31 +505,11 @@ static int prop_stripe_rmw_apply(struct btrfs_inode *inode,
+ return 0;
+ }
+
+-static const char *prop_stripe_rmw_extract(const struct btrfs_inode *inode)
+-{
+- /* Not inheritable; nothing regenerates the value from inode state. */
+- return NULL;
+-}
+-
+ static bool prop_stripe_alloc_ignore(const struct btrfs_inode *inode)
+ {
+ return false;
+ }
+
+-static const char *prop_compression_extract(const struct btrfs_inode *inode)
+-{
+- switch (inode->prop_compress) {
+- case BTRFS_COMPRESS_ZLIB:
+- case BTRFS_COMPRESS_LZO:
+- case BTRFS_COMPRESS_ZSTD:
+- return btrfs_compress_type2str(inode->prop_compress);
+- default:
+- break;
+- }
+-
+- return NULL;
+-}
+-
+ static struct prop_handler prop_handlers[] = {
+ {
+ .xattr_name = XATTR_BTRFS_PREFIX "compression",
+@@ -535,7 +523,6 @@ static struct prop_handler prop_handlers[] = {
+ .xattr_name = XATTR_BTRFS_PREFIX "stripe_alloc",
+ .validate = prop_stripe_alloc_validate,
+ .apply = prop_stripe_alloc_apply,
+- .extract = prop_stripe_alloc_extract,
+ .ignore = prop_stripe_alloc_ignore,
+ .inheritable = 0
+ },
+@@ -543,7 +530,6 @@ static struct prop_handler prop_handlers[] = {
+ .xattr_name = XATTR_BTRFS_PREFIX "stripe_alloc_allow_rmw",
+ .validate = prop_stripe_rmw_validate,
+ .apply = prop_stripe_rmw_apply,
+- .extract = prop_stripe_rmw_extract,
+ .ignore = prop_stripe_alloc_ignore,
+ .inheritable = 0
+ },
+--
+2.47.3
+