[PATCH 3/5] qemu: Use bitmap with migration capabilities

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

 



All calls to qemuMonitorGetMigrationCapability in QEMU driver are
replaced with qemuMigrationCapsGet.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c    |  7 +++++++
 src/qemu/qemu_driver.c    | 32 +++++++++++++-------------------
 src/qemu/qemu_migration.c | 45 ++++++++++++++++++++++++++-------------------
 src/qemu/qemu_migration.h |  4 ++++
 4 files changed, 50 insertions(+), 38 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a8cabc5727..1dcf263ce5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10184,6 +10184,13 @@ qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver,
         }
     }
 
+    /* Migration events capability must always be enabled, clearing it from
+     * migration capabilities bitmap makes sure it won't be touched anywhere
+     * else.
+     */
+    ignore_value(virBitmapClearBit(priv->migrationCaps,
+                                   QEMU_MONITOR_MIGRATION_CAPS_EVENTS));
+
     ret = 0;
 
  cleanup:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fb4d722368..7f77dcb994 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13413,20 +13413,17 @@ qemuDomainMigrateGetCompressionCache(virDomainPtr dom,
 
     priv = vm->privateData;
 
-    qemuDomainObjEnterMonitor(driver, vm);
-
-    ret = qemuMonitorGetMigrationCapability(
-                priv->mon,
-                QEMU_MONITOR_MIGRATION_CAPS_XBZRLE);
-    if (ret == 0) {
+    if (!qemuMigrationCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
                        _("Compressed migration is not supported by "
                          "QEMU binary"));
-        ret = -1;
-    } else if (ret > 0) {
-        ret = qemuMonitorGetMigrationCacheSize(priv->mon, cacheSize);
+        goto endjob;
     }
 
+    qemuDomainObjEnterMonitor(driver, vm);
+
+    ret = qemuMonitorGetMigrationCacheSize(priv->mon, cacheSize);
+
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         ret = -1;
 
@@ -13467,21 +13464,18 @@ qemuDomainMigrateSetCompressionCache(virDomainPtr dom,
 
     priv = vm->privateData;
 
-    qemuDomainObjEnterMonitor(driver, vm);
-
-    ret = qemuMonitorGetMigrationCapability(
-                priv->mon,
-                QEMU_MONITOR_MIGRATION_CAPS_XBZRLE);
-    if (ret == 0) {
+    if (!qemuMigrationCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
                        _("Compressed migration is not supported by "
                          "QEMU binary"));
-        ret = -1;
-    } else if (ret > 0) {
-        VIR_DEBUG("Setting compression cache to %llu B", cacheSize);
-        ret = qemuMonitorSetMigrationCacheSize(priv->mon, cacheSize);
+        goto endjob;
     }
 
+    qemuDomainObjEnterMonitor(driver, vm);
+
+    VIR_DEBUG("Setting compression cache to %llu B", cacheSize);
+    ret = qemuMonitorSetMigrationCacheSize(priv->mon, cacheSize);
+
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         ret = -1;
 
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index b286d68061..72edbb667c 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1274,17 +1274,12 @@ qemuMigrationSetOption(virQEMUDriverPtr driver,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     int ret;
 
-    if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0)
-        return -1;
+    if (!qemuMigrationCapsGet(vm, capability)) {
+        if (!state) {
+            /* Unsupported but we want it off anyway */
+            return 0;
+        }
 
-    ret = qemuMonitorGetMigrationCapability(priv->mon, capability);
-
-    if (ret < 0) {
-        goto cleanup;
-    } else if (ret == 0 && !state) {
-        /* Unsupported but we want it off anyway */
-        goto cleanup;
-    } else if (ret == 0) {
         if (job == QEMU_ASYNC_JOB_MIGRATION_IN) {
             virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
                            _("Migration option '%s' is not supported by "
@@ -1296,15 +1291,17 @@ qemuMigrationSetOption(virQEMUDriverPtr driver,
                              "source QEMU binary"),
                            qemuMonitorMigrationCapsTypeToString(capability));
         }
-        ret = -1;
-        goto cleanup;
+        return -1;
     }
 
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0)
+        return -1;
+
     ret = qemuMonitorSetMigrationCapability(priv->mon, capability, state);
 
- cleanup:
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         ret = -1;
+
     return ret;
 }
 
@@ -5923,12 +5920,8 @@ qemuMigrationReset(virQEMUDriverPtr driver,
         goto cleanup;
 
     for (cap = 0; cap < QEMU_MONITOR_MIGRATION_CAPS_LAST; cap++) {
-        /* "events" capability is set (when supported) in qemuConnectMonitor
-         * and should never be cleared */
-        if (cap == QEMU_MONITOR_MIGRATION_CAPS_EVENTS)
-            continue;
-
-        if (qemuMigrationSetOption(driver, vm, cap, false, job) < 0)
+        if (qemuMigrationCapsGet(vm, cap) &&
+            qemuMigrationSetOption(driver, vm, cap, false, job) < 0)
             goto cleanup;
     }
 
@@ -5989,3 +5982,17 @@ qemuMigrationFetchMirrorStats(virQEMUDriverPtr driver,
     virHashFree(blockinfo);
     return 0;
 }
+
+
+bool
+qemuMigrationCapsGet(virDomainObjPtr vm,
+                     qemuMonitorMigrationCaps cap)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    bool enabled = false;
+
+    if (priv->migrationCaps)
+        ignore_value(virBitmapGetBit(priv->migrationCaps, cap, &enabled));
+
+    return enabled;
+}
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 63a4325624..f634138f4d 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -326,4 +326,8 @@ qemuMigrationFetchMirrorStats(virQEMUDriverPtr driver,
                               qemuDomainAsyncJob asyncJob,
                               qemuDomainJobInfoPtr jobInfo);
 
+bool
+qemuMigrationCapsGet(virDomainObjPtr vm,
+                     qemuMonitorMigrationCaps cap);
+
 #endif /* __QEMU_MIGRATION_H__ */
-- 
2.14.2

--
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