* [PATCH] zloop: restore finished zones with reduced capacity
@ 2026-07-31 6:11 raoxu
2026-08-03 13:04 ` Damien Le Moal
0 siblings, 1 reply; 7+ messages in thread
From: raoxu @ 2026-07-31 6:11 UTC (permalink / raw)
To: dlemoal; +Cc: axboe, hch, linux-block, linux-kernel, raoxu, stable
From: Xu Rao <raoxu@uniontech.com>
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@vger.kernel.org
Signed-off-by: Xu Rao <raoxu@uniontech.com>
---
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 &&
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] zloop: restore finished zones with reduced capacity 2026-07-31 6:11 [PATCH] zloop: restore finished zones with reduced capacity raoxu @ 2026-08-03 13:04 ` Damien Le Moal 2026-08-04 2:34 ` [PATCH v2] zloop: truncate finished zones to zone capacity raoxu 0 siblings, 1 reply; 7+ messages in thread From: Damien Le Moal @ 2026-08-03 13:04 UTC (permalink / raw) To: raoxu; +Cc: axboe, hch, linux-block, linux-kernel, stable On 7/31/26 15:11, raoxu wrote: > From: Xu Rao <raoxu@uniontech.com> > > 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@vger.kernel.org > Signed-off-by: Xu Rao <raoxu@uniontech.com> > --- > 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] zloop: truncate finished zones to zone capacity 2026-08-03 13:04 ` Damien Le Moal @ 2026-08-04 2:34 ` raoxu 2026-08-04 4:26 ` Damien Le Moal ` (3 more replies) 0 siblings, 4 replies; 7+ messages in thread From: raoxu @ 2026-08-04 2:34 UTC (permalink / raw) To: dlemoal; +Cc: axboe, hch, linux-block, linux-kernel, raoxu, stable From: Xu Rao <raoxu@uniontech.com> The size of a sequential zone backing file records the amount of data written and is used to restore the zone state. A backing file whose size is equal to the zone capacity is restored as a full zone, while a file larger than the zone capacity is rejected as invalid. However, zloop_finish_zone() currently truncates the backing file to the zone size. For devices with a reduced zone capacity, finishing a zone therefore creates a backing file larger than the zone capacity. After the device is removed and later re-added, that zone file is rejected instead of being restored as a full zone. Truncate finished sequential zones to the zone capacity, matching the persistent representation accepted by zloop_update_seq_zone() for a full zone. Suggested-by: Damien Le Moal <dlemoal@kernel.org> Fixes: eb0570c7df23 ("block: new zoned loop block device driver") Cc: stable@vger.kernel.org Signed-off-by: Xu Rao <raoxu@uniontech.com> --- Changes in v2: - Fix zloop_finish_zone() instead of accepting oversized backing files in zloop_update_seq_zone(), as suggested by Damien. - Update documentation to describe the corrected backing file size. Documentation/admin-guide/blockdev/zoned_loop.rst | 9 ++++----- drivers/block/zloop.c | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zoned_loop.rst b/Documentation/admin-guide/blockdev/zoned_loop.rst index f4f1f3121bf9..95974425ca05 100644 --- a/Documentation/admin-guide/blockdev/zoned_loop.rst +++ b/Documentation/admin-guide/blockdev/zoned_loop.rst @@ -30,11 +30,10 @@ indicates the position of the write pointer of the zone. When resetting a sequential zone, its backing file size is truncated to zero. Conversely, for a zone finish operation, the backing file is truncated to the -zone size. With this, the maximum capacity of a zloop zoned block device created -can be larger configured to be larger than the storage space available on the -backing file system. Of course, for such configuration, writing more data than -the storage space available on the backing file system will result in write -errors. +zone capacity. With this, a zloop zoned block device can be configured with a +larger capacity than the storage space available on the backing file system. Of +course, for such configuration, writing more data than the storage space +available on the backing file system will result in write errors. The zoned loop block device driver implements a complete zone transition state machine. That is, zones can be empty, implicitly opened, explicitly opened, diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c index 55eeb6aac0ea..1333fae05ac5 100644 --- a/drivers/block/zloop.c +++ b/drivers/block/zloop.c @@ -478,7 +478,8 @@ static int zloop_finish_zone(struct zloop_device *zlo, unsigned int zone_no) zone->cond == BLK_ZONE_COND_FULL) goto unlock; - if (vfs_truncate(&zone->file->f_path, zlo->zone_size << SECTOR_SHIFT)) { + if (vfs_truncate(&zone->file->f_path, + zlo->zone_capacity << SECTOR_SHIFT)) { set_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags); ret = -EIO; goto unlock; -- 2.50.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] zloop: truncate finished zones to zone capacity 2026-08-04 2:34 ` [PATCH v2] zloop: truncate finished zones to zone capacity raoxu @ 2026-08-04 4:26 ` Damien Le Moal 2026-08-04 12:36 ` Christoph Hellwig ` (2 subsequent siblings) 3 siblings, 0 replies; 7+ messages in thread From: Damien Le Moal @ 2026-08-04 4:26 UTC (permalink / raw) To: raoxu; +Cc: axboe, hch, linux-block, linux-kernel, stable On 8/4/26 11:34, raoxu wrote: > From: Xu Rao <raoxu@uniontech.com> > > The size of a sequential zone backing file records the amount of data > written and is used to restore the zone state. A backing file whose size > is equal to the zone capacity is restored as a full zone, while a file > larger than the zone capacity is rejected as invalid. > > However, zloop_finish_zone() currently truncates the backing file to the > zone size. For devices with a reduced zone capacity, finishing a zone > therefore creates a backing file larger than the zone capacity. After the > device is removed and later re-added, that zone file is rejected instead > of being restored as a full zone. > > Truncate finished sequential zones to the zone capacity, matching the > persistent representation accepted by zloop_update_seq_zone() for a full > zone. > > Suggested-by: Damien Le Moal <dlemoal@kernel.org> > Fixes: eb0570c7df23 ("block: new zoned loop block device driver") > Cc: stable@vger.kernel.org > Signed-off-by: Xu Rao <raoxu@uniontech.com> Looks good. Reviewed-by: Damien Le Moal <dlemoal@kernel.org> -- Damien Le Moal Western Digital Research ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] zloop: truncate finished zones to zone capacity 2026-08-04 2:34 ` [PATCH v2] zloop: truncate finished zones to zone capacity raoxu 2026-08-04 4:26 ` Damien Le Moal @ 2026-08-04 12:36 ` Christoph Hellwig 2026-08-04 12:37 ` Christoph Hellwig 2026-08-04 13:00 ` Jens Axboe 3 siblings, 0 replies; 7+ messages in thread From: Christoph Hellwig @ 2026-08-04 12:36 UTC (permalink / raw) To: raoxu; +Cc: dlemoal, axboe, hch, linux-block, linux-kernel, stable Looks good: Reviewed-by: Christoph Hellwig <hch@lst.de> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] zloop: truncate finished zones to zone capacity 2026-08-04 2:34 ` [PATCH v2] zloop: truncate finished zones to zone capacity raoxu 2026-08-04 4:26 ` Damien Le Moal 2026-08-04 12:36 ` Christoph Hellwig @ 2026-08-04 12:37 ` Christoph Hellwig 2026-08-04 13:00 ` Jens Axboe 3 siblings, 0 replies; 7+ messages in thread From: Christoph Hellwig @ 2026-08-04 12:37 UTC (permalink / raw) To: raoxu; +Cc: dlemoal, axboe, hch, linux-block, linux-kernel, stable On Tue, Aug 04, 2026 at 10:34:03AM +0800, raoxu wrote: > However, zloop_finish_zone() currently truncates the backing file to the > zone size. For devices with a reduced zone capacity, finishing a zone > therefore creates a backing file larger than the zone capacity. After the > device is removed and later re-added, that zone file is rejected instead > of being restored as a full zone. Can you add a blktests test case for this? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] zloop: truncate finished zones to zone capacity 2026-08-04 2:34 ` [PATCH v2] zloop: truncate finished zones to zone capacity raoxu ` (2 preceding siblings ...) 2026-08-04 12:37 ` Christoph Hellwig @ 2026-08-04 13:00 ` Jens Axboe 3 siblings, 0 replies; 7+ messages in thread From: Jens Axboe @ 2026-08-04 13:00 UTC (permalink / raw) To: dlemoal, raoxu; +Cc: hch, linux-block, linux-kernel, stable On Tue, 04 Aug 2026 10:34:03 +0800, raoxu wrote: > The size of a sequential zone backing file records the amount of data > written and is used to restore the zone state. A backing file whose size > is equal to the zone capacity is restored as a full zone, while a file > larger than the zone capacity is rejected as invalid. > > However, zloop_finish_zone() currently truncates the backing file to the > zone size. For devices with a reduced zone capacity, finishing a zone > therefore creates a backing file larger than the zone capacity. After the > device is removed and later re-added, that zone file is rejected instead > of being restored as a full zone. > > [...] Applied, thanks! [1/1] zloop: truncate finished zones to zone capacity commit: 72e67c118642634c25465db0c8bcfa54c4ce086c Best regards, -- Jens Axboe ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-08-04 13:00 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-31 6:11 [PATCH] zloop: restore finished zones with reduced capacity raoxu 2026-08-03 13:04 ` Damien Le Moal 2026-08-04 2:34 ` [PATCH v2] zloop: truncate finished zones to zone capacity raoxu 2026-08-04 4:26 ` Damien Le Moal 2026-08-04 12:36 ` Christoph Hellwig 2026-08-04 12:37 ` Christoph Hellwig 2026-08-04 13:00 ` Jens Axboe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox