From: Niklas Cassel <cassel@kernel.org>
To: qemu-devel@nongnu.org
Cc: Niklas Cassel <cassel@kernel.org>,
dlemoal@kernel.org, Stefan Hajnoczi <stefanha@redhat.com>,
Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Hanna Reitz <hreitz@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Eric Blake <eblake@redhat.com>,
qemu-block@nongnu.org, Sam Li <faithilikerun@gmail.com>
Subject: [PATCH v15 7/7] virtio-blk: report zone errors with their zone status codes
Date: Mon, 26 Oct 2026 13:12:55 +0100 [thread overview]
Message-ID: <20261026121259.3354561-8-cassel@kernel.org> (raw)
In-Reply-To: <20261026121259.3354561-1-cassel@kernel.org>
virtio-blk completes a failed write with VIRTIO_BLK_S_IOERR, and a
failed zone append or zone management request with
VIRTIO_BLK_S_ZONE_INVALID_CMD. It never reports the zone status codes
that virtio 1.4 (5.2.6.2) requires for a write off the write pointer
or for a request that exceeds a zone resource limit.
When VIRTIO_BLK_F_ZONED is negotiated, map the zone errors of the block
layer to them:
BLK_ZE_UNALIGNED_WRITE VIRTIO_BLK_S_ZONE_UNALIGNED_WP
BLK_ZE_BOUNDARY VIRTIO_BLK_S_ZONE_INVALID_CMD
BLK_ZE_OPEN_RESOURCE VIRTIO_BLK_S_ZONE_OPEN_RESOURCE
BLK_ZE_ACTIVE_RESOURCE VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE
Other errors keep their status code. A FINISH that exceeds a zone
resource limit also gets a zone resource status code, which 5.2.6
defines for any zone operation. Zone errors of writes are reported
regardless of the rerror/werror policy, as they are the deterministic
result of the request.
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
hw/block/virtio-blk.c | 48 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 44 insertions(+), 4 deletions(-)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 536d71a91a..1d35997f7e 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -68,11 +68,44 @@ void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
virtio_notify(vdev, req->vq);
}
+/*
+ * Map a zone error (see include/block/block-common.h) to its virtio-blk
+ * status, or return VIRTIO_BLK_S_OK if @error is not one.
+ */
+static uint8_t virtio_blk_zone_status(VirtIOBlock *s, int error)
+{
+ if (!virtio_vdev_has_feature(VIRTIO_DEVICE(s), VIRTIO_BLK_F_ZONED)) {
+ return VIRTIO_BLK_S_OK;
+ }
+
+ switch (error) {
+ case BLK_ZE_UNALIGNED_WRITE:
+ return VIRTIO_BLK_S_ZONE_UNALIGNED_WP;
+ case BLK_ZE_BOUNDARY:
+ return VIRTIO_BLK_S_ZONE_INVALID_CMD;
+ case BLK_ZE_OPEN_RESOURCE:
+ return VIRTIO_BLK_S_ZONE_OPEN_RESOURCE;
+ case BLK_ZE_ACTIVE_RESOURCE:
+ return VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE;
+ default:
+ return VIRTIO_BLK_S_OK;
+ }
+}
+
static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
bool is_read)
{
VirtIOBlock *s = req->dev;
- BlockErrorAction action = blk_get_error_action(s->blk, is_read, error);
+ uint8_t zone_status = virtio_blk_zone_status(s, error);
+ /*
+ * Zone errors are the deterministic result of the request, so they are
+ * reported whatever the rerror/werror policy: stopping the VM would only
+ * make the request fail the same way again when it is retried on resume,
+ * and ignoring the error would hide the failure from the guest.
+ */
+ BlockErrorAction action = zone_status != VIRTIO_BLK_S_OK ?
+ BLOCK_ERROR_ACTION_REPORT :
+ blk_get_error_action(s->blk, is_read, error);
if (action == BLOCK_ERROR_ACTION_STOP) {
/* Break the link as the next request is going to be parsed from the
@@ -84,7 +117,8 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
s->rq = req;
}
} else if (action == BLOCK_ERROR_ACTION_REPORT) {
- virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
+ virtio_blk_req_complete(req, zone_status != VIRTIO_BLK_S_OK ?
+ zone_status : VIRTIO_BLK_S_IOERR);
block_acct_failed(blk_get_stats(s->blk), &req->acct);
g_free(req);
}
@@ -767,7 +801,10 @@ static void virtio_blk_zone_mgmt_complete(void *opaque, int ret)
trace_virtio_blk_zone_mgmt_complete(vdev, req,ret);
if (ret) {
- err_status = VIRTIO_BLK_S_ZONE_INVALID_CMD;
+ err_status = virtio_blk_zone_status(s, -ret);
+ if (err_status == VIRTIO_BLK_S_OK) {
+ err_status = VIRTIO_BLK_S_ZONE_INVALID_CMD;
+ }
}
virtio_blk_req_complete(req, err_status);
@@ -827,7 +864,10 @@ static void virtio_blk_zone_append_complete(void *opaque, int ret)
uint8_t err_status = VIRTIO_BLK_S_OK;
if (ret) {
- err_status = VIRTIO_BLK_S_ZONE_INVALID_CMD;
+ err_status = virtio_blk_zone_status(s, -ret);
+ if (err_status == VIRTIO_BLK_S_OK) {
+ err_status = VIRTIO_BLK_S_ZONE_INVALID_CMD;
+ }
goto out;
}
--
2.56.0
prev parent reply other threads:[~2026-10-26 12:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 12:12 [PATCH v15 0/7] Add full zoned storage emulation to the qcow2 driver Niklas Cassel
2026-10-26 12:12 ` [PATCH v15 1/7] docs/qcow2: add the zoned format feature Niklas Cassel
2026-10-26 12:12 ` [PATCH v15 2/7] qcow2: add configurations for zoned format extension Niklas Cassel
2026-10-26 12:12 ` [PATCH v15 3/7] block: define errnos for zone protocol errors Niklas Cassel
2026-10-26 12:12 ` [PATCH v15 4/7] qcow2: add zoned emulation capability Niklas Cassel
2026-10-26 12:12 ` [PATCH v15 5/7] iotests: test the zoned format feature for qcow2 file Niklas Cassel
2026-10-26 12:12 ` [PATCH v15 6/7] qcow2: validate the write pointer table when opening an image Niklas Cassel
2026-10-26 12:12 ` Niklas Cassel [this message]
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=20261026121259.3354561-8-cassel@kernel.org \
--to=cassel@kernel.org \
--cc=armbru@redhat.com \
--cc=dlemoal@kernel.org \
--cc=eblake@redhat.com \
--cc=faithilikerun@gmail.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.