* Juan Quintela ([email protected]) wrote:
> To make sections optional, we need to do it at the beggining of the code.
>
> Signed-off-by: Juan Quintela <[email protected]>
Do you also need to add this test to qemu_save_device_state ?
Dave
> ---
> include/migration/vmstate.h | 2 ++
> migration/vmstate.c | 11 +++++++++++
> savevm.c | 4 ++++
> 3 files changed, 17 insertions(+)
>
> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
> index fc5e643..a8b59eb 100644
> --- a/include/migration/vmstate.h
> +++ b/include/migration/vmstate.h
> @@ -813,6 +813,8 @@ int vmstate_load_state(QEMUFile *f, const
> VMStateDescription *vmsd,
> void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
> void *opaque, QJSON *vmdesc);
>
> +bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
> +
> int vmstate_register_with_alias_id(DeviceState *dev, int instance_id,
> const VMStateDescription *vmsd,
> void *base, int alias_id,
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index 108995e..36dab84 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -276,6 +276,17 @@ static void vmsd_desc_field_end(const VMStateDescription
> *vmsd, QJSON *vmdesc,
> json_end_object(vmdesc);
> }
>
> +
> +bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque)
> +{
> + if (vmsd->needed && !vmsd->needed(opaque)) {
> + /* optional section not needed */
> + return false;
> + }
> + return true;
> +}
> +
> +
> void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
> void *opaque, QJSON *vmdesc)
> {
> diff --git a/savevm.c b/savevm.c
> index 01770cd..2b4e554 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -763,6 +763,10 @@ void qemu_savevm_state_complete(QEMUFile *f)
> if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
> continue;
> }
> + if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) {
> + continue;
> + }
> +
> trace_savevm_section_start(se->idstr, se->section_id);
>
> json_start_object(vmdesc, NULL);
> --
> 2.4.0
>
>
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK