From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 38/53] vmstate: Add a VSTRUCT type
Date: Thu, 31 May 2018 19:16:56 +0200 [thread overview]
Message-ID: <20180531171656.21855-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20180531171656.21855-1-pbonzini@redhat.com>
From: Corey Minyard <cminyard@mvista.com>
The VMS_STRUCT has no way to specify which version of a structure
to use. Add a type and a new field to allow the specific version
of a structure to be used.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
Message-Id: <1524670052-28373-2-git-send-email-minyard@acm.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
include/migration/vmstate.h | 45 +++++++++++++++++++++++++++++++++++++
migration/vmstate.c | 25 +++++++++++++++++----
2 files changed, 66 insertions(+), 4 deletions(-)
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index df463fd33d..efa0a1150e 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -143,6 +143,11 @@ enum VMStateFlags {
* to determine the number of entries in the array. Only valid in
* combination with one of VMS_VARRAY*. */
VMS_MULTIPLY_ELEMENTS = 0x4000,
+
+ /* A structure field that is like VMS_STRUCT, but uses
+ * VMStateField.struct_version_id to tell which version of the
+ * structure we are referencing to use. */
+ VMS_VSTRUCT = 0x8000,
};
typedef enum {
@@ -167,6 +172,7 @@ struct VMStateField {
enum VMStateFlags flags;
const VMStateDescription *vmsd;
int version_id;
+ int struct_version_id;
bool (*field_exists)(void *opaque, int version_id);
};
@@ -248,6 +254,25 @@ extern const VMStateInfo vmstate_info_qtailq;
vmstate_offset_array(_state, _field, uint8_t, \
sizeof(typeof_field(_state, _field)))
+/* In the macros below, if there is a _version, that means the macro's
+ * field will be processed only if the version being received is >=
+ * the _version specified. In general, if you add a new field, you
+ * would increment the structure's version and put that version
+ * number into the new field so it would only be processed with the
+ * new version.
+ *
+ * In particular, for VMSTATE_STRUCT() and friends the _version does
+ * *NOT* pick the version of the sub-structure. It works just as
+ * specified above. The version of the top-level structure received
+ * is passed down to all sub-structures. This means that the
+ * sub-structures must have version that are compatible with all the
+ * structures that use them.
+ *
+ * If you want to specify the version of the sub-structure, use
+ * VMSTATE_VSTRUCT(), which allows the specific sub-structure version
+ * to be directly specified.
+ */
+
#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) { \
.name = (stringify(_field)), \
.version_id = (_version), \
@@ -395,6 +420,17 @@ extern const VMStateInfo vmstate_info_qtailq;
.offset = offsetof(_state, _field), \
}
+#define VMSTATE_VSTRUCT_TEST(_field, _state, _test, _version, _vmsd, _type, _struct_version) { \
+ .name = (stringify(_field)), \
+ .version_id = (_version), \
+ .struct_version_id = (_struct_version), \
+ .field_exists = (_test), \
+ .vmsd = &(_vmsd), \
+ .size = sizeof(_type), \
+ .flags = VMS_VSTRUCT, \
+ .offset = vmstate_offset_value(_state, _field, _type), \
+}
+
#define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
.name = (stringify(_field)), \
.version_id = (_version), \
@@ -712,6 +748,13 @@ extern const VMStateInfo vmstate_info_qtailq;
#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \
VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)
+#define VMSTATE_VSTRUCT(_field, _state, _vmsd, _type, _struct_version)\
+ VMSTATE_VSTRUCT_TEST(_field, _state, NULL, 0, _vmsd, _type, _struct_version)
+
+#define VMSTATE_VSTRUCT_V(_field, _state, _version, _vmsd, _type, _struct_version) \
+ VMSTATE_VSTRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type, \
+ _struct_version)
+
#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \
VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
@@ -1000,6 +1043,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque, int version_id);
int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque, QJSON *vmdesc);
+int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
+ void *opaque, QJSON *vmdesc, int version_id);
bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);
diff --git a/migration/vmstate.c b/migration/vmstate.c
index 0b3282c9df..f0b07f4ea1 100644
--- a/migration/vmstate.c
+++ b/migration/vmstate.c
@@ -136,6 +136,9 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
} else if (field->flags & VMS_STRUCT) {
ret = vmstate_load_state(f, field->vmsd, curr_elem,
field->vmsd->version_id);
+ } else if (field->flags & VMS_VSTRUCT) {
+ ret = vmstate_load_state(f, field->vmsd, curr_elem,
+ field->struct_version_id);
} else {
ret = field->info->get(f, curr_elem, size, field);
}
@@ -209,6 +212,8 @@ static const char *vmfield_get_type_name(VMStateField *field)
if (field->flags & VMS_STRUCT) {
type = "struct";
+ } else if (field->flags & VMS_VSTRUCT) {
+ type = "vstruct";
} else if (field->info->name) {
type = field->info->name;
}
@@ -309,7 +314,13 @@ bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque)
int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
- void *opaque, QJSON *vmdesc)
+ void *opaque, QJSON *vmdesc_id)
+{
+ return vmstate_save_state_v(f, vmsd, opaque, vmdesc_id, vmsd->version_id);
+}
+
+int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
+ void *opaque, QJSON *vmdesc, int version_id)
{
int ret = 0;
VMStateField *field = vmsd->fields;
@@ -327,13 +338,15 @@ int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
if (vmdesc) {
json_prop_str(vmdesc, "vmsd_name", vmsd->name);
- json_prop_int(vmdesc, "version", vmsd->version_id);
+ json_prop_int(vmdesc, "version", version_id);
json_start_array(vmdesc, "fields");
}
while (field->name) {
- if (!field->field_exists ||
- field->field_exists(opaque, vmsd->version_id)) {
+ if ((field->field_exists &&
+ field->field_exists(opaque, version_id)) ||
+ (!field->field_exists &&
+ field->version_id <= version_id)) {
void *first_elem = opaque + field->offset;
int i, n_elems = vmstate_n_elems(opaque, field);
int size = vmstate_size(opaque, field);
@@ -363,6 +376,10 @@ int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
} else if (field->flags & VMS_STRUCT) {
ret = vmstate_save_state(f, field->vmsd, curr_elem,
vmdesc_loop);
+ } else if (field->flags & VMS_VSTRUCT) {
+ ret = vmstate_save_state_v(f, field->vmsd, curr_elem,
+ vmdesc_loop,
+ field->struct_version_id);
} else {
ret = field->info->put(f, curr_elem, size, field,
vmdesc_loop);
--
2.17.0
next prev parent reply other threads:[~2018-05-31 17:17 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-31 17:12 [Qemu-devel] [PULL 00/53] Misc patches for 2018-05-31 Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 01/53] sandbox: disable -sandbox if CONFIG_SECCOMP undefined Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 02/53] vfio: Include "exec/address-spaces.h" directly in the source file Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 03/53] accel: Do not include "exec/address-spaces.h" if it is not necessary Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 04/53] target: " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 05/53] memory: Do not include "exec/ioport.h" " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 06/53] target/i386: " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 07/53] target/xtensa: Include "qemu/timer.h" to use NANOSECONDS_PER_SECOND Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 08/53] target/ppc: Include "exec/exec-all.h" which provides tlb_flush() Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 09/53] target/hppa: Include "qemu/log.h" to use qemu_log() Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 10/53] target: Do not include "exec/exec-all.h" if it is not necessary Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 11/53] nios2: do not include exec-all.h from cpu.h Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 12/53] hw: Do not include "exec/ioport.h" if it is not necessary Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 13/53] hw: Do not include "exec/address-spaces.h" " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 14/53] hw: Do not include "sysemu/block-backend.h" " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 15/53] hw: Do not include "sysemu/blockdev.h" " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 16/53] " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 17/53] hw/block/nvme: Include "qemu/cutils.h" directly in the source file Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 18/53] hw/misc/mips_itu: Cleanup includes Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 19/53] hw/misc/sga: Use the correct ISA include Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 20/53] hw/hppa: Remove unused include Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 21/53] hw/i386/pc: " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 22/53] hw/ide: " Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 23/53] hw: Clean "hw/devices.h" includes Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 24/53] qom: Document qom/device-list-properties implementation specific Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 25/53] qom: support orphan objects in object_get_canonical_path Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 26/53] virtio: free MemoryRegionCache when initialization fails Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 27/53] memory.h: Fix typo in documentation comment Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 28/53] memory: get rid of memory_region_init_reservation Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 29/53] memory: delete struct AddressSpaceOps Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 30/53] hw/isa/superio: Fix inconsistent use of Chardev->be Paolo Bonzini
2018-05-31 18:08 ` Philippe Mathieu-Daudé
2018-05-31 17:12 ` [Qemu-devel] [PULL 31/53] mux: fix ctrl-a b again Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 32/53] memfd: Avoid Coverity warning about integer overflow Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 33/53] exec.c: Initialize sa_flags passed to sigaction() Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 34/53] WHPX: dynamically load WHP libraries Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 35/53] WHPX: fix some compiler warnings Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 36/53] qemu-options: Mark the non-functional -clock option as deprecated Paolo Bonzini
2018-05-31 17:12 ` [Qemu-devel] [PULL 37/53] tcg: remove softfloat from --disable-tcg builds Paolo Bonzini
2018-05-31 17:15 ` [Qemu-devel] [PULL 39/53] ipmi: Use proper struct reference for KCS vmstate Paolo Bonzini
2018-05-31 17:15 ` [Qemu-devel] [PULL 40/53] docs/interop: add "firmware.json" Paolo Bonzini
2018-05-31 19:07 ` Eric Blake
2018-05-31 17:15 ` [Qemu-devel] [PULL 41/53] gdbstub: Prevent fd leakage Paolo Bonzini
2018-05-31 17:15 ` [Qemu-devel] [PULL 42/53] virtio-gpu-3d: Define VIRTIO_GPU_CAPSET_VIRGL2 elsewhere Paolo Bonzini
2018-05-31 17:15 ` [Qemu-devel] [PULL 43/53] scripts/update-linux-headers: Handle __aligned_u64 Paolo Bonzini
2018-05-31 17:15 ` [Qemu-devel] [PULL 44/53] scripts/update-linux-headers: Handle kernel license no longer being one file Paolo Bonzini
2018-05-31 17:15 ` [Qemu-devel] [PULL 45/53] target/i386/kvm.c: Handle renaming of KVM_HINTS_DEDICATED Paolo Bonzini
2018-05-31 17:15 ` [Qemu-devel] [PULL 46/53] Update Linux headers to 4.17-rc6 Paolo Bonzini
2018-05-31 17:16 ` [Qemu-devel] [PULL 47/53] target/i386/kvm.c: Remove compatibility shim for KVM_HINTS_REALTIME Paolo Bonzini
2018-05-31 17:16 ` [Qemu-devel] [PULL 48/53] hw/i2c/smbus: Use DeviceClass::realize instead of SMBusDeviceClass::init Paolo Bonzini
2018-05-31 17:16 ` [Qemu-devel] [PULL 49/53] hw/i2c: Use DeviceClass::realize instead of I2CSlaveClass::init Paolo Bonzini
2018-05-31 17:16 ` [Qemu-devel] [PULL 50/53] qdev: Simplify the SysBusDeviceClass::init path Paolo Bonzini
2018-05-31 17:16 ` [Qemu-devel] [PULL 51/53] qdev: Remove DeviceClass::init() and ::exit() Paolo Bonzini
2018-05-31 17:16 ` [Qemu-devel] [PULL 52/53] char: Remove unwanted crlf conversion Paolo Bonzini
2018-06-08 17:39 ` Greg Kurz
2018-06-08 17:56 ` Philippe Mathieu-Daudé
2018-06-09 7:31 ` Greg Kurz
2018-06-08 18:08 ` Patryk Olszewski
2018-05-31 17:16 ` [Qemu-devel] [PULL 53/53] memory: Make operations using MemoryRegionIoeventfd struct pass by pointer Paolo Bonzini
2018-05-31 17:16 ` [Qemu-devel] [PULL 37/53] tcg: remove softfloat from --disable-tcg builds Paolo Bonzini
2018-05-31 17:16 ` Paolo Bonzini [this message]
2018-05-31 17:52 ` [Qemu-devel] [PULL 00/53] Misc patches for 2018-05-31 Peter Maydell
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=20180531171656.21855-2-pbonzini@redhat.com \
--to=pbonzini@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;
as well as URLs for NNTP newsgroup(s).