#include CONFIG_DEVICES
#include "trace.h"
+static const VMStateDescription vmstate_virtio_mem_device_early;
+
/*
* We only had legacy x86 guests that did not support
* VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have legacy guests.
host_memory_backend_set_mapped(vmem->memdev, true);
vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem));
+ if (vmem->early_migration) {
+ vmstate_register(VMSTATE_IF(vmem), VMSTATE_INSTANCE_ID_ANY,
+ &vmstate_virtio_mem_device_early, vmem);
+ }
qemu_register_reset(virtio_mem_system_reset, vmem);
/*
*/
memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL);
qemu_unregister_reset(virtio_mem_system_reset, vmem);
+ if (vmem->early_migration) {
+ vmstate_unregister(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_early,
+ vmem);
+ }
vmstate_unregister_ram(&vmem->memdev->mr, DEVICE(vmem));
host_memory_backend_set_mapped(vmem->memdev, false);
virtio_del_queue(vdev, 0);
},
};
+static bool virtio_mem_vmstate_field_exists(void *opaque, int version_id)
+{
+ const VirtIOMEM *vmem = VIRTIO_MEM(opaque);
+
+ /* With early migration, these fields were already migrated. */
+ return !vmem->early_migration;
+}
+
static const VMStateDescription vmstate_virtio_mem_device = {
.name = "virtio-mem-device",
.minimum_version_id = 1,
.version_id = 1,
.priority = MIG_PRI_VIRTIO_MEM,
.post_load = virtio_mem_post_load,
+ .fields = (VMStateField[]) {
+ VMSTATE_WITH_TMP_TEST(VirtIOMEM, virtio_mem_vmstate_field_exists,
+ VirtIOMEMMigSanityChecks,
+ vmstate_virtio_mem_sanity_checks),
+ VMSTATE_UINT64(usable_region_size, VirtIOMEM),
+ VMSTATE_UINT64_TEST(size, VirtIOMEM, virtio_mem_vmstate_field_exists),
+ VMSTATE_UINT64(requested_size, VirtIOMEM),
+ VMSTATE_BITMAP_TEST(bitmap, VirtIOMEM, virtio_mem_vmstate_field_exists,
+ 0, bitmap_size),
+ VMSTATE_END_OF_LIST()
+ },
+};
+
+/*
+ * Transfer properties that are immutable while migration is active early,
+ * such that we have have this information around before migrating any RAM
+ * content.
+ *
+ * Note that virtio_mem_is_busy() makes sure these properties can no longer
+ * change on the migration source until migration completed.
+ *
+ * With QEMU compat machines, we transmit these properties later, via
+ * vmstate_virtio_mem_device instead -- see virtio_mem_vmstate_field_exists().
+ */
+static const VMStateDescription vmstate_virtio_mem_device_early = {
+ .name = "virtio-mem-device-early",
+ .minimum_version_id = 1,
+ .version_id = 1,
+ .early_setup = true,
.fields = (VMStateField[]) {
VMSTATE_WITH_TMP(VirtIOMEM, VirtIOMEMMigSanityChecks,
vmstate_virtio_mem_sanity_checks),
- VMSTATE_UINT64(usable_region_size, VirtIOMEM),
VMSTATE_UINT64(size, VirtIOMEM),
- VMSTATE_UINT64(requested_size, VirtIOMEM),
VMSTATE_BITMAP(bitmap, VirtIOMEM, 0, bitmap_size),
VMSTATE_END_OF_LIST()
},
DEFINE_PROP_ON_OFF_AUTO(VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP, VirtIOMEM,
unplugged_inaccessible, ON_OFF_AUTO_AUTO),
#endif
+ DEFINE_PROP_BOOL(VIRTIO_MEM_EARLY_MIGRATION_PROP, VirtIOMEM,
+ early_migration, true),
DEFINE_PROP_END_OF_LIST(),
};