From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Juraj Marcin <jmarcin@redhat.com>,
Alexander Mikhalitsyn <alexander@mihalicyn.com>,
Fabiano Rosas <farosas@suse.de>, Peter Xu <peterx@redhat.com>,
Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
Subject: [PATCH 06/11] vmstate: Introduce vmstate_save_field_with_vmdesc()
Date: Wed, 1 Apr 2026 16:28:39 -0400 [thread overview]
Message-ID: <20260401202844.673494-7-peterx@redhat.com> (raw)
In-Reply-To: <20260401202844.673494-1-peterx@redhat.com>
Introduce a helper to do both the JSON blob generations and save vmstate.
This further shrinks the function a bit. More importantly, we'll need to
save two fields in one loop very soon in the future with the JSON blob.
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/vmstate.c | 45 ++++++++++++++++++++++++++++++++-------------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/migration/vmstate.c b/migration/vmstate.c
index 05badef42f..b274204e66 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -514,6 +514,35 @@ static bool vmstate_save_field(QEMUFile *f, void *pv, size_t size,
return true;
}
+/*
+ * Save a whole VMSD field, including its JSON blob separately when @vmdesc
+ * is specified.
+ */
+static inline bool
+vmstate_save_field_with_vmdesc(QEMUFile *f, void *pv, size_t size,
+ const VMStateDescription *vmsd,
+ const VMStateField *field, JSONWriter *vmdesc,
+ int i, int max, Error **errp)
+{
+ uint64_t old_offset, written_bytes;
+ bool ok;
+
+ vmsd_desc_field_start(vmsd, vmdesc, field, i, max);
+
+ old_offset = qemu_file_transferred(f);
+ ok = vmstate_save_field(f, pv, size, field, vmdesc, errp);
+ written_bytes = qemu_file_transferred(f) - old_offset;
+
+ vmsd_desc_field_end(vmsd, vmdesc, field, written_bytes);
+
+ if (!ok) {
+ error_prepend(errp, "Save of field %s/%s failed: ",
+ vmsd->name, field->name);
+ }
+
+ return ok;
+}
+
static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque, JSONWriter *vmdesc,
int version_id, Error **errp)
@@ -542,7 +571,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
void *first_elem = opaque + field->offset;
int i, n_elems = vmstate_n_elems(opaque, field);
int size = vmstate_size(opaque, field);
- uint64_t old_offset, written_bytes;
JSONWriter *vmdesc_loop = vmdesc;
bool is_prev_null = false;
@@ -559,7 +587,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
/* maximum number of elements to compress in the JSON blob */
int max_elems = vmsd_can_compress(field) ? (n_elems - i) : 1;
- old_offset = qemu_file_transferred(f);
if (field->flags & VMS_ARRAY_OF_POINTER) {
assert(curr_elem);
curr_elem = *(void **)curr_elem;
@@ -606,15 +633,9 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
}
}
- vmsd_desc_field_start(vmsd, vmdesc_loop, inner_field,
- i, max_elems);
-
- ok = vmstate_save_field(f, curr_elem, size, inner_field,
- vmdesc_loop, errp);
-
- written_bytes = qemu_file_transferred(f) - old_offset;
- vmsd_desc_field_end(vmsd, vmdesc_loop, inner_field,
- written_bytes);
+ ok = vmstate_save_field_with_vmdesc(f, curr_elem, size, vmsd,
+ inner_field, vmdesc_loop,
+ i, max_elems, errp);
/* If we used a fake temp field.. free it now */
if (is_null) {
@@ -622,8 +643,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
}
if (!ok) {
- error_prepend(errp, "Save of field %s/%s failed: ",
- vmsd->name, field->name);
goto out;
}
--
2.50.1
next prev parent reply other threads:[~2026-04-01 20:30 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 20:28 [PATCH 00/11] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Peter Xu
2026-04-01 20:28 ` [PATCH 01/11] vmstate: Pass in struct itself for VMSTATE_ARRAY_OF_POINTER Peter Xu
2026-04-20 19:25 ` Fabiano Rosas
2026-04-20 19:50 ` Peter Xu
2026-04-01 20:28 ` [PATCH 02/11] vmstate: Pass in struct itself for VMSTATE_VARRAY_OF_POINTER_UINT32 Peter Xu
2026-04-01 20:28 ` [PATCH 03/11] vmstate: Do not set size for VMS_ARRAY_OF_POINTER Peter Xu
2026-04-01 20:28 ` [PATCH 04/11] vmstate: Update max_elems early and check field compressable once Peter Xu
2026-04-01 20:28 ` [PATCH 05/11] vmstate: Rename VMS_NULLPTR_MARKER to VMS_MARKER_PTR_NULL Peter Xu
2026-04-01 20:28 ` Peter Xu [this message]
2026-04-01 20:28 ` [PATCH 07/11] vmstate: Allow vmstate_info_nullptr to emit non-NULL markers Peter Xu
2026-04-01 20:28 ` [PATCH 08/11] vmstate: Implement load of ptr marker in vmstate core Peter Xu
2026-04-01 20:28 ` [PATCH 09/11] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Peter Xu
2026-04-01 20:28 ` [PATCH 10/11] vmstate: Stop checking size for nullptr compression Peter Xu
2026-04-01 20:28 ` [PATCH 11/11] tests/unit/test-vmstate: add tests for VMS_ARRAY_OF_POINTER_AUTO_ALLOC Peter Xu
2026-04-08 17:41 ` [PATCH 00/11] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Juraj Marcin
2026-04-14 9:31 ` Alexander Mikhalitsyn
2026-04-14 15:23 ` Fabiano Rosas
2026-04-14 15:28 ` Alexander Mikhalitsyn
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=20260401202844.673494-7-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=aleksandr.mikhalitsyn@futurfusion.io \
--cc=alexander@mihalicyn.com \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--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.