Added a new `libvirt` migration flag `VIR_MIGRATE_POSTCOPY` and the
necessary code to pass this flag to qemu as migration capability.
Signed-off-by: Cristian Klein <cristian.klein(a)cs.umu.se>
---
include/libvirt/libvirt.h.in | 1 +
src/libvirt.c | 7 +++++++
src/qemu/qemu_migration.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_migration.h | 3 ++-
4 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 6371b7b..bdc33c6 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1225,6 +1225,7 @@ typedef enum {
VIR_MIGRATE_ABORT_ON_ERROR = (1 << 12), /* abort migration on I/O errors
happened during migration */
VIR_MIGRATE_AUTO_CONVERGE = (1 << 13), /* force convergence */
VIR_MIGRATE_RDMA_PIN_ALL = (1 << 14), /* RDMA memory pinning */
+ VIR_MIGRATE_POSTCOPY = (1 << 15), /* enable (but don't start)
post-copy */
} virDomainMigrateFlags;
diff --git a/src/libvirt.c b/src/libvirt.c
index 1a285ca..33aeafa 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -5265,6 +5265,7 @@ virDomainMigrateDirect(virDomainPtr domain,
* automatically when supported).
* VIR_MIGRATE_UNSAFE Force migration even if it is considered unsafe.
* VIR_MIGRATE_OFFLINE Migrate offline
+ * VIR_MIGRATE_POSTCOPY Enable (but don't start) post-copy
*
* VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
* Applications using the VIR_MIGRATE_PEER2PEER flag will probably
@@ -5291,6 +5292,12 @@ virDomainMigrateDirect(virDomainPtr domain,
* can use either VIR_MIGRATE_NON_SHARED_DISK or
* VIR_MIGRATE_NON_SHARED_INC as they are mutually exclusive.
*
+ * If you want to enable post-copy migration you must set the
+ * VIR_MIGRATE_POSTCOPY flag. Once migration is active, you may
+ * start post-copy by calling virDomainMigrateStartPostCopy.
+ * When to start post-copy is entirely left to the user, libvirt
+ * only implements the necessary mechanism.
+ *
* In either case it is typically only necessary to specify a
* URI if the destination host has multiple interfaces and a
* specific interface is required to transmit migration data.
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index a5bd825..bd1f2d6 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1799,6 +1799,45 @@ qemuMigrationSetOffline(virQEMUDriverPtr driver,
static int
+qemuMigrationSetPostCopy(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ qemuDomainAsyncJob job)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ int ret;
+
+ if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0)
+ return -1;
+
+ ret = qemuMonitorGetMigrationCapability(
+ priv->mon,
+ QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY);
+
+ if (ret < 0) {
+ goto cleanup;
+ } else if (ret == 0) {
+ if (job == QEMU_ASYNC_JOB_MIGRATION_IN) {
+ virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+ _("Post-copy migration is not supported by "
+ "target QEMU binary"));
+ } else {
+ virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+ _("Post-copy migration is not supported by "
+ "source QEMU binary"));
+ }
+ ret = -1;
+ goto cleanup;
+ }
+
+ ret = qemuMonitorSetMigrationCapability(
+ priv->mon,
+ QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY);
+
+ cleanup:
+ qemuDomainObjExitMonitor(driver, vm);
+ return ret;
+}
+static int
qemuMigrationSetCompression(virQEMUDriverPtr driver,
virDomainObjPtr vm,
qemuDomainAsyncJob job)
@@ -3580,6 +3619,10 @@ qemuMigrationRun(virQEMUDriverPtr driver,
if (flags & VIR_MIGRATE_RDMA_PIN_ALL &&
qemuMigrationSetPinAll(driver, vm,
QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+
+ if (flags & VIR_MIGRATE_POSTCOPY &&
+ qemuMigrationSetPostCopy(driver, vm,
+ QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
goto cleanup;
if (qemuDomainObjEnterMonitorAsync(driver, vm,
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index e7a90c3..349c9c4 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -41,7 +41,8 @@
VIR_MIGRATE_COMPRESSED | \
VIR_MIGRATE_ABORT_ON_ERROR | \
VIR_MIGRATE_AUTO_CONVERGE | \
- VIR_MIGRATE_RDMA_PIN_ALL)
+ VIR_MIGRATE_RDMA_PIN_ALL | \
+ VIR_MIGRATE_POSTCOPY)
/* All supported migration parameters and their types. */
# define QEMU_MIGRATION_PARAMETERS \
--
1.9.1