* zloop fixes
@ 2026-10-29 15:03 Christoph Hellwig
2026-10-29 15:03 ` [PATCH 1/4] zloop: remove a duplicate call to zloop_get_block_size Christoph Hellwig
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Christoph Hellwig @ 2026-10-29 15:03 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe; +Cc: Josef Bacik, linux-block
Hi all,
this series has misc fixes for zloop.
Diffstat:
zloop.c | 80 ++++++++++++++++++++++++++++++----------------------------------
1 file changed, 38 insertions(+), 42 deletions(-)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/4] zloop: remove a duplicate call to zloop_get_block_size
2026-10-29 15:03 zloop fixes Christoph Hellwig
@ 2026-10-29 15:03 ` Christoph Hellwig
2026-10-30 1:11 ` Damien Le Moal
2026-10-29 15:03 ` [PATCH 2/4] zloop: share more code for opening a zone backing file Christoph Hellwig
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2026-10-29 15:03 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe; +Cc: Josef Bacik, linux-block
The sequential zone path has two calls to zloop_get_block_size, one
conditional on not having a block size, and one unconditionally.
Remove the latter as the block size only needs to be queried once.
Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/zloop.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 9145e0f98d56..71f7685efb13 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -1183,8 +1183,6 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
return ret;
}
- zloop_get_block_size(zlo, zone);
-
mutex_lock(&zone->lock);
ret = zloop_update_seq_zone(zlo, zone_no);
mutex_unlock(&zone->lock);
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/4] zloop: share more code for opening a zone backing file
2026-10-29 15:03 zloop fixes Christoph Hellwig
2026-10-29 15:03 ` [PATCH 1/4] zloop: remove a duplicate call to zloop_get_block_size Christoph Hellwig
@ 2026-10-29 15:03 ` Christoph Hellwig
2026-10-30 1:10 ` Damien Le Moal
2026-10-29 15:03 ` [PATCH 3/4] zloop: fput file after failed zone init Christoph Hellwig
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2026-10-29 15:03 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe; +Cc: Josef Bacik, linux-block
Use a common path for opening and querying the block size.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/zloop.c | 65 +++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 39 deletions(-)
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 71f7685efb13..3dc484e3c700 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -1107,8 +1107,6 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
{
struct zloop_zone *zone = &zlo->zones[zone_no];
int oflags = O_RDWR;
- struct kstat stat;
- sector_t file_sectors;
int ret;
mutex_init(&zone->lock);
@@ -1122,27 +1120,33 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
if (!opts->buffered_io)
oflags |= O_DIRECT;
+ zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/%s-%06u",
+ zlo->base_dir, zlo->id,
+ zone_no < zlo->nr_conv_zones ? "cnv" : "seq",
+ zone_no);
+ if (IS_ERR(zone->file)) {
+ pr_err("Failed to open zone %u file %s/%u/%s-%06u (err=%ld)",
+ zone_no, zlo->base_dir, zlo->id,
+ zone_no < zlo->nr_conv_zones ? "cnv" : "seq",
+ zone_no, PTR_ERR(zone->file));
+ return PTR_ERR(zone->file);
+ }
+
+ if (zlo->block_size) {
+ ret = zloop_get_block_size(zlo, zone);
+ if (ret)
+ return ret;
+ }
+
if (zone_no < zlo->nr_conv_zones) {
+ sector_t file_sectors;
+ struct kstat stat;
+
/* Conventional zone file. */
set_bit(ZLOOP_ZONE_CONV, &zone->flags);
zone->cond = BLK_ZONE_COND_NOT_WP;
zone->wp = U64_MAX;
- zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/cnv-%06u",
- zlo->base_dir, zlo->id, zone_no);
- if (IS_ERR(zone->file)) {
- pr_err("Failed to open zone %u file %s/%u/cnv-%06u (err=%ld)",
- zone_no, zlo->base_dir, zlo->id, zone_no,
- PTR_ERR(zone->file));
- return PTR_ERR(zone->file);
- }
-
- if (!zlo->block_size) {
- ret = zloop_get_block_size(zlo, zone);
- if (ret)
- return ret;
- }
-
ret = vfs_getattr(&zone->file->f_path, &stat, STATX_SIZE, 0);
if (ret < 0) {
pr_err("Failed to get zone %u file stat\n", zone_no);
@@ -1163,30 +1167,13 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
zone_no, ret);
return ret;
}
-
- return 0;
- }
-
- /* Sequential zone file. */
- zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/seq-%06u",
- zlo->base_dir, zlo->id, zone_no);
- if (IS_ERR(zone->file)) {
- pr_err("Failed to open zone %u file %s/%u/seq-%06u (err=%ld)",
- zone_no, zlo->base_dir, zlo->id, zone_no,
- PTR_ERR(zone->file));
- return PTR_ERR(zone->file);
- }
-
- if (!zlo->block_size) {
- ret = zloop_get_block_size(zlo, zone);
- if (ret)
- return ret;
+ } else {
+ /* Sequential zone file. */
+ mutex_lock(&zone->lock);
+ ret = zloop_update_seq_zone(zlo, zone_no);
+ mutex_unlock(&zone->lock);
}
- mutex_lock(&zone->lock);
- ret = zloop_update_seq_zone(zlo, zone_no);
- mutex_unlock(&zone->lock);
-
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/4] zloop: fput file after failed zone init
2026-10-29 15:03 zloop fixes Christoph Hellwig
2026-10-29 15:03 ` [PATCH 1/4] zloop: remove a duplicate call to zloop_get_block_size Christoph Hellwig
2026-10-29 15:03 ` [PATCH 2/4] zloop: share more code for opening a zone backing file Christoph Hellwig
@ 2026-10-29 15:03 ` Christoph Hellwig
2026-10-30 1:11 ` Damien Le Moal
2026-10-29 15:03 ` [PATCH 4/4] zloop: check that the zone backing file support ->{read,write}_iter Christoph Hellwig
2026-10-29 15:34 ` zloop fixes Jens Axboe
4 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2026-10-29 15:03 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe; +Cc: Josef Bacik, linux-block
Clean up after failure in zloop_init_zone, as the caller only cleans up
the zones before the current one.
Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/zloop.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 3dc484e3c700..f0aca9d43851 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -1135,7 +1135,7 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
if (zlo->block_size) {
ret = zloop_get_block_size(zlo, zone);
if (ret)
- return ret;
+ goto out_fput;
}
if (zone_no < zlo->nr_conv_zones) {
@@ -1150,14 +1150,14 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
ret = vfs_getattr(&zone->file->f_path, &stat, STATX_SIZE, 0);
if (ret < 0) {
pr_err("Failed to get zone %u file stat\n", zone_no);
- return ret;
+ goto out_fput;
}
file_sectors = stat.size >> SECTOR_SHIFT;
if (restore && file_sectors != zlo->zone_size) {
pr_err("Invalid conventional zone %u file size (%llu sectors != %llu)\n",
zone_no, file_sectors, zlo->zone_capacity);
- return ret;
+ goto out_fput;
}
ret = vfs_truncate(&zone->file->f_path,
@@ -1165,15 +1165,21 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
if (ret < 0) {
pr_err("Failed to truncate zone %u file (err=%d)\n",
zone_no, ret);
- return ret;
+ goto out_fput;
}
} else {
/* Sequential zone file. */
mutex_lock(&zone->lock);
ret = zloop_update_seq_zone(zlo, zone_no);
mutex_unlock(&zone->lock);
+ if (ret)
+ goto out_fput;
}
+ return 0;
+
+out_fput:
+ fput(zone->file);
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/4] zloop: check that the zone backing file support ->{read,write}_iter
2026-10-29 15:03 zloop fixes Christoph Hellwig
` (2 preceding siblings ...)
2026-10-29 15:03 ` [PATCH 3/4] zloop: fput file after failed zone init Christoph Hellwig
@ 2026-10-29 15:03 ` Christoph Hellwig
2026-10-30 1:11 ` Damien Le Moal
2026-10-29 15:34 ` zloop fixes Jens Axboe
4 siblings, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2026-10-29 15:03 UTC (permalink / raw)
To: Damien Le Moal, Jens Axboe; +Cc: Josef Bacik, linux-block
I/O to backing files requires support for iter based read/write, so check
for that upfront instead of dereferencing a NULL pointer later.
Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
Reported-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/block/zloop.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index f0aca9d43851..65634a39b0bf 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -1132,6 +1132,11 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
return PTR_ERR(zone->file);
}
+ if (!zone->file->f_op->read_iter || !zone->file->f_op->write_iter) {
+ ret = -EINVAL;
+ goto out_fput;
+ }
+
if (zlo->block_size) {
ret = zloop_get_block_size(zlo, zone);
if (ret)
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: zloop fixes
2026-10-29 15:03 zloop fixes Christoph Hellwig
` (3 preceding siblings ...)
2026-10-29 15:03 ` [PATCH 4/4] zloop: check that the zone backing file support ->{read,write}_iter Christoph Hellwig
@ 2026-10-29 15:34 ` Jens Axboe
4 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2026-10-29 15:34 UTC (permalink / raw)
To: Damien Le Moal, Christoph Hellwig; +Cc: Josef Bacik, linux-block
On Thu, 29 Oct 2026 16:03:31 +0100, Christoph Hellwig wrote:
> this series has misc fixes for zloop.
>
> Diffstat:
> zloop.c | 80 ++++++++++++++++++++++++++++++----------------------------------
> 1 file changed, 38 insertions(+), 42 deletions(-)
Applied, thanks!
[1/4] zloop: remove a duplicate call to zloop_get_block_size
commit: 0835f4909553e78a97d1ac59ed6eb776b4f78c92
[2/4] zloop: share more code for opening a zone backing file
commit: 5e9929e2f03c79574e76605e1a82509575db2d30
[3/4] zloop: fput file after failed zone init
commit: 134ffb0755626c91af82fc7debc8b6f75f1f777e
[4/4] zloop: check that the zone backing file support ->{read,write}_iter
commit: 0c10f8a1a7ae1502ea4ea7e13f222df89c28adf4
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/4] zloop: share more code for opening a zone backing file
2026-10-29 15:03 ` [PATCH 2/4] zloop: share more code for opening a zone backing file Christoph Hellwig
@ 2026-10-30 1:10 ` Damien Le Moal
0 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2026-10-30 1:10 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe; +Cc: Josef Bacik, linux-block
On 2026/10/29 22:03, Christoph Hellwig wrote:
> Use a common path for opening and querying the block size.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/block/zloop.c | 65 +++++++++++++++++--------------------------
> 1 file changed, 26 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
> index 71f7685efb13..3dc484e3c700 100644
> --- a/drivers/block/zloop.c
> +++ b/drivers/block/zloop.c
> @@ -1107,8 +1107,6 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
> {
> struct zloop_zone *zone = &zlo->zones[zone_no];
> int oflags = O_RDWR;
> - struct kstat stat;
> - sector_t file_sectors;
> int ret;
>
> mutex_init(&zone->lock);
> @@ -1122,27 +1120,33 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
> if (!opts->buffered_io)
> oflags |= O_DIRECT;
>
> + zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/%s-%06u",
> + zlo->base_dir, zlo->id,
> + zone_no < zlo->nr_conv_zones ? "cnv" : "seq",
> + zone_no);
> + if (IS_ERR(zone->file)) {
> + pr_err("Failed to open zone %u file %s/%u/%s-%06u (err=%ld)",
> + zone_no, zlo->base_dir, zlo->id,
> + zone_no < zlo->nr_conv_zones ? "cnv" : "seq",
> + zone_no, PTR_ERR(zone->file));
> + return PTR_ERR(zone->file);
> + }
> +
> + if (zlo->block_size) {
Shouldn't this be:
if (!zlo->block_size) {
?
Not a huge problem, but no need to repeatedly get the block size for all zones.
Other than that, this is a nice cleanup!
> + ret = zloop_get_block_size(zlo, zone);
> + if (ret)
> + return ret;
> + }
> +
> if (zone_no < zlo->nr_conv_zones) {
> + sector_t file_sectors;
> + struct kstat stat;
> +
> /* Conventional zone file. */
> set_bit(ZLOOP_ZONE_CONV, &zone->flags);
> zone->cond = BLK_ZONE_COND_NOT_WP;
> zone->wp = U64_MAX;
>
> - zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/cnv-%06u",
> - zlo->base_dir, zlo->id, zone_no);
> - if (IS_ERR(zone->file)) {
> - pr_err("Failed to open zone %u file %s/%u/cnv-%06u (err=%ld)",
> - zone_no, zlo->base_dir, zlo->id, zone_no,
> - PTR_ERR(zone->file));
> - return PTR_ERR(zone->file);
> - }
> -
> - if (!zlo->block_size) {
> - ret = zloop_get_block_size(zlo, zone);
> - if (ret)
> - return ret;
> - }
> -
> ret = vfs_getattr(&zone->file->f_path, &stat, STATX_SIZE, 0);
> if (ret < 0) {
> pr_err("Failed to get zone %u file stat\n", zone_no);
> @@ -1163,30 +1167,13 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
> zone_no, ret);
> return ret;
> }
> -
> - return 0;
> - }
> -
> - /* Sequential zone file. */
> - zone->file = zloop_filp_open_fmt(oflags, 0600, "%s/%u/seq-%06u",
> - zlo->base_dir, zlo->id, zone_no);
> - if (IS_ERR(zone->file)) {
> - pr_err("Failed to open zone %u file %s/%u/seq-%06u (err=%ld)",
> - zone_no, zlo->base_dir, zlo->id, zone_no,
> - PTR_ERR(zone->file));
> - return PTR_ERR(zone->file);
> - }
> -
> - if (!zlo->block_size) {
> - ret = zloop_get_block_size(zlo, zone);
> - if (ret)
> - return ret;
> + } else {
> + /* Sequential zone file. */
> + mutex_lock(&zone->lock);
> + ret = zloop_update_seq_zone(zlo, zone_no);
> + mutex_unlock(&zone->lock);
> }
>
> - mutex_lock(&zone->lock);
> - ret = zloop_update_seq_zone(zlo, zone_no);
> - mutex_unlock(&zone->lock);
> -
> return ret;
> }
>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/4] zloop: remove a duplicate call to zloop_get_block_size
2026-10-29 15:03 ` [PATCH 1/4] zloop: remove a duplicate call to zloop_get_block_size Christoph Hellwig
@ 2026-10-30 1:11 ` Damien Le Moal
0 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2026-10-30 1:11 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe; +Cc: Josef Bacik, linux-block
On 2026/10/29 22:03, Christoph Hellwig wrote:
> The sequential zone path has two calls to zloop_get_block_size, one
> conditional on not having a block size, and one unconditionally.
>
> Remove the latter as the block size only needs to be queried once.
>
> Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/4] zloop: fput file after failed zone init
2026-10-29 15:03 ` [PATCH 3/4] zloop: fput file after failed zone init Christoph Hellwig
@ 2026-10-30 1:11 ` Damien Le Moal
0 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2026-10-30 1:11 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe; +Cc: Josef Bacik, linux-block
On 2026/10/29 22:03, Christoph Hellwig wrote:
> Clean up after failure in zloop_init_zone, as the caller only cleans up
> the zones before the current one.
>
> Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/4] zloop: check that the zone backing file support ->{read,write}_iter
2026-10-29 15:03 ` [PATCH 4/4] zloop: check that the zone backing file support ->{read,write}_iter Christoph Hellwig
@ 2026-10-30 1:11 ` Damien Le Moal
0 siblings, 0 replies; 10+ messages in thread
From: Damien Le Moal @ 2026-10-30 1:11 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe; +Cc: Josef Bacik, linux-block
On 2026/10/29 22:03, Christoph Hellwig wrote:
> I/O to backing files requires support for iter based read/write, so check
> for that upfront instead of dereferencing a NULL pointer later.
>
> Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
> Reported-by: Josef Bacik <josef@toxicpanda.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-10-30 1:11 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-29 15:03 zloop fixes Christoph Hellwig
2026-10-29 15:03 ` [PATCH 1/4] zloop: remove a duplicate call to zloop_get_block_size Christoph Hellwig
2026-10-30 1:11 ` Damien Le Moal
2026-10-29 15:03 ` [PATCH 2/4] zloop: share more code for opening a zone backing file Christoph Hellwig
2026-10-30 1:10 ` Damien Le Moal
2026-10-29 15:03 ` [PATCH 3/4] zloop: fput file after failed zone init Christoph Hellwig
2026-10-30 1:11 ` Damien Le Moal
2026-10-29 15:03 ` [PATCH 4/4] zloop: check that the zone backing file support ->{read,write}_iter Christoph Hellwig
2026-10-30 1:11 ` Damien Le Moal
2026-10-29 15:34 ` zloop fixes Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox