From: Niklas Cassel <cassel@kernel.org>
To: qemu-devel@nongnu.org
Cc: Damien Le Moal <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>,
Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>,
Jeuk Kim <jeuk20.kim@samsung.com>,
Daejun Park <daejun7.park@samsung.com>,
Niklas Cassel <cassel@kernel.org>
Subject: [PATCH v17 3/9] block: define errnos for zone protocol errors
Date: Thu, 12 Nov 2026 12:49:12 +0100 [thread overview]
Message-ID: <20261112114918.1269168-4-cassel@kernel.org> (raw)
In-Reply-To: <20261112114918.1269168-1-cassel@kernel.org>
A block driver that emulates zones (e.g. qcow2 with the zoned format
feature) rejects requests that violate the zone protocol, and the device
model has to report each of these to the guest with the matching zone
error (ZAC/ZBC sense data, virtio-blk zone status codes, ...). It can
only do so if each condition comes with an errno of its own, rather than
a generic one such as EIO.
Define one for each condition:
BLK_ZE_UNALIGNED_WRITE ESPIPE write not at the write pointer
BLK_ZE_BOUNDARY ERANGE write past the zone capacity
BLK_ZE_OPEN_RESOURCE ETOOMANYREFS open zone limit reached
BLK_ZE_ACTIVE_RESOURCE EOVERFLOW active zone limit reached
BLK_ZE_FULL EXFULL write to a full zone
ETOOMANYREFS and EOVERFLOW are what Linux returns for
BLK_STS_ZONE_OPEN_RESOURCE and BLK_STS_ZONE_ACTIVE_RESOURCE, so a host
zoned device used through file-posix already reports the same values.
For the boundary case, ERANGE is used rather than EFBIG, which the host
file system can legitimately return for an image file.
A write that is not at the write pointer gets ESPIPE, which file and
block device I/O never return, rather than EINVAL, which a zoned driver
also uses for invalid requests such as an invalid zone state
transition. So a device model can map each of these errnos to its zone
error without having to know which request failed.
A full zone has no write pointer, and ZAC, ZBC, NVMe ZNS and virtio-blk
all report a write to a full zone differently from a write that is not
at the write pointer, so it gets its own errno, EXFULL.
ETOOMANYREFS is not POSIX and EXFULL is Linux-specific, so provide
fallbacks for hosts that lack them.
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
include/block/block-common.h | 17 +++++++++++++++++
include/qemu/osdep.h | 6 ++++++
2 files changed, 23 insertions(+)
diff --git a/include/block/block-common.h b/include/block/block-common.h
index 1667fe5b62..b62675619e 100644
--- a/include/block/block-common.h
+++ b/include/block/block-common.h
@@ -125,6 +125,23 @@ typedef struct BlockZoneDescriptor {
BlockZoneState state;
} BlockZoneDescriptor;
+/*
+ * Errors that zoned block drivers report for zone protocol violations, as
+ * positive errno values (drivers return them negated). Each condition has an
+ * errno of its own that zoned block drivers do not return for anything else,
+ * so that device models can report the matching zone error to the guest
+ * whichever request failed. In particular, EINVAL is not used, as it also
+ * reports invalid requests, such as an invalid zone state transition. The
+ * zone resource errors are the errnos Linux uses for BLK_STS_ZONE_OPEN_RESOURCE
+ * and BLK_STS_ZONE_ACTIVE_RESOURCE, so a host zoned device accessed through
+ * file-posix reports the same values.
+ */
+#define BLK_ZE_UNALIGNED_WRITE ESPIPE /* write not at write pointer */
+#define BLK_ZE_BOUNDARY ERANGE /* write past zone capacity */
+#define BLK_ZE_OPEN_RESOURCE ETOOMANYREFS /* open zone limit reached */
+#define BLK_ZE_ACTIVE_RESOURCE EOVERFLOW /* active zone limit reached */
+#define BLK_ZE_FULL EXFULL /* write to a full zone */
+
/*
* Track write pointers of a zone in bytes.
*/
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index b27d159d5b..254a41bf1f 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -353,6 +353,12 @@ void QEMU_ERROR("code path is reachable")
#if !defined(ESHUTDOWN)
#define ESHUTDOWN 4099
#endif
+#if !defined(ETOOMANYREFS)
+#define ETOOMANYREFS 4100
+#endif
+#if !defined(EXFULL)
+#define EXFULL 4101
+#endif
#define RETRY_ON_EINTR(expr) \
(__extension__ \
--
2.56.0
next prev parent reply other threads:[~2026-11-12 11:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 11:49 [PATCH v17 0/9] Add full zoned storage emulation to the qcow2 driver Niklas Cassel
2026-11-12 11:49 ` [PATCH v17 1/9] docs/qcow2: add the zoned format feature Niklas Cassel
2026-11-12 11:49 ` [PATCH v17 2/9] qcow2: add configurations for zoned format extension Niklas Cassel
2026-11-12 11:49 ` Niklas Cassel [this message]
2026-11-15 23:45 ` [PATCH v17 3/9] block: define errnos for zone protocol errors Damien Le Moal
2026-11-12 11:49 ` [PATCH v17 4/9] qcow2: add zoned emulation capability Niklas Cassel
2026-11-12 11:49 ` [PATCH v17 5/9] iotests: test the zoned format feature for qcow2 file Niklas Cassel
2026-11-12 11:49 ` [PATCH v17 6/9] qcow2: validate the write pointer table when opening an image Niklas Cassel
2026-11-12 11:49 ` [PATCH v17 7/9] virtio-blk: report zone errors with their zone status codes Niklas Cassel
2026-11-15 23:48 ` Damien Le Moal
2026-11-12 11:49 ` [PATCH v17 8/9] block: add accessors for the zone model, capacity and open zone limit Niklas Cassel
2026-11-15 23:48 ` Damien Le Moal
2026-11-12 11:49 ` [PATCH v17 9/9] scsi: add the sense codes of zoned block devices Niklas Cassel
2026-11-15 23:49 ` 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=20261112114918.1269168-4-cassel@kernel.org \
--to=cassel@kernel.org \
--cc=armbru@redhat.com \
--cc=daejun7.park@samsung.com \
--cc=dlemoal@kernel.org \
--cc=eblake@redhat.com \
--cc=faithilikerun@gmail.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=jeuk20.kim@samsung.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@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.