[libvirt] [PATCH v2 4/8] Implemented VIR_MIGRATE_POSTCOPY in qemu driver

Cristian Klein cristian.klein at cs.umu.se
Tue Sep 30 14:39:25 UTC 2014


Signed-off-by: Cristian Klein <cristian.klein at cs.umu.se>
---
 src/qemu/qemu_migration.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_migration.h |  3 ++-
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 284cd5a..4a36946 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1801,6 +1801,49 @@ 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;
+    }
+
+    /* Post-copy only needs to be enabled on source qemu,
+     * for target, this function only acts as a capability check */
+    if (job == QEMU_ASYNC_JOB_MIGRATION_OUT) {
+        ret = qemuMonitorSetMigrationCapability(
+                    priv->mon,
+                    QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY);
+    }
+
+ cleanup:
+    qemuDomainObjExitMonitor(driver, vm);
+    return ret;
+}
+static int
 qemuMigrationSetCompression(virQEMUDriverPtr driver,
                             virDomainObjPtr vm,
                             qemuDomainAsyncJob job)
@@ -2741,6 +2784,11 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
         dataFD[1] = -1; /* 'st' owns the FD now & will close it */
     }
 
+    if (flags & VIR_MIGRATE_POSTCOPY &&
+        qemuMigrationSetPostCopy(driver, vm,
+                                 QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+        goto stop;
+
     if (flags & VIR_MIGRATE_COMPRESSED &&
         qemuMigrationSetCompression(driver, vm,
                                     QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
@@ -3583,6 +3631,18 @@ qemuMigrationRun(virQEMUDriverPtr driver,
                                QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
         goto cleanup;
 
+    if (flags & VIR_MIGRATE_POSTCOPY) {
+        if (!(flags & VIR_MIGRATE_LIVE)) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Enabling post-copy only makes sense with "
+                             "live migration"));
+            goto cleanup;
+        }
+        if (qemuMigrationSetPostCopy(driver, vm,
+                                     QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+            goto cleanup;
+    }
+
     if (qemuDomainObjEnterMonitorAsync(driver, vm,
                                        QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
         goto cleanup;
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




More information about the libvir-list mailing list