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>, Damien Le Moal <dlemoal@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] btrfs: zoned: tolerate a failed zone finish on a full block group
Date: Sun, 22 Nov 2026 23:23:09 +0000 [thread overview]
Message-ID: <20261122232310.4099580-3-mc@raidlab.org> (raw)
In-Reply-To: <20261122232310.4099580-1-mc@raidlab.org>
do_zone_finish() sends ZONE_FINISH to the zone of each stripe of a block
group. It stops at the first error and returns it, even if the profile
tolerates the failed device. Since commit 3d16abf6c88a ("btrfs: zoned:
directly call do_zone_finish() from btrfs_zone_finish_endio_workfn()"),
btrfs_zone_finish_endio_workfn() handles that error with
btrfs_handle_fs_error(). So one failed device of a RAID1 metadata block
group turns the filesystem read-only.
When the block group is allocated up to the zone capacity and
everything is written, the zones are already full on the devices. A
failed ZONE_FINISH does not change them. In this case, finish the zones
of all stripes. Like a write, fail only if more devices failed than the
profile tolerates. Count a missing device toward the limit. The failed
device keeps the zone counted as active until the zone is reset or the
filesystem is remounted. For metadata, the active zone reservation
comes back only at the next mount.
A partly written block group keeps the current behavior. It stops at
the first error and returns it. Finishing the zones after a failed one
would leave more zones at different write pointers.
btrfs_load_block_group_raid1() refuses such a block group at the next
mount.
Fixes: 3d16abf6c88a ("btrfs: zoned: directly call do_zone_finish() from btrfs_zone_finish_endio_workfn()")
CC: stable@vger.kernel.org # 6.18+: a18a6b93a284: btrfs: zoned: finish active block group cleanup if call_zone_finish() fails
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
fs/btrfs/zoned.c | 48 ++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 42 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 45bd05d8edb4..d18dc4f4dc33 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2540,9 +2540,6 @@ static int call_zone_finish(struct btrfs_block_group *block_group,
bool cleared;
int ret;
- if (!device->bdev)
- return 0;
-
if (zinfo->max_active_zones == 0)
return 0;
@@ -2573,6 +2570,9 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
const bool is_metadata = (block_group->flags &
(BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM));
struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
+ enum btrfs_raid_types index;
+ bool zones_full;
+ int failed = 0;
int ret = 0;
int i;
@@ -2639,6 +2639,13 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
}
clear_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags);
+ /*
+ * If the block group is allocated up to the zone capacity,
+ * everything is written and the zones should be full already. A
+ * truncated or failed write at the end is not detected here. That
+ * would need a zone report from every device.
+ */
+ zones_full = (block_group->alloc_offset == block_group->zone_capacity);
block_group->alloc_offset = block_group->zone_capacity;
if (block_group->flags & (BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_SYSTEM))
block_group->meta_write_pointer = block_group->start +
@@ -2651,12 +2658,41 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
down_read(&dev_replace->rwsem);
map = block_group->physical_map;
for (i = 0; i < map->num_stripes; i++) {
- ret = call_zone_finish(block_group, &map->stripes[i]);
- if (ret)
- break;
+ struct btrfs_io_stripe *stripe = &map->stripes[i];
+ int err;
+
+ if (!stripe->dev->bdev) {
+ failed++;
+ continue;
+ }
+
+ err = call_zone_finish(block_group, stripe);
+ if (err) {
+ btrfs_warn(fs_info,
+ "zoned: failed to finish zone at physical %llu on devid %llu: %d",
+ stripe->physical, stripe->dev->devid, err);
+ failed++;
+ ret = err;
+ /*
+ * Do not finish more zones of a partly written block
+ * group. They would end at a different write pointer
+ * than the failed one.
+ */
+ if (!zones_full)
+ break;
+ }
}
up_read(&dev_replace->rwsem);
+ /*
+ * Zones that are already full do not change with a failed finish.
+ * Like a write, fail only if more devices failed than the profile
+ * tolerates. A missing device counts toward the limit.
+ */
+ index = btrfs_bg_flags_to_raid_index(map->type);
+ if (zones_full && failed <= btrfs_raid_array[index].tolerated_failures)
+ ret = 0;
+
if (!ret && !fully_written)
btrfs_dec_block_group_ro(block_group);
--
2.53.0
next prev parent reply other threads:[~2026-11-22 23:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 23:23 [PATCH 0/3] btrfs: zoned: handle a failed zone finish on one device Miroslav Cimerman
2026-11-22 23:23 ` [PATCH 1/3] btrfs: zoned: do not fail an ordered extent on a zone finish error Miroslav Cimerman
2026-11-22 23:23 ` Miroslav Cimerman [this message]
2026-11-22 23:23 ` [PATCH 3/3] btrfs: zoned: do not WARN when zones fail to finish before relocation 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=20261122232310.4099580-3-mc@raidlab.org \
--to=mc@raidlab.org \
--cc=dlemoal@kernel.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