[PATCH 3/4] btrfs: zoned: take the RAID1 zone capacity from a present stripe

From: Miroslav Cimerman

Date: Thu Nov 19 2026 - 16:40:55 EST


btrfs_load_block_group_raid1() takes the zone capacity of the block
group from stripes 0 and 1. A missing device has a capacity of 0, which
min_not_zero() skips, but a RAID1C3 or RAID1C4 block group with both
stripes missing gets a capacity of 0. Once it has been written to, it
fails to load, and a degraded mount fails although a copy is left:

BTRFS error (device nb4): zoned: invalid write pointer 98304 (larger than zone capacity 0) in block group 83886080
BTRFS error (device nb4): zoned: failed to load zone info of bg 83886080
BTRFS error (device nb4): failed to read block groups: -EIO

In that case, take the smallest non-zero capacity of the other stripes.

Fixes: 568220fa9657 ("btrfs: zoned: support RAID0/1/10 on top of raid stripe tree")
CC: stable@xxxxxxxxxxxxxxx # 6.7+
Signed-off-by: Miroslav Cimerman <mc@xxxxxxxxxxx>
---
Found in an LLM review of the previous patches. The fix and the commit
message were prepared with the help of an LLM, which also tested it. I
reviewed everything.

Taking the smallest capacity of all stripes would also cover a third or
fourth stripe with a smaller capacity, but a block group written past
it would then fail to load, so it is not done here.

fs/btrfs/zoned.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 8bd44dd260a4..5722e16a5432 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1535,6 +1535,12 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,

/* In case a device is missing we have a cap of 0, so don't use it. */
bg->zone_capacity = min_not_zero(zone_info[0].capacity, zone_info[1].capacity);
+ /* RAID1C3 and RAID1C4 can miss both of them, take the others then. */
+ if (!bg->zone_capacity) {
+ for (i = 2; i < map->num_stripes; i++)
+ bg->zone_capacity = min_not_zero(bg->zone_capacity,
+ zone_info[i].capacity);
+ }

/*
* When the last extent is removed, last_alloc can be smaller than the other write
--
2.53.0