From: Damien Le Moal <dlemoal@kernel.org>
To: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
linux-scsi@vger.kernel.org,
"Martin K . Petersen" <martin.petersen@oracle.com>
Subject: [PATCH v10 06/13] zloop: fix ordered zone append handling
Date: Mon, 16 Nov 2026 08:33:20 +0900 [thread overview]
Message-ID: <20261115233327.941586-7-dlemoal@kernel.org> (raw)
In-Reply-To: <20261115233327.941586-1-dlemoal@kernel.org>
For oredered zone append commands, the function
zloop_set_zone_append_sector() increments a zone write pointer without
checking if the zone is already open (implicitly or explicitly). This
check is done only when the command is later executed using a work item,
and the zone is only then implicitly open if needed. This creates a short
time window where a report zone can show an empty zone with a write
pointer that is not equal to the zone start sector, which is incorrect.
Calling zloop_do_open_zone() in zloop_set_zone_append_sector() is required
but introduces locking complexity as the zone mutex cannot be taken in the
context of zloop_queue_rq(). Instead introduce the ordered workqueue
append_workqueue to handle zone append commands when ordered zone append
is enabled. This ensure that all zone append operations are executed in
the order of there submission. This removes the need for setting the
command sector in the context of zloop_queue_rq() and we can rely on the
reguar command execution done by zloop_rw(). With this change,
zloop_seq_write_prep() is simplified and zloop_set_zone_append_sector() is
removed entirely.
This change does reduce the command execution concurrency and impact
performance with ordered zone append enabled for file systems using zone
append. This is however not a critical option and the default unordered
zone append handling is unaffected.
Fixes: fcc6eaa3a03a ("zloop: introduce the ordered_zone_append configuration parameter")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
drivers/block/zloop.c | 115 +++++++++++++++++-------------------------
1 file changed, 47 insertions(+), 68 deletions(-)
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 96666742523b..0cf67acf8096 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -129,6 +129,7 @@ struct zloop_device {
struct gendisk *disk;
struct workqueue_struct *workqueue;
+ struct workqueue_struct *append_workqueue;
bool buffered_io;
bool zone_append;
bool ordered_zone_append;
@@ -590,32 +591,24 @@ static int zloop_seq_write_prep(struct zloop_cmd *cmd)
* when submitted.
*/
if (is_append) {
- /*
- * If ordered zone append is in use, we already checked and set
- * the target sector in zloop_queue_rq().
- */
- if (!zlo->ordered_zone_append) {
- if (zone->cond == BLK_ZONE_COND_FULL ||
- zone->wp + nr_sectors > zone_end) {
- ret = -EIO;
- goto out_unlock;
- }
- cmd->sector = zone->wp;
- }
- } else {
- if (cmd->sector != zone->wp) {
- if (zone->wp == ULLONG_MAX)
- pr_err("%pg: Zone %u: write to %s zone: sect %llu\n",
- zlo->disk->part0, zone_no,
- blk_zone_cond_str(zone->cond),
- cmd->sector);
- else
- pr_err("%pg: Zone %u: unaligned write: sect %llu, wp %llu\n",
- zlo->disk->part0, zone_no, cmd->sector,
- zone->wp);
+ if (zone->cond == BLK_ZONE_COND_FULL ||
+ zone->wp + nr_sectors > zone_end) {
ret = -EIO;
goto out_unlock;
}
+ cmd->sector = zone->wp;
+ } else if (cmd->sector != zone->wp) {
+ if (zone->wp == ULLONG_MAX)
+ pr_err("%pg: Zone %u: write to %s zone: sect %llu\n",
+ zlo->disk->part0, zone_no,
+ blk_zone_cond_str(zone->cond),
+ cmd->sector);
+ else
+ pr_err("%pg: Zone %u: unaligned write: sect %llu, wp %llu\n",
+ zlo->disk->part0, zone_no, cmd->sector,
+ zone->wp);
+ ret = -EIO;
+ goto out_unlock;
}
/* Implicitly open the target zone. */
@@ -625,15 +618,13 @@ static int zloop_seq_write_prep(struct zloop_cmd *cmd)
}
/*
- * Advance the write pointer, unless ordered zone append is in use. If
- * the write fails, the write pointer position will be corrected when
- * the next I/O starts execution.
+ * Advance the write pointer. If the write fails, the write pointer
+ * position will be corrected when the next I/O starts execution.
*/
- if (!is_append || !zlo->ordered_zone_append) {
- zone->wp += nr_sectors;
- if (zone->wp == zone_end)
- zloop_mark_full(zlo, zone);
- }
+ zone->wp += nr_sectors;
+ if (zone->wp == zone_end)
+ zloop_mark_full(zlo, zone);
+
out_unlock:
spin_unlock(&zone->wp_lock);
return ret;
@@ -885,58 +876,27 @@ static void zloop_complete_rq(struct request *rq)
blk_mq_end_request(rq, sts);
}
-static bool zloop_set_zone_append_sector(struct request *rq)
-{
- struct zloop_device *zlo = rq->q->queuedata;
- unsigned int zone_no = rq_zone_no(rq);
- struct zloop_zone *zone = &zlo->zones[zone_no];
- sector_t zone_end = zone->start + zlo->zone_capacity;
- sector_t nr_sectors = blk_rq_sectors(rq);
-
- spin_lock(&zone->wp_lock);
-
- if (zone->cond == BLK_ZONE_COND_FULL ||
- zone->wp + nr_sectors > zone_end) {
- spin_unlock(&zone->wp_lock);
- return false;
- }
-
- rq->__sector = zone->wp;
- zone->wp += blk_rq_sectors(rq);
- if (zone->wp >= zone_end)
- zloop_mark_full(zlo, zone);
-
- spin_unlock(&zone->wp_lock);
-
- return true;
-}
-
static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct request *rq = bd->rq;
struct zloop_cmd *cmd = blk_mq_rq_to_pdu(rq);
struct zloop_device *zlo = rq->q->queuedata;
+ struct workqueue_struct *wq;
if (data_race(READ_ONCE(zlo->state)) == Zlo_deleting) {
rq->rq_flags |= RQF_QUIET;
return BLK_STS_IOERR;
}
- /*
- * If we need to strongly order zone append operations, set the request
- * sector to the zone write pointer location now instead of when the
- * command work runs.
- */
- if (zlo->ordered_zone_append && req_op(rq) == REQ_OP_ZONE_APPEND) {
- if (!zloop_set_zone_append_sector(rq))
- return BLK_STS_IOERR;
- }
-
blk_mq_start_request(rq);
INIT_WORK(&cmd->work, zloop_cmd_workfn);
- queue_work(zlo->workqueue, &cmd->work);
+ if (zlo->ordered_zone_append && req_op(rq) == REQ_OP_ZONE_APPEND)
+ wq = zlo->append_workqueue;
+ else
+ wq = zlo->workqueue;
+ queue_work(wq, &cmd->work);
return BLK_STS_OK;
}
@@ -1029,6 +989,8 @@ static void zloop_free_disk(struct gendisk *disk)
fput(zlo->data_dir);
destroy_workqueue(zlo->workqueue);
+ if (zlo->append_workqueue)
+ destroy_workqueue(zlo->append_workqueue);
kfree(zlo->base_dir);
kvfree(zlo);
}
@@ -1285,6 +1247,21 @@ static int zloop_ctl_add(struct zloop_options *opts)
goto out_free_idr;
}
+ /*
+ * Use an ordered workqueue for strongly ordered zone append operations
+ * so that we can keep processing the operations in the same order as
+ * they are submitted.
+ */
+ if (zlo->ordered_zone_append) {
+ zlo->append_workqueue =
+ alloc_ordered_workqueue("zloop%d_append", WQ_FREEZABLE,
+ zlo->id);
+ if (!zlo->append_workqueue) {
+ ret = -ENOMEM;
+ goto out_destroy_workqueue;
+ }
+ }
+
if (opts->base_dir)
zlo->base_dir = kstrdup(opts->base_dir, GFP_KERNEL);
else
@@ -1391,6 +1368,8 @@ static int zloop_ctl_add(struct zloop_options *opts)
kfree(zlo->base_dir);
out_destroy_workqueue:
destroy_workqueue(zlo->workqueue);
+ if (zlo->append_workqueue)
+ destroy_workqueue(zlo->append_workqueue);
out_free_idr:
mutex_lock(&zloop_ctl_mutex);
idr_remove(&zloop_index_idr, zlo->id);
--
2.56.0
next prev parent reply other threads:[~2026-11-15 23:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 23:33 [PATCH v10 00/13] Add support for storage element depopulation Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 01/13] block: introduce disk_zone_is_offline() Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 02/13] block: refactor blk_revalidate_disk_zones() Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 03/13] block: allow dropping all zone write plugs on revalidation Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 04/13] block: introduce storage element management Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 05/13] block: add storage element management ioctls Damien Le Moal
2026-11-15 23:33 ` Damien Le Moal [this message]
2026-11-15 23:33 ` [PATCH v10 07/13] zloop: fix zone reporting consistency Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 08/13] zloop: add storage element emulation Damien Le Moal
2026-11-15 23:58 ` sashiko-bot
2026-11-15 23:33 ` [PATCH v10 09/13] zloop: add degrade_element control command Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 10/13] scsi: scsi_proto: refine the definition of storage element health Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 11/13] scsi: sd_zbc: always revalidate zones for disks supporting head depopulation Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 12/13] scsi: sd_zbc: define storage element management operations Damien Le Moal
2026-11-16 0:04 ` sashiko-bot
2026-11-15 23:33 ` [PATCH v10 13/13] scsi: sd: fail read commands to offline zones early Damien Le Moal
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=20261115233327.941586-7-dlemoal@kernel.org \
--to=dlemoal@kernel.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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