[PATCH v2 39/73] qemu: Set migration capabilities automatically

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Most migration capabilities are directly connected with
virDomainMigrateFlags so qemuMigrationParamsFromFlags can automatically
enable them.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_migration.c        | 30 ---------------------
 src/qemu/qemu_migration_params.c | 45 +++++++++++++++++++++++++++-----
 src/qemu/qemu_migration_params.h |  6 -----
 3 files changed, 39 insertions(+), 42 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 0446003f47..e1a29d9569 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2385,18 +2385,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
         goto stopjob;
     }
 
-    if (qemuMigrationParamsSetCapability(vm,
-                                         QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
-                                         flags & VIR_MIGRATE_RDMA_PIN_ALL,
-                                         migParams) < 0)
-        goto stopjob;
-
-    if (qemuMigrationParamsSetCapability(vm,
-                                         QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
-                                         flags & VIR_MIGRATE_POSTCOPY,
-                                         migParams) < 0)
-        goto stopjob;
-
     if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
                                  migParams) < 0)
         goto stopjob;
@@ -3341,24 +3329,6 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
     if (qemuMigrationParamsSetCompression(vm, compression, migParams) < 0)
         goto error;
 
-    if (qemuMigrationParamsSetCapability(vm,
-                                         QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
-                                         flags & VIR_MIGRATE_AUTO_CONVERGE,
-                                         migParams) < 0)
-        goto error;
-
-    if (qemuMigrationParamsSetCapability(vm,
-                                         QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
-                                         flags & VIR_MIGRATE_RDMA_PIN_ALL,
-                                         migParams) < 0)
-        goto error;
-
-    if (qemuMigrationParamsSetCapability(vm,
-                                         QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
-                                         flags & VIR_MIGRATE_POSTCOPY,
-                                         migParams) < 0)
-        goto error;
-
     if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
                                  migParams) < 0)
         goto error;
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 03056eed09..369e560990 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -49,6 +49,13 @@ struct _qemuMigrationParamsAlwaysOnItem {
     int party; /* bit-wise OR of qemuMigrationParty */
 };
 
+typedef struct _qemuMigrationParamsFlagMapItem qemuMigrationParamsFlagMapItem;
+struct _qemuMigrationParamsFlagMapItem {
+    virDomainMigrateFlags flag;
+    qemuMonitorMigrationCaps cap;
+    int party; /* bit-wise OR of qemuMigrationParty */
+};
+
 /* Migration capabilities which should always be enabled as long as they
  * are supported by QEMU. */
 static const qemuMigrationParamsAlwaysOnItem qemuMigrationParamsAlwaysOn[] = {
@@ -56,6 +63,21 @@ static const qemuMigrationParamsAlwaysOnItem qemuMigrationParamsAlwaysOn[] = {
      QEMU_MIGRATION_SOURCE},
 };
 
+/* Translation from virDomainMigrateFlags to qemuMonitorMigrationCaps. */
+static const qemuMigrationParamsFlagMapItem qemuMigrationParamsFlagMap[] = {
+    {VIR_MIGRATE_RDMA_PIN_ALL,
+     QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
+     QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
+
+    {VIR_MIGRATE_AUTO_CONVERGE,
+     QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
+     QEMU_MIGRATION_SOURCE},
+
+    {VIR_MIGRATE_POSTCOPY,
+     QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
+     QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
+};
+
 
 static qemuMigrationParamsPtr
 qemuMigrationParamsNew(void)
@@ -97,12 +119,21 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
                              qemuMigrationParty party)
 {
     qemuMigrationParamsPtr migParams;
+    size_t i;
 
     if (!(migParams = qemuMigrationParamsNew()))
         return NULL;
 
-    if (!params)
-        return migParams;
+    for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsFlagMap); i++) {
+        qemuMonitorMigrationCaps cap = qemuMigrationParamsFlagMap[i].cap;
+
+        if (qemuMigrationParamsFlagMap[i].party & party &&
+            flags & qemuMigrationParamsFlagMap[i].flag) {
+            VIR_DEBUG("Enabling migration capability '%s'",
+                      qemuMonitorMigrationCapsTypeToString(cap));
+            ignore_value(virBitmapSetBit(migParams->caps, cap));
+        }
+    }
 
 #define GET(PARAM, VAR) \
     do { \
@@ -116,9 +147,11 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
             migParams->params.VAR ## _set = true; \
     } while (0)
 
-    if (party == QEMU_MIGRATION_SOURCE) {
-        GET(AUTO_CONVERGE_INITIAL, cpuThrottleInitial);
-        GET(AUTO_CONVERGE_INCREMENT, cpuThrottleIncrement);
+    if (params) {
+        if (party == QEMU_MIGRATION_SOURCE) {
+            GET(AUTO_CONVERGE_INITIAL, cpuThrottleInitial);
+            GET(AUTO_CONVERGE_INCREMENT, cpuThrottleIncrement);
+        }
     }
 
 #undef GET
@@ -197,7 +230,7 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 }
 
 
-int
+static int
 qemuMigrationParamsSetCapability(virDomainObjPtr vm ATTRIBUTE_UNUSED,
                                  qemuMonitorMigrationCaps capability,
                                  bool state,
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index fac901e35c..494ac104ad 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -71,12 +71,6 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
                          int asyncJob,
                          qemuMigrationParamsPtr migParams);
 
-int
-qemuMigrationParamsSetCapability(virDomainObjPtr vm,
-                                 qemuMonitorMigrationCaps capability,
-                                 bool state,
-                                 qemuMigrationParamsPtr migParams);
-
 int
 qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
-- 
2.17.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux