public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: Peter Xu <peterx@redhat.com>, qemu-devel@nongnu.org
Cc: Alexander Mikhalitsyn <alexander@mihalicyn.com>,
	Juraj Marcin <jmarcin@redhat.com>,
	peterx@redhat.com
Subject: Re: [PATCH RFC 06/10] vmstate: Introduce vmstate_save_field_with_vmdesc()
Date: Thu, 19 Mar 2026 17:36:33 -0300	[thread overview]
Message-ID: <87fr5v36b2.fsf@suse.de> (raw)
In-Reply-To: <20260317232332.15209-7-peterx@redhat.com>

Peter Xu <peterx@redhat.com> writes:

> Introduce a helper to do both the JSON blob dump and vmstate dump.  This
> further shrinks the function a bit.  More importantly, we'll need to dump
> two fields in one loop very soon in the future with the JSON blob.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  migration/vmstate.c | 38 +++++++++++++++++++++++++++-----------
>  1 file changed, 27 insertions(+), 11 deletions(-)
>
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index caa7b50bce..5a6b352764 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -514,6 +514,30 @@ static bool vmstate_save_field(QEMUFile *f, void *pv, size_t size,
>      return true;
>  }
>  
> +/*
> + * Dump a whole VMSD field, including its JSON blob separately when @vmdesc

Could do without the "dump" terminology all over the series. There's
already use for that term due to -dump-vmstate.

> + * 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);
> +
> +    return ok;
> +}
> +
>  static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
>                                  void *opaque, JSONWriter *vmdesc,
>                                  int version_id, Error **errp)
> @@ -542,7 +566,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;
>  
> @@ -558,7 +581,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMStateDescription *vmsd,
>                  bool is_null;
>                  int max_elems = n_elems - i;
>  
> -                old_offset = qemu_file_transferred(f);
>                  if (field->flags & VMS_ARRAY_OF_POINTER) {
>                      assert(curr_elem);
>                      curr_elem = *(void **)curr_elem;
> @@ -606,15 +628,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) {


  parent reply	other threads:[~2026-03-19 20:37 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17 23:23 [PATCH RFC 00/10] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Peter Xu
2026-03-17 23:23 ` [PATCH RFC 01/10] vmstate: Pass in struct itself for VMSTATE_ARRAY_OF_POINTER Peter Xu
2026-03-18  9:36   ` Alexander Mikhalitsyn
2026-03-17 23:23 ` [PATCH RFC 02/10] vmstate: Pass in struct itself for VMSTATE_VARRAY_OF_POINTER_UINT32 Peter Xu
2026-03-18  9:37   ` Alexander Mikhalitsyn
2026-03-17 23:23 ` [PATCH RFC 03/10] vmstate: Do not set size for VMS_ARRAY_OF_POINTER Peter Xu
2026-03-18  9:37   ` Alexander Mikhalitsyn
2026-03-17 23:23 ` [PATCH RFC 04/10] vmstate: Limit the vmdesc_loop dedup trick to compressable field Peter Xu
2026-03-18  9:43   ` Alexander Mikhalitsyn
2026-03-26 19:27   ` Peter Xu
2026-03-17 23:23 ` [PATCH RFC 05/10] vmstate: Rename VMS_NULLPTR_MARKER to VMS_MARKER_PTR_NULL Peter Xu
2026-03-18  9:38   ` Alexander Mikhalitsyn
2026-03-17 23:23 ` [PATCH RFC 06/10] vmstate: Introduce vmstate_save_field_with_vmdesc() Peter Xu
2026-03-18  9:39   ` Alexander Mikhalitsyn
2026-03-19 20:36   ` Fabiano Rosas [this message]
2026-03-17 23:23 ` [PATCH RFC 07/10] vmstate: Allow vmstate_info_nullptr to emit non-NULL markers Peter Xu
2026-03-18  9:40   ` Alexander Mikhalitsyn
2026-03-19 20:46   ` Fabiano Rosas
2026-03-26 19:25     ` Peter Xu
2026-03-26 21:19       ` Fabiano Rosas
2026-03-17 23:23 ` [PATCH RFC 08/10] vmstate: Implement load of ptr marker in vmstate core Peter Xu
2026-03-18  9:48   ` Alexander Mikhalitsyn
2026-03-19 20:56   ` Fabiano Rosas
2026-03-19 21:57     ` Peter Xu
2026-03-19 22:07       ` Alexander Graf
2026-03-20 13:03       ` Fabiano Rosas
2026-03-20 14:51         ` Peter Xu
2026-03-17 23:23 ` [PATCH RFC 09/10] vmstate: Implement VMS_ARRAY_OF_POINTER_AUTO_ALLOC Peter Xu
2026-03-18 10:00   ` Alexander Mikhalitsyn
2026-03-19 14:10     ` Peter Xu
2026-03-19 22:06   ` Fabiano Rosas
2026-03-20 14:42   ` Fabiano Rosas
2026-03-20 15:37     ` Peter Xu
2026-03-17 23:23 ` [PATCH RFC 10/10] tests/unit/test-vmstate: add tests for VMS_ARRAY_OF_POINTER_ALLOW_NULL Peter Xu

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=87fr5v36b2.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=alexander@mihalicyn.com \
    --cc=jmarcin@redhat.com \
    --cc=peterx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox