Re: [PATCH] zloop: restore finished zones with reduced capacity

From: Damien Le Moal

Date: Mon Aug 03 2026 - 09:07:42 EST


On 7/31/26 15:11, raoxu wrote:
> From: Xu Rao <raoxu@xxxxxxxxxxxxx>
>
> zloop_finish_zone() truncates a finished sequential zone backing file to
> zone_size. When zone_capacity is smaller than zone_size,
> zloop_update_seq_zone() rejects that file when the device is re-added
> because it treats every file larger than zone_capacity as invalid.
>
> Documentation/admin-guide/blockdev/zoned_loop.rst, section "Overview",
> states that a zone finish operation truncates the backing file to the zone
> size. A file whose size equals zone_size is therefore a valid
> representation of a finished zone.
>
> Accept both zone_capacity and zone_size as full-zone representations. Keep
> rejecting all other files larger than zone_capacity.
>
> Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Xu Rao <raoxu@xxxxxxxxxxxxx>
> ---
> drivers/block/zloop.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
> index 55eeb6aac0ea..b69d798f203c 100644
> --- a/drivers/block/zloop.c
> +++ b/drivers/block/zloop.c
> @@ -324,7 +324,8 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)
> }
>
> file_sectors = stat.size >> SECTOR_SHIFT;
> - if (file_sectors > zlo->zone_capacity) {
> + if (file_sectors > zlo->zone_capacity &&
> + file_sectors != zlo->zone_size) {
> pr_err("Zone %u file too large (%llu sectors > %llu)\n",
> zone_no, file_sectors, zlo->zone_capacity);
> return -EINVAL;
> @@ -339,7 +340,8 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)
> spin_lock(&zone->wp_lock);
> if (!file_sectors) {
> zloop_mark_empty(zlo, zone);
> - } else if (file_sectors == zlo->zone_capacity) {
> + } else if (file_sectors == zlo->zone_capacity ||
> + file_sectors == zlo->zone_size) {
> zloop_mark_full(zlo, zone);
> } else {
> if (zone->cond != BLK_ZONE_COND_IMP_OPEN &&

The problem comes from at least zloop_finish_zone() which truncates a zone file
to zlo->zone_size << SECTOR_SHIFT instead of zlo->zone_capacity << SECTOR_SHIFT.
So I think that is what we need to fix.

--
Damien Le Moal
Western Digital Research