From: Stefan Hajnoczi <stefanha@redhat.com>
To: Sam Li <faithilikerun@gmail.com>
Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
Hanna Reitz <hreitz@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
cassel@kernel.org, dlemoal@kernel.org, qemu-block@nongnu.org,
dmitry.fomichev@wdc.com, Markus Armbruster <armbru@redhat.com>,
Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
Eric Blake <eblake@redhat.com>
Subject: Re: [PATCH v12 4/5] qcow2: add zoned emulation capability
Date: Mon, 29 Jun 2026 20:23:47 +0200 [thread overview]
Message-ID: <20260629182347.GB376767@fedora> (raw)
In-Reply-To: <20260623184830.373232-5-faithilikerun@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3396 bytes --]
On Tue, Jun 23, 2026 at 08:48:29PM +0200, Sam Li wrote:
> +static int coroutine_fn GRAPH_RDLOCK
> +qcow2_rw_wp_at(BlockDriverState *bs, uint64_t *wp,
> + int32_t index, bool is_write)
> +{
> + BDRVQcow2State *s = bs->opaque;
> + uint64_t wp_byte_off = sizeof(uint64_t) * index;
> + uint64_t cluster_file_off =
> + s->zoned_header.zonedmeta_offset +
> + (wp_byte_off & ~((uint64_t)s->cluster_size - 1));
> + size_t off_in_cluster = wp_byte_off & (s->cluster_size - 1);
> + void *cluster_buf;
> + uint64_t *slot;
> + int ret;
> +
> + assert(s->wp_cache != NULL);
> +
> + qemu_co_mutex_lock(&s->lock);
> + ret = qcow2_cache_get(bs, s->wp_cache, cluster_file_off, &cluster_buf);
> + if (ret < 0) {
> + qemu_co_mutex_unlock(&s->lock);
> + error_report("Failed to %s WP slot (zone %d): %s",
> + is_write ? "write" : "read", index, strerror(-ret));
> + return ret;
> + }
> +
> + slot = (uint64_t *)((char *)cluster_buf + off_in_cluster);
> + if (is_write) {
> + *slot = *wp;
Missing cpu_to_be64()?
> + qcow2_cache_entry_mark_dirty(s->wp_cache, cluster_buf);
> + } else {
> + *wp = *slot;
Missing be64_to_cpu()?
> +static inline int coroutine_fn GRAPH_RDLOCK
> +qcow2_refresh_zonedmeta(BlockDriverState *bs)
> +{
> + int ret;
> + BDRVQcow2State *s = bs->opaque;
> + uint64_t wps_size = s->zoned_header.nr_zones * sizeof(uint64_t);
> + g_autofree uint64_t *temp = NULL;
> +
> + temp = g_new(uint64_t, s->zoned_header.nr_zones);
> + ret = bdrv_pread(bs->file, s->zoned_header.zonedmeta_offset,
> + wps_size, temp, 0);
> + if (ret < 0) {
> + error_report("Cannot read metadata");
> + return ret;
> + }
> +
> + memcpy(bs->wps->wp, temp, wps_size);
Missing be64_to_cpu()?
bs->wps->wp[] is in QEMU's format while temp is in qcow2's format. The
representations are not guaranteed to remain the same. An explicit
conversion from qcow2's representation to QEMU's representation would be
best. You could also use build-time assertions (QEMU_BUILD_BUG_ON()) to
check that the qcow2 constants match the QEMU constants.
> @@ -559,8 +874,34 @@ qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
> "is wrong");
> return -EINVAL;
> }
> - if (!qcow2_check_zone_options(&zoned_ext, errp)) {
> - return -EINVAL;
> +
> + bs->wps = g_malloc(sizeof(BlockZoneWps)
> + + s->zoned_header.nr_zones * sizeof(uint64_t));
> + ret = qcow2_refresh_zonedmeta(bs);
Is bs->wps freed when qcow2_refresh_zonedmeta() fails?
> @@ -4161,6 +4879,45 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
> ret = -EINVAL;
> goto unlock;
> }
> +
> + uint32_t nrz = s->zoned_header.nr_zones;
> + zoned_meta_size = sizeof(uint64_t) * nrz;
> + g_autofree uint64_t *meta = NULL;
> + meta = g_new0(uint64_t, nrz);
> +
> + for (i = 0; i < s->zoned_header.conventional_zones; ++i) {
> + meta[i] = i * s->zoned_header.zone_size;
> + meta[i] |= 1ULL << 59;
> + }
> +
> + for (; i < nrz; ++i) {
> + meta[i] = i * s->zoned_header.zone_size;
> + }
Missing cpu_to_be64()?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-06-29 18:24 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 18:48 [PATCH v12 0/5] Add full zoned storage emulation to the qcow2 driver Sam Li
2026-06-23 18:48 ` [PATCH v12 1/5] docs/qcow2: add the zoned format feature Sam Li
2026-06-23 18:48 ` [PATCH v12 2/5] qcow2: add configurations for zoned format extension Sam Li
2026-06-26 12:26 ` Niklas Cassel
2026-06-23 18:48 ` [PATCH v12 3/5] virtio-blk: do not merge writes across a zone boundary Sam Li
2026-06-24 19:21 ` Stefan Hajnoczi
2026-06-26 11:44 ` Niklas Cassel
2026-06-26 11:50 ` Sam Li
2026-06-23 18:48 ` [PATCH v12 4/5] qcow2: add zoned emulation capability Sam Li
2026-06-29 17:40 ` Stefan Hajnoczi
2026-06-29 18:20 ` Sam Li
2026-06-29 18:23 ` Stefan Hajnoczi [this message]
2026-06-23 18:48 ` [PATCH v12 5/5] iotests: test the zoned format feature for qcow2 file Sam Li
2026-06-26 11:33 ` [PATCH v12 0/5] Add full zoned storage emulation to the qcow2 driver Niklas Cassel
2026-06-26 11:41 ` Sam Li
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=20260629182347.GB376767@fedora \
--to=stefanha@redhat.com \
--cc=armbru@redhat.com \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=dmitry.fomichev@wdc.com \
--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 \
/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.