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>,
Qu Wenruo <wqu@suse.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/5] btrfs: tests: zoned: add RAID1 cases with missing or stale stripes
Date: Sat, 21 Nov 2026 13:45:49 +0000 [thread overview]
Message-ID: <20261121134550.216217-6-mc@raidlab.org> (raw)
In-Reply-To: <20261121134550.216217-1-mc@raidlab.org>
Add cases for the previous patches. On a degraded mount:
- RAID1 with the first device missing, and RAID1 metadata with an empty
first zone: both are marked active
- RAID1C3 with the first and the last, and with the first two devices
missing
- RAID1 and RAID1C3 with different write pointers: the highest one is
taken
- RAID1 with full zones of different capacities
- RAID1 with a full zone that has extents past the smaller capacity: not
capped, so the caller then refuses the block group
On a regular mount:
- RAID1 with the first zone offline, with a failed zone report for it,
and with full zones of different capacities: now load
- RAID1C3 with a smaller third zone: sets the capacity
- two cases that still fail: a write pointer past the capacity in a zone
that is not full, and full zones with extents past the capacity
Let a case set the zone capacity of each stripe. A stripe without a
write pointer has a capacity of 0 unless the case sets one:
btrfs_load_zone_info() gives 0 for a missing device or a failed zone
report, while an offline zone keeps its capacity. Derive the active
state from the write pointer and the capacity, and check the zone
capacity and the active state where a case asks for it. All new cases
fail without the previous patches, except the two that fail either way.
Those make sure that only full zones without extents past the capacity
are capped.
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
v2 (was 4/4): add the cases with an empty first zone, with different
zone capacities and with a failed zone report, and a capacity per
stripe. The case with an offline zone gives that zone a capacity now.
The subject was "btrfs: tests: zoned: add degraded RAID1 cases", but
6 of the 14 new cases are on a regular mount.
Prepared with the help of an LLM, which also ran the tests. I reviewed
everything.
fs/btrfs/tests/zoned-tests.c | 203 ++++++++++++++++++++++++++++++++++-
1 file changed, 201 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/tests/zoned-tests.c b/fs/btrfs/tests/zoned-tests.c
index bb9969210444..4848aa6fde11 100644
--- a/fs/btrfs/tests/zoned-tests.c
+++ b/fs/btrfs/tests/zoned-tests.c
@@ -21,12 +21,15 @@ struct load_zone_info_test_vector {
u64 raid_type;
u64 num_stripes;
u64 alloc_offsets[8];
+ u64 capacities[8];
u64 last_alloc;
u64 bg_length;
bool degraded;
int expected_result;
u64 expected_alloc_offset;
+ u64 expected_zone_capacity;
+ bool expected_active;
const char *description;
};
@@ -77,8 +80,16 @@ 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;
- if (zone_info[i].alloc_offset && zone_info[i].alloc_offset < ZONE_SIZE)
+ /*
+ * Without a write pointer, the capacity is 0 for a missing device
+ * or a failed zone report, while an offline zone keeps its own.
+ */
+ if (zone_info[i].alloc_offset == WP_MISSING_DEV)
+ zone_info[i].capacity = test->capacities[i];
+ else
+ zone_info[i].capacity = test->capacities[i] ?: ZONE_SIZE;
+ if (zone_info[i].alloc_offset &&
+ zone_info[i].alloc_offset < zone_info[i].capacity)
__set_bit(i, active);
}
if (test->degraded)
@@ -101,6 +112,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,7 +268,182 @@ 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: metadata, empty first zone on DEGRADED",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ 0, SZ_1M,
+ },
+ .degraded = true,
+ .expected_alloc_offset = SZ_1M,
+ .expected_active = true,
+ },
+ {
+ .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 or a failed zone report has no write pointer on a
+ * regular mount either. An offline zone still has its capacity.
+ */
+ {
+ .description = "RAID1: first zone offline",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ WP_MISSING_DEV, SZ_1M,
+ },
+ .capacities = {
+ ZONE_SIZE - SZ_1M,
+ },
+ .expected_alloc_offset = SZ_1M,
+ .expected_zone_capacity = ZONE_SIZE - SZ_1M,
+ },
+ {
+ .description = "RAID1: failed zone report of the first zone",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ WP_MISSING_DEV, SZ_1M,
+ },
+ .expected_alloc_offset = SZ_1M,
+ .expected_zone_capacity = ZONE_SIZE,
+ },
+ /* The block group's capacity is the smallest of its stripes'. */
+ {
+ .description = "RAID1C3: smaller third zone capacity",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1C3,
+ .num_stripes = 3,
+ .alloc_offsets = {
+ SZ_1M, SZ_1M, SZ_1M,
+ },
+ .capacities = {
+ ZONE_SIZE, ZONE_SIZE, ZONE_SIZE - SZ_1M,
+ },
+ .expected_alloc_offset = SZ_1M,
+ .expected_zone_capacity = ZONE_SIZE - SZ_1M,
+ },
+ /* Full zones report their own capacity, which can differ by device. */
+ {
+ .description = "RAID1: full zones with different capacities",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ ZONE_SIZE - SZ_1M, ZONE_SIZE,
+ },
+ .capacities = {
+ ZONE_SIZE - SZ_1M, ZONE_SIZE,
+ },
+ .last_alloc = ZONE_SIZE - SZ_1M,
+ .expected_alloc_offset = ZONE_SIZE - SZ_1M,
+ .expected_zone_capacity = ZONE_SIZE - SZ_1M,
+ },
+ {
+ .description = "RAID1: full zones with different capacities on DEGRADED",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ ZONE_SIZE, ZONE_SIZE - SZ_1M,
+ },
+ .capacities = {
+ ZONE_SIZE, ZONE_SIZE - SZ_1M,
+ },
+ .last_alloc = ZONE_SIZE - SZ_1M,
+ .degraded = true,
+ .expected_alloc_offset = ZONE_SIZE - SZ_1M,
+ .expected_zone_capacity = ZONE_SIZE - SZ_1M,
+ },
+ {
+ .description = "RAID1: full zone with extents past the capacity on DEGRADED",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ SZ_1M, ZONE_SIZE,
+ },
+ .capacities = {
+ ZONE_SIZE - SZ_1M, ZONE_SIZE,
+ },
+ .last_alloc = ZONE_SIZE,
+ .degraded = true,
+ .expected_alloc_offset = ZONE_SIZE,
+ .expected_zone_capacity = ZONE_SIZE - SZ_1M,
+ },
/* Error case: having different write pointers. */
+ {
+ .description = "RAID1: fail: write pointer past the capacity",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ ZONE_SIZE - SZ_1M, ZONE_SIZE - SZ_512K,
+ },
+ .capacities = {
+ ZONE_SIZE - SZ_1M, ZONE_SIZE,
+ },
+ .expected_result = -EIO,
+ },
+ {
+ .description = "RAID1: fail: full zones with extents past the capacity",
+ .raid_type = BTRFS_BLOCK_GROUP_RAID1,
+ .num_stripes = 2,
+ .alloc_offsets = {
+ ZONE_SIZE - SZ_1M, ZONE_SIZE,
+ },
+ .capacities = {
+ ZONE_SIZE - SZ_1M, ZONE_SIZE,
+ },
+ .last_alloc = ZONE_SIZE,
+ .expected_result = -EIO,
+ },
{
.description = "RAID1: fail: different write pointers",
.raid_type = BTRFS_BLOCK_GROUP_RAID1,
--
2.53.0
prev parent reply other threads:[~2026-11-21 13:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 13:45 [PATCH v2 0/5] btrfs: zoned: RAID1 block groups " Miroslav Cimerman
2026-11-21 13:45 ` [PATCH v2 1/5] btrfs: zoned: take the RAID1 active state from the first present stripe Miroslav Cimerman
2026-11-21 13:45 ` [PATCH v2 2/5] btrfs: zoned: take the RAID1 zone capacity from all present stripes Miroslav Cimerman
2026-11-21 13:45 ` [PATCH v2 3/5] btrfs: zoned: cap full RAID1 zones at the block group's capacity Miroslav Cimerman
2026-11-21 13:45 ` [PATCH v2 4/5] btrfs: zoned: use the highest RAID1 write pointer on degraded mounts Miroslav Cimerman
2026-11-21 13:45 ` 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=20261121134550.216217-6-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 \
--cc=wqu@suse.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®