[PATCH 1/3] btrfs: zoned: do not fail an ordered extent on a zone finish error
From: Miroslav Cimerman
Date: Sun Nov 22 2026 - 18:23:28 EST
When an ordered extent ends at the zone capacity of its block group,
btrfs_zone_finish_endio() finishes the zones of the block group. Since
commit c428b763f29b ("btrfs: zoned: propagate do_zone_finish() error in
btrfs_zone_finish_endio()"), it returns the error of do_zone_finish().
btrfs_finish_one_ordered() then fails the ordered extent. It skips the
file extent item that points the file to the new data. It also frees the
new extent.
However, the data of the ordered extent is already written. Only the
ZONE_FINISH command failed, for example on one device of a RAID1 block
group. The write is still lost:
O_DIRECT overwrite, the last extent ends at the zone capacity
write and sync return 0
ZONE_FINISH fails on one device
btrfs_finish_one_ordered(): no file extent item, extent freed
first O_DIRECT read of the file: -EIO (writeback error of the mapping)
later reads, also after a remount: the old data of that extent
do_zone_finish() marks the block group as finished before it sends
ZONE_FINISH, so nothing writes to these zones anymore. Report the error
and let the ordered extent complete, as before that commit.
Fixes: c428b763f29b ("btrfs: zoned: propagate do_zone_finish() error in btrfs_zone_finish_endio()")
CC: stable@xxxxxxxxxxxxxxx # 7.3+
Signed-off-by: Miroslav Cimerman <mc@xxxxxxxxxxx>
---
fs/btrfs/zoned.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index e6ce6f05ad75..45bd05d8edb4 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2783,7 +2783,7 @@ int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 leng
{
struct btrfs_block_group *block_group;
u64 min_alloc_bytes;
- int ret = 0;
+ int ret;
if (!btrfs_is_zoned(fs_info))
return 0;
@@ -2803,11 +2803,18 @@ int btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 leng
block_group->start + block_group->zone_capacity)
goto out;
+ /*
+ * The data of the ordered extent is written. A failure to finish the
+ * zones does not change that, so only report it.
+ */
ret = do_zone_finish(block_group, true);
+ if (ret)
+ btrfs_warn(fs_info, "zoned: failed to finish zones of block group %llu: %d",
+ block_group->start, ret);
out:
btrfs_put_block_group(block_group);
- return ret;
+ return 0;
}
static void btrfs_zone_finish_endio_workfn(struct work_struct *work)
--
2.53.0