[PATCH 1/4] btrfs: zoned: take the RAID1 active state from the first present stripe
From: Miroslav Cimerman
Date: Thu Nov 19 2026 - 16:40:38 EST
btrfs_load_block_group_raid1() compares the active state of each
present stripe's zone with stripe 0's. A missing device has no active
zones, so with stripe 0 missing, an active zone of a present stripe
always mismatches, and a degraded mount neither activates the block
group nor marks it active. It is then not on the list of active block
groups, while its zones are active and count against their devices'
active zone limits.
If it is a data block group, writing data to it tries to activate it,
which fails when the active zones left are reserved for metadata. With
no other data block group with room left, the allocation then returns
-EAGAIN, and the write waits for a zone finish forever:
task:dd state:D
btrfs_new_extent_direct
btrfs_dio_iomap_next
iomap_iter
__iomap_dio_rw
btrfs_direct_write
btrfs_do_write_iter
vfs_write
If it is a metadata block group, writing tree blocks to it activates it
with a warning:
WARNING: fs/btrfs/zoned.c:2451 at btrfs_zone_activate+0x72a/0xa60, CPU#1: btrfs/157
btrfs_check_meta_write_pointer
write_meta_extent_buffer
btree_writepages
Compare with the first present stripe instead.
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 by an LLM while testing the next patch. The fix and the commit
message were prepared with the help of an LLM, which also tested it. I
reviewed everything.
A mismatch between present stripes, like a stripe behind the others on
a degraded mount, is not changed. Depending on which stripe comes
first, the block group is marked active at load without the zone of the
other stripe accounted, or activated at its first write if it has room
left, which can fail as above when no active zone is left. Both happened
before too. I can look at the active zone accounting for these zones
separately.
btrfs_load_block_group_raid10() compares the active state with stripe
0's too, but activates the block group on a mismatch instead of
skipping it. With stripe 0 missing, that warns at mount for a metadata
block group, and can fail the mount for a data block group when no
active zone is left. RAID10 also adds a zone capacity of 0 for a
missing first stripe of a pair, which fails the degraded mount once a
block group holds more than the capacity that is left. Neither is
changed in this series. I will send fixes for both.
fs/btrfs/zoned.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index e6ce6f05ad75..8eac6e2283a2 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1522,6 +1522,7 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
u64 last_alloc)
{
struct btrfs_fs_info *fs_info = bg->fs_info;
+ int first = -1;
int i;
if ((map->type & BTRFS_BLOCK_GROUP_DATA) && !fs_info->stripe_root) {
@@ -1555,6 +1556,9 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
if (zone_info[i].alloc_offset == WP_CONVENTIONAL)
zone_info[i].alloc_offset = last_alloc;
+ if (first < 0)
+ first = i;
+
if (unlikely((zone_info[0].alloc_offset != zone_info[i].alloc_offset) &&
!btrfs_test_opt(fs_info, DEGRADED))) {
btrfs_err(fs_info,
@@ -1562,13 +1566,13 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
btrfs_bg_type_to_raid_name(map->type));
return -EIO;
}
- if (test_bit(0, active) != test_bit(i, active)) {
+ if (test_bit(first, active) != test_bit(i, active)) {
if (unlikely(!btrfs_test_opt(fs_info, DEGRADED) &&
!btrfs_zone_activate(bg))) {
return -EIO;
}
} else {
- if (test_bit(0, active))
+ if (test_bit(first, active))
set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &bg->runtime_flags);
}
}
--
2.53.0