Peter Xu <[email protected]> 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 <[email protected]>
> ---
> 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) {