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 2/5] btrfs: zoned: take the RAID1 zone capacity from all present stripes
Date: Sat, 21 Nov 2026 13:45:46 +0000 [thread overview]
Message-ID: <20261121134550.216217-3-mc@raidlab.org> (raw)
In-Reply-To: <20261121134550.216217-1-mc@raidlab.org>
btrfs_load_block_group_raid1() takes the zone capacity of a block group
from stripes 0 and 1 only, also when it creates one. RAID1C3 and RAID1C4
have more stripes, and that goes wrong in two ways.
A missing device has a capacity of 0, which min_not_zero() skips, but
with stripes 0 and 1 both missing the capacity is 0. Once the block
group 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
A third or fourth stripe with a smaller capacity is ignored, so the
block group is written past the end of that stripe's zone, and those
writes fail:
I/O error, dev nb2, sector 122880 op 0x7:(ZONE_APPEND) flags 0xc800 phys_seg 2 prio class 2
Take the smallest capacity of all present stripes.
RAID1C3 and RAID1C4 block groups already written past a smaller third or
fourth stripe failed a regular mount before. Now a degraded mount with
all devices present refuses them too, where it loaded them with the
larger capacity. A degraded mount without the device with the smaller
capacity still loads them.
Fixes: 568220fa9657 ("btrfs: zoned: support RAID0/1/10 on top of raid stripe tree")
CC: stable@vger.kernel.org # 6.7+
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
v2: was 3/4. Takes the smallest capacity of all present stripes now, not
only when stripes 0 and 1 are missing. A smaller third or fourth stripe
was ignored too.
Found in an LLM review of this series. The fix and the commit message
were prepared with the help of an LLM, which also tested it. I reviewed
everything.
The next patch takes care of full zones that report different
capacities.
fs/btrfs/zoned.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 8eac6e2283a2..ce7c535adff6 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1532,7 +1532,9 @@ 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);
+ bg->zone_capacity = 0;
+ for (i = 0; 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
next 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 with missing or stale stripes 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 ` Miroslav Cimerman [this message]
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 ` [PATCH v2 5/5] btrfs: tests: zoned: add RAID1 cases with missing or stale stripes Miroslav Cimerman
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-3-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