From: Sanne Raymaekers <sraymaek@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, fam@euphon.net, kwolf@redhat.com,
hreitz@redhat.com, Sanne Raymaekers <sraymaek@redhat.com>
Subject: [PATCH v3 3/3] block/vmdk: add eos marker for stream optimized disks
Date: Fri, 16 Oct 2026 14:37:50 +0200 [thread overview]
Message-ID: <20261016123750.94769-4-sraymaek@redhat.com> (raw)
In-Reply-To: <20261016123750.94769-1-sraymaek@redhat.com>
The end of stream marker should be at the very end of a stream optimized
disk. It consists of a regular marker struct with `val`, `size` and
`type` set to 0. It is then padded with more 0s to fill out a
sector. This effectively results in 512 zero bytes.[^1]
[^1] Virtual Disk Format 5.0 Technical Note.
Signed-off-by: Sanne Raymaekers <sraymaek@redhat.com>
---
block/vmdk.c | 48 ++++++++++++++++++++++++++++--------------------
1 file changed, 28 insertions(+), 20 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index e090e122f1..b1848130a0 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -195,6 +195,13 @@ typedef struct VmdkGrainMarker {
uint8_t data[];
} QEMU_PACKED VmdkGrainMarker;
+typedef struct EosMarker {
+ uint64_t val;
+ uint32_t size;
+ uint32_t type;
+ uint8_t pad[512 - 16];
+} QEMU_PACKED EosMarker;
+
enum {
MARKER_END_OF_STREAM = 0,
MARKER_GRAIN_TABLE = 1,
@@ -987,12 +994,7 @@ vmdk_open_vmdk4(BlockDriverState *bs, BdrvChild *file, int flags,
VMDK4Header header;
uint8_t pad[512 - 4 - sizeof(VMDK4Header)];
- struct {
- uint64_t val;
- uint32_t size;
- uint32_t type;
- uint8_t pad[512 - 16];
- } QEMU_PACKED eos_marker;
+ EosMarker eos_marker;
} QEMU_PACKED footer;
ret = bdrv_pread(file, bs->file->bs->total_sectors * 512 - 1536,
@@ -2182,23 +2184,29 @@ vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,
QEMUIOVector *qiov)
{
if (bytes == 0) {
- /* The caller will write bytes 0 to signal EOF.
- * When receive it, we align EOF to a sector boundary. */
+ /* The caller will write bytes 0 to signal EOF. */
BDRVVmdkState *s = bs->opaque;
- int i, ret;
+ int ret;
int64_t length;
+ QEMU_AUTO_VFREE EosMarker *eos_marker = NULL;
- for (i = 0; i < s->num_extents; i++) {
- length = bdrv_co_getlength(s->extents[i].file->bs);
- if (length < 0) {
- return length;
- }
- length = QEMU_ALIGN_UP(length, BDRV_SECTOR_SIZE);
- ret = bdrv_co_truncate(s->extents[i].file, length, false,
- PREALLOC_MODE_OFF, 0, NULL);
- if (ret < 0) {
- return ret;
- }
+ /* Stream optimized disks should only contain a single extent. */
+ assert(s->num_extents == 1);
+
+ /*
+ * Stream optimized disks end with an EOS marker,
+ * consisting of 512 null bytes.
+ */
+ eos_marker = qemu_blockalign0(bs, sizeof(EosMarker));
+ length = bdrv_co_getlength(s->extents[0].file->bs);
+ if (length < 0) {
+ return length;
+ }
+ length = QEMU_ALIGN_UP(length, BDRV_SECTOR_SIZE);
+ ret = bdrv_co_pwrite(s->extents[0].file, length, sizeof(EosMarker),
+ eos_marker, 0);
+ if (ret < 0) {
+ return ret;
}
return 0;
}
--
2.55.0
prev parent reply other threads:[~2026-10-16 12:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 12:37 [PATCH v3 0/3] block/vmdk: fixes for stream optimized disks Sanne Raymaekers
2026-10-16 12:37 ` [PATCH v3 1/3] block/vmdk: align stream optimized data grains on 512 byte chunks Sanne Raymaekers
2026-10-16 12:37 ` [PATCH v3 2/3] block/vmdk: skip RGD for stream optimized disks Sanne Raymaekers
2026-10-16 12:37 ` Sanne Raymaekers [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=20261016123750.94769-4-sraymaek@redhat.com \
--to=sraymaek@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.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.