[PATCH 4/4] btrfs: tests: zoned: add degraded RAID1 cases

From: Miroslav Cimerman

Date: Thu Nov 19 2026 - 16:41:08 EST


Add cases for the previous patches. On a degraded mount: RAID1 with the
first device missing, which has to be marked active, RAID1C3 with the
first and the last and with the first two devices missing, and RAID1
and RAID1C3 with different write pointers, which take the highest one.
On a regular mount: RAID1 with the first zone offline, which now loads.

Give missing devices a zone capacity of 0, as btrfs_load_zone_info()
does, and check the zone capacity and the active state where a case
asks for it. All six cases fail without the previous patches.

Signed-off-by: Miroslav Cimerman <mc@xxxxxxxxxxx>
---
Prepared with the help of an LLM, which also ran the tests. I reviewed
everything.

fs/btrfs/tests/zoned-tests.c | 82 +++++++++++++++++++++++++++++++++++-
1 file changed, 81 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/tests/zoned-tests.c b/fs/btrfs/tests/zoned-tests.c
index bb9969210444..9cc5b32bb2ee 100644
--- a/fs/btrfs/tests/zoned-tests.c
+++ b/fs/btrfs/tests/zoned-tests.c
@@ -27,6 +27,8 @@ struct load_zone_info_test_vector {

int expected_result;
u64 expected_alloc_offset;
+ u64 expected_zone_capacity;
+ bool expected_active;

const char *description;
};
@@ -77,7 +79,9 @@ static int test_load_zone_info(struct btrfs_fs_info *fs_info,
for (int i = 0; i < test->num_stripes; i++) {
zone_info[i].physical = 0;
zone_info[i].alloc_offset = test->alloc_offsets[i];
- zone_info[i].capacity = ZONE_SIZE;
+ /* A missing device has a capacity of 0. */
+ if (zone_info[i].alloc_offset != WP_MISSING_DEV)
+ zone_info[i].capacity = ZONE_SIZE;
if (zone_info[i].alloc_offset && zone_info[i].alloc_offset < ZONE_SIZE)
__set_bit(i, active);
}
@@ -101,6 +105,19 @@ static int test_load_zone_info(struct btrfs_fs_info *fs_info,
return -EINVAL;
}

+ if (!ret && test->expected_zone_capacity &&
+ bg->zone_capacity != test->expected_zone_capacity) {
+ test_err("unexpected zone_capacity: zone_capacity %llu expected %llu",
+ bg->zone_capacity, test->expected_zone_capacity);
+ return -EINVAL;
+ }
+
+ if (!ret && test->expected_active &&
+ !test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &bg->runtime_flags)) {
+ test_err("block group not marked active");
+ return -EINVAL;
+ }
+
return 0;
}

@@ -244,6 +261,69 @@ static const struct load_zone_info_test_vector load_zone_info_tests[] = {
.degraded = true,
.expected_alloc_offset = SZ_1M,
},
+ {
+ .description = "RAID1: missing first device on DEGRADED",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ WP_MISSING_DEV, SZ_1M,
+ },
+ .degraded = true,
+ .expected_alloc_offset = SZ_1M,
+ .expected_active = true,
+ },
+ {
+ .description = "RAID1C3: missing first and last device on DEGRADED",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1C3,
+ .num_stripes = 3,
+ .alloc_offsets = {
+ WP_MISSING_DEV, SZ_1M, WP_MISSING_DEV,
+ },
+ .degraded = true,
+ .expected_alloc_offset = SZ_1M,
+ },
+ {
+ .description = "RAID1C3: missing first and second device on DEGRADED",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1C3,
+ .num_stripes = 3,
+ .alloc_offsets = {
+ WP_MISSING_DEV, WP_MISSING_DEV, SZ_1M,
+ },
+ .degraded = true,
+ .expected_alloc_offset = SZ_1M,
+ .expected_zone_capacity = ZONE_SIZE,
+ },
+ /* A stripe behind the others: the highest write pointer on DEGRADED. */
+ {
+ .description = "RAID1: different write pointers on DEGRADED",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ SZ_1M, SZ_2M,
+ },
+ .degraded = true,
+ .expected_alloc_offset = SZ_2M,
+ },
+ {
+ .description = "RAID1C3: first missing, different write pointers on DEGRADED",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1C3,
+ .num_stripes = 3,
+ .alloc_offsets = {
+ WP_MISSING_DEV, SZ_2M, SZ_1M,
+ },
+ .degraded = true,
+ .expected_alloc_offset = SZ_2M,
+ },
+ /* An offline zone has no write pointer on a regular mount either. */
+ {
+ .description = "RAID1: first zone offline",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ WP_MISSING_DEV, SZ_1M,
+ },
+ .expected_alloc_offset = SZ_1M,
+ },
/* Error case: having different write pointers. */
{
.description = "RAID1: fail: different write pointers",
--
2.53.0