Commit 8c07559f authored by Aaron Lindsay's avatar Aaron Lindsay Committed by Peter Maydell
Browse files

migration: Add post_save function to VMStateDescription



In some cases it may be helpful to modify state before saving it for
migration, and then modify the state back after it has been saved. The
existing pre_save function provides half of this functionality. This
patch adds a post_save function to provide the second half.

Signed-off-by: default avatarAaron Lindsay <aclindsa@gmail.com>
Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
Reviewed-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
Message-id: 20181211151945.29137-2-aaron@os.amperecomputing.com
Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parent 8733d762
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -419,8 +419,13 @@ The functions to do that are inside a vmstate definition, and are called:

  This function is called before we save the state of one device.

Example: You can look at hpet.c, that uses the three function to
massage the state that is transferred.
- ``int (*post_save)(void *opaque);``

  This function is called after we save the state of one device
  (even upon failure, unless the call to pre_save returned an error).

Example: You can look at hpet.c, that uses the first three functions
to massage the state that is transferred.

The ``VMSTATE_WITH_TMP`` macro may be useful when the migration
data doesn't match the stored device data well; it allows an
+1 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ struct VMStateDescription {
    int (*pre_load)(void *opaque);
    int (*post_load)(void *opaque, int version_id);
    int (*pre_save)(void *opaque);
    int (*post_save)(void *opaque);
    bool (*needed)(void *opaque);
    const VMStateField *fields;
    const VMStateDescription **subsections;
+12 −1
Original line number Diff line number Diff line
@@ -390,6 +390,9 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
                if (ret) {
                    error_report("Save of field %s/%s failed",
                                 vmsd->name, field->name);
                    if (vmsd->post_save) {
                        vmsd->post_save(opaque);
                    }
                    return ret;
                }

@@ -415,7 +418,15 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
        json_end_array(vmdesc);
    }

    return vmstate_subsection_save(f, vmsd, opaque, vmdesc);
    ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc);

    if (vmsd->post_save) {
        int ps_ret = vmsd->post_save(opaque);
        if (!ret) {
            ret = ps_ret;
        }
    }
    return ret;
}

static const VMStateDescription *