From: Peter Xu <peterx@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: farosas@suse.de, "open list:All patches CC here" <qemu-devel@nongnu.org>
Subject: Re: [PATCH v2 07/16] migration: factor out vmstate_save_field() from vmstate_save_state()
Date: Tue, 3 Mar 2026 10:38:45 -0500 [thread overview]
Message-ID: <aacAhTY55cp4QgQu@x1.local> (raw)
In-Reply-To: <20260220210214.800050-8-vsementsov@yandex-team.ru>
On Sat, Feb 21, 2026 at 12:02:05AM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Simplify vmstate_save_state() which is rather big, and simplify further
> refactoring.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
I wonder how hard it is to have this helper also cover the rest in the loop
over elements, on e.g. VMS_ARRAY_OF_POINTER, vmdesc_loop being able to
change, and all the nullptr handling.
I had a feeling that you intentionally skipped those because it'll not be
as trivial - I think it's fine, but IIUC we can always figure a way out.
Can be done later. Agree this is an improvement already,
Reviewed-by: Peter Xu <peterx@redhat.com>
> ---
> migration/vmstate.c | 40 +++++++++++++++++++++++++---------------
> 1 file changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index 810b131f18..d8c30830d6 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -26,6 +26,9 @@ static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd,
> Error **errp);
> static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd,
> void *opaque, Error **errp);
> +static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
> + void *opaque, JSONWriter *vmdesc,
> + int version_id, Error **errp);
>
> /* Whether this field should exist for either save or load the VM? */
> static bool
> @@ -450,6 +453,26 @@ static bool vmstate_pre_save(const VMStateDescription *vmsd, void *opaque,
> return true;
> }
>
> +static bool vmstate_save_field(QEMUFile *f, void *pv, size_t size,
> + const VMStateField *field,
> + JSONWriter *vmdesc, Error **errp)
> +{
> + if (field->flags & VMS_STRUCT) {
> + return vmstate_save_state(f, field->vmsd, pv, vmdesc, errp) >= 0;
> + } else if (field->flags & VMS_VSTRUCT) {
> + return vmstate_save_state_v(f, field->vmsd, pv, vmdesc,
> + field->struct_version_id,
> + errp) >= 0;
> + }
> +
> + if (field->info->put(f, pv, size, field, vmdesc) < 0) {
> + error_setg(errp, "put failed");
> + return false;
> + }
> +
> + return true;
> +}
> +
> static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
> void *opaque, JSONWriter *vmdesc,
> int version_id, Error **errp)
> @@ -542,21 +565,8 @@ static int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
> vmsd_desc_field_start(vmsd, vmdesc_loop, inner_field,
> i, max_elems);
>
> - if (inner_field->flags & VMS_STRUCT) {
> - ret = vmstate_save_state(f, inner_field->vmsd,
> - curr_elem, vmdesc_loop, errp);
> - } else if (inner_field->flags & VMS_VSTRUCT) {
> - ret = vmstate_save_state_v(f, inner_field->vmsd,
> - curr_elem, vmdesc_loop,
> - inner_field->struct_version_id,
> - errp);
> - } else {
> - ret = inner_field->info->put(f, curr_elem, size,
> - inner_field, vmdesc_loop);
> - if (ret < 0) {
> - error_setg(errp, "put failed");
> - }
> - }
> + ret = vmstate_save_field(f, curr_elem, size, inner_field,
> + vmdesc_loop, errp) ? 0 : -EINVAL;
>
> written_bytes = qemu_file_transferred(f) - old_offset;
> vmsd_desc_field_end(vmsd, vmdesc_loop, inner_field,
> --
> 2.52.0
>
--
Peter Xu
next prev parent reply other threads:[~2026-03-03 15:39 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260220210214.800050-1-vsementsov@yandex-team.ru>
2026-02-20 21:01 ` [PATCH v2 01/16] migration: vmstate_save_state_v: fix double error_setg Vladimir Sementsov-Ogievskiy
2026-02-27 22:14 ` Fabiano Rosas
2026-03-03 14:30 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 02/16] migration: make vmstate_save_state_v() static Vladimir Sementsov-Ogievskiy
2026-02-27 22:15 ` Fabiano Rosas
2026-03-03 15:01 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 03/16] migration: make .post_save() a void function Vladimir Sementsov-Ogievskiy
2026-02-27 22:41 ` Fabiano Rosas
2026-02-27 23:56 ` Vladimir Sementsov-Ogievskiy
2026-03-03 15:05 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 04/16] migration: vmstate_load_state(): add some newlines Vladimir Sementsov-Ogievskiy
2026-02-27 22:41 ` Fabiano Rosas
2026-03-03 15:06 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 05/16] migration: vmstate_save/load_state(): stop tracing errors Vladimir Sementsov-Ogievskiy
2026-02-27 22:44 ` Fabiano Rosas
2026-03-03 15:13 ` Peter Xu
2026-03-04 16:10 ` Vladimir Sementsov-Ogievskiy
2026-02-20 21:02 ` [PATCH v2 06/16] migration: factor out vmstate_pre_save() from vmstate_save_state() Vladimir Sementsov-Ogievskiy
2026-03-03 15:22 ` Peter Xu
2026-03-04 16:27 ` Vladimir Sementsov-Ogievskiy
2026-03-04 16:42 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 07/16] migration: factor out vmstate_save_field() " Vladimir Sementsov-Ogievskiy
2026-03-03 15:38 ` Peter Xu [this message]
2026-03-04 17:22 ` Vladimir Sementsov-Ogievskiy
2026-02-20 21:02 ` [PATCH v2 08/16] migration: factor out vmstate_pre_load() from vmstate_load_state() Vladimir Sementsov-Ogievskiy
2026-03-03 16:11 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 09/16] migration: factor out vmstate_load_field() " Vladimir Sementsov-Ogievskiy
2026-03-03 16:14 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 10/16] migration: factor out vmstate_post_load() " Vladimir Sementsov-Ogievskiy
2026-03-03 16:16 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 11/16] migration: convert vmstate_subsection_save/load functions to bool Vladimir Sementsov-Ogievskiy
2026-03-03 16:17 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 12/16] migration: VMStateInfo: introduce new handlers with errp Vladimir Sementsov-Ogievskiy
2026-03-03 16:19 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 13/16] migration: introduce vmstate_load_vmsd() and vmstate_save_vmsd() Vladimir Sementsov-Ogievskiy
2026-03-03 16:22 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 14/16] migration/cpr: move to new migration APIs Vladimir Sementsov-Ogievskiy
2026-03-03 16:23 ` Peter Xu
2026-02-20 21:02 ` [PATCH v2 15/16] migration/savevm: " Vladimir Sementsov-Ogievskiy
2026-03-03 16:42 ` Peter Xu
2026-03-04 17:04 ` Vladimir Sementsov-Ogievskiy
2026-02-20 21:02 ` [PATCH v2 16/16] migration/vmstate-types: " Vladimir Sementsov-Ogievskiy
2026-03-03 16:56 ` Peter Xu
2026-03-04 17:38 ` Vladimir Sementsov-Ogievskiy
2026-03-04 18:20 ` Peter Xu
2026-03-04 19:15 ` Vladimir Sementsov-Ogievskiy
2026-03-04 19:20 ` Peter Xu
2026-03-04 20:06 ` Vladimir Sementsov-Ogievskiy
2026-03-04 21:53 ` Peter Xu
2026-02-20 21:05 ` [PATCH v2 00/16] migration: more bool+errp APIs Vladimir Sementsov-Ogievskiy
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=aacAhTY55cp4QgQu@x1.local \
--to=peterx@redhat.com \
--cc=farosas@suse.de \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/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.