From: Miroslav Cimerman <mc@raidlab.org>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>, Chris Mason <mason@kernel.org>,
Naohiro Aota <naohiro.aota@wdc.com>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] btrfs: tests: zoned: add degraded RAID1 cases
Date: Thu, 19 Nov 2026 21:38:35 +0000 [thread overview]
Message-ID: <20261119213835.103131-5-mc@raidlab.org> (raw)
In-Reply-To: <20261119213835.103131-1-mc@raidlab.org>
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@raidlab.org>
---
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
prev parent reply other threads:[~2026-11-19 21:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 21:38 [PATCH 0/4] btrfs: zoned: RAID1 block groups with missing or stale stripes Miroslav Cimerman
2026-11-19 21:38 ` [PATCH 1/4] btrfs: zoned: take the RAID1 active state from the first present stripe Miroslav Cimerman
2026-11-19 21:38 ` [PATCH 2/4] btrfs: zoned: use the highest RAID1 write pointer on degraded mounts Miroslav Cimerman
2026-11-19 21:38 ` [PATCH 3/4] btrfs: zoned: take the RAID1 zone capacity from a present stripe Miroslav Cimerman
2026-11-19 21:38 ` Miroslav Cimerman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119213835.103131-5-mc@raidlab.org \
--to=mc@raidlab.org \
--cc=dsterba@suse.com \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=naohiro.aota@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®