From: Juraj Marcin <jmarcin@redhat.com>
This allows devices to specify when during migration their fields should
be saved. For now there are two Save Phases defined.
EARLY_START
These devices are saved during qemu_savevm_state_setup(), and
corresponds to migration SETUP state, same behavior as the former
early_setup flag.
COMPLETE
These devices are saved during migration completion or switch-over with
qemu_savevm_state_complete_precopy_non_iterable(), this corresponds to
the migration DEVICE state. This is the default phase if none is
specified explicitly.
This also allows introduction of other phases in the future, for example
ITERATE_LIVE and POSTCOPY once support for iterative devices and
postcopy is implemented in VMSD, and for the NETPASS phase implemented
in this series.
Signed-off-by: Juraj Marcin <jmarcin@redhat.com>
---
hw/virtio/virtio-mem.c | 2 +-
include/migration/vmstate.h | 27 +++++++++++++++++++--------
migration/savevm.c | 4 ++--
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
index c1e2defb68..6d3e3746e5 100644
--- a/hw/virtio/virtio-mem.c
+++ b/hw/virtio/virtio-mem.c
@@ -1438,7 +1438,7 @@ static const VMStateDescription vmstate_virtio_mem_device_early = {
.name = "virtio-mem-device-early",
.minimum_version_id = 1,
.version_id = 1,
- .early_setup = true,
+ .phase = VMS_PHASE_EARLY_SETUP,
.post_load = virtio_mem_post_load_early,
.fields = (const VMStateField[]) {
VMSTATE_WITH_TMP(VirtIOMEM, VirtIOMEMMigSanityChecks,
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index ed9095a466..62d7e9fe38 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -186,18 +186,29 @@ struct VMStateField {
bool (*field_exists)(void *opaque, int version_id);
};
-struct VMStateDescription {
- const char *name;
- bool unmigratable;
+typedef enum {
/*
- * This VMSD describes something that should be sent during setup phase
- * of migration. It plays similar role as save_setup() for explicitly
+ * Specifies a VMSD of a device that should be migrated during the migration
+ * completion phase (switch-over). (Default behavior, same behavior as
+ * before the introduction of save phase.)
+ */
+ VMS_PHASE_COMPLETE = 0,
+ /*
+ * Specifies a VMSD of a device that should be saved during setup phase of
+ * migration. It plays similar role as save_setup() for explicitly
* registered vmstate entries, so it can be seen as a way to describe
* save_setup() in VMSD structures.
- *
+ */
+ VMS_PHASE_EARLY_SETUP,
+} VMStateSavePhase;
+
+struct VMStateDescription {
+ const char *name;
+ bool unmigratable;
+ /*
* Note that for now, a SaveStateEntry cannot have a VMSD and
* operations (e.g., save_setup()) set at the same time. Consequently,
- * save_setup() and a VMSD with early_setup set to true are mutually
+ * save_setup() and a VMSD with phase set to EARLY_SETUP are mutually
* exclusive. For this reason, also early_setup VMSDs are migrated in a
* QEMU_VM_SECTION_FULL section, while save_setup() data is migrated in
* a QEMU_VM_SECTION_START section.
@@ -213,7 +224,7 @@ struct VMStateDescription {
* <0 on error where -value is an error number from errno.h
*/
- bool early_setup;
+ VMStateSavePhase phase;
int version_id;
int minimum_version_id;
MigrationPriority priority;
diff --git a/migration/savevm.c b/migration/savevm.c
index 1020094fc8..78eb1d6165 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1370,7 +1370,7 @@ int qemu_savevm_state_setup(QEMUFile *f, Error **errp)
trace_savevm_state_setup();
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
- if (se->vmsd && se->vmsd->early_setup) {
+ if (se->vmsd && se->vmsd->phase == VMS_PHASE_EARLY_SETUP) {
ret = vmstate_save(f, se, vmdesc, errp);
if (ret) {
migrate_error_propagate(ms, error_copy(*errp));
@@ -1672,7 +1672,7 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f,
cpu_synchronize_all_states();
QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
- if (se->vmsd && se->vmsd->early_setup) {
+ if (se->vmsd && se->vmsd->phase != VMS_PHASE_COMPLETE) {
/* Already saved during qemu_savevm_state_setup(). */
continue;
}
--
2.52.0