9119d9
From 73d70735326d8577eadfbc97d9cf2217da3d8e69 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <73d70735326d8577eadfbc97d9cf2217da3d8e69@dist-git>
9119d9
From: Jiri Denemark <jdenemar@redhat.com>
9119d9
Date: Mon, 10 Nov 2014 14:46:26 +0100
9119d9
Subject: [PATCH] qemu: Always set migration capabilities
9119d9
9119d9
We used to set migration capabilities only when a user asked for them in
9119d9
flags. This is fine when migration succeeds since the QEMU process is
9119d9
killed in the end but in case migration fails or if it's cancelled, some
9119d9
capabilities may remain turned on with no way to turn them off. To fix
9119d9
that, migration capabilities have to be turned on if requested but
9119d9
explicitly turned off in case they were not requested but QEMU supports
9119d9
them.
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1163953
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
(cherry picked from commit ab393383c84eb049fc2d75c3e79249ca58062887)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/qemu/qemu_migration.c    | 42 +++++++++++++++++++++++++++++-------------
9119d9
 src/qemu/qemu_monitor.c      |  5 +++--
9119d9
 src/qemu/qemu_monitor.h      |  3 ++-
9119d9
 src/qemu/qemu_monitor_json.c |  5 +++--
9119d9
 src/qemu/qemu_monitor_json.h |  3 ++-
9119d9
 tests/qemumonitorjsontest.c  |  3 ++-
9119d9
 6 files changed, 41 insertions(+), 20 deletions(-)
9119d9
9119d9
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
9119d9
index d6c8553..7745d77 100644
9119d9
--- a/src/qemu/qemu_migration.c
9119d9
+++ b/src/qemu/qemu_migration.c
9119d9
@@ -1805,6 +1805,7 @@ qemuMigrationSetOffline(virQEMUDriverPtr driver,
9119d9
 static int
9119d9
 qemuMigrationSetCompression(virQEMUDriverPtr driver,
9119d9
                             virDomainObjPtr vm,
9119d9
+                            bool state,
9119d9
                             qemuDomainAsyncJob job)
9119d9
 {
9119d9
     qemuDomainObjPrivatePtr priv = vm->privateData;
9119d9
@@ -1819,6 +1820,9 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver,
9119d9
 
9119d9
     if (ret < 0) {
9119d9
         goto cleanup;
9119d9
+    } else if (ret == 0 && !state) {
9119d9
+        /* Unsupported but we want it off anyway */
9119d9
+        goto cleanup;
9119d9
     } else if (ret == 0) {
9119d9
         if (job == QEMU_ASYNC_JOB_MIGRATION_IN) {
9119d9
             virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
9119d9
@@ -1835,7 +1839,8 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver,
9119d9
 
9119d9
     ret = qemuMonitorSetMigrationCapability(
9119d9
                 priv->mon,
9119d9
-                QEMU_MONITOR_MIGRATION_CAPS_XBZRLE);
9119d9
+                QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
9119d9
+                state);
9119d9
 
9119d9
  cleanup:
9119d9
     qemuDomainObjExitMonitor(driver, vm);
9119d9
@@ -1845,6 +1850,7 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver,
9119d9
 static int
9119d9
 qemuMigrationSetAutoConverge(virQEMUDriverPtr driver,
9119d9
                              virDomainObjPtr vm,
9119d9
+                             bool state,
9119d9
                              qemuDomainAsyncJob job)
9119d9
 {
9119d9
     qemuDomainObjPrivatePtr priv = vm->privateData;
9119d9
@@ -1859,6 +1865,9 @@ qemuMigrationSetAutoConverge(virQEMUDriverPtr driver,
9119d9
 
9119d9
     if (ret < 0) {
9119d9
         goto cleanup;
9119d9
+    } else if (ret == 0 && !state) {
9119d9
+        /* Unsupported but we want it off anyway */
9119d9
+        goto cleanup;
9119d9
     } else if (ret == 0) {
9119d9
         virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
9119d9
                        _("Auto-Converge is not supported by "
9119d9
@@ -1869,7 +1878,8 @@ qemuMigrationSetAutoConverge(virQEMUDriverPtr driver,
9119d9
 
9119d9
     ret = qemuMonitorSetMigrationCapability(
9119d9
                 priv->mon,
9119d9
-                QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE);
9119d9
+                QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
9119d9
+                state);
9119d9
 
9119d9
  cleanup:
9119d9
     qemuDomainObjExitMonitor(driver, vm);
9119d9
@@ -1880,6 +1890,7 @@ qemuMigrationSetAutoConverge(virQEMUDriverPtr driver,
9119d9
 static int
9119d9
 qemuMigrationSetPinAll(virQEMUDriverPtr driver,
9119d9
                        virDomainObjPtr vm,
9119d9
+                       bool state,
9119d9
                        qemuDomainAsyncJob job)
9119d9
 {
9119d9
     qemuDomainObjPrivatePtr priv = vm->privateData;
9119d9
@@ -1894,6 +1905,9 @@ qemuMigrationSetPinAll(virQEMUDriverPtr driver,
9119d9
 
9119d9
     if (ret < 0) {
9119d9
         goto cleanup;
9119d9
+    } else if (ret == 0 && !state) {
9119d9
+        /* Unsupported but we want it off anyway */
9119d9
+        goto cleanup;
9119d9
     } else if (ret == 0) {
9119d9
         if (job == QEMU_ASYNC_JOB_MIGRATION_IN) {
9119d9
             virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
9119d9
@@ -1910,7 +1924,8 @@ qemuMigrationSetPinAll(virQEMUDriverPtr driver,
9119d9
 
9119d9
     ret = qemuMonitorSetMigrationCapability(
9119d9
                 priv->mon,
9119d9
-                QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL);
9119d9
+                QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
9119d9
+                state);
9119d9
 
9119d9
  cleanup:
9119d9
     qemuDomainObjExitMonitor(driver, vm);
9119d9
@@ -2745,8 +2760,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
9119d9
         dataFD[1] = -1; /* 'st' owns the FD now & will close it */
9119d9
     }
9119d9
 
9119d9
-    if (flags & VIR_MIGRATE_COMPRESSED &&
9119d9
-        qemuMigrationSetCompression(driver, vm,
9119d9
+    if (qemuMigrationSetCompression(driver, vm,
9119d9
+                                    flags & VIR_MIGRATE_COMPRESSED,
9119d9
                                     QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
9119d9
         goto stop;
9119d9
 
9119d9
@@ -2755,8 +2770,9 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
9119d9
         goto stop;
9119d9
     }
9119d9
 
9119d9
-    if (flags & VIR_MIGRATE_RDMA_PIN_ALL &&
9119d9
-        qemuMigrationSetPinAll(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
9119d9
+    if (qemuMigrationSetPinAll(driver, vm,
9119d9
+                               flags & VIR_MIGRATE_RDMA_PIN_ALL,
9119d9
+                               QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
9119d9
         goto stop;
9119d9
 
9119d9
     if (mig->lockState) {
9119d9
@@ -3573,18 +3589,18 @@ qemuMigrationRun(virQEMUDriverPtr driver,
9119d9
             goto cleanup;
9119d9
     }
9119d9
 
9119d9
-    if (flags & VIR_MIGRATE_COMPRESSED &&
9119d9
-        qemuMigrationSetCompression(driver, vm,
9119d9
+    if (qemuMigrationSetCompression(driver, vm,
9119d9
+                                    flags & VIR_MIGRATE_COMPRESSED,
9119d9
                                     QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
-    if (flags & VIR_MIGRATE_AUTO_CONVERGE &&
9119d9
-        qemuMigrationSetAutoConverge(driver, vm,
9119d9
+    if (qemuMigrationSetAutoConverge(driver, vm,
9119d9
+                                     flags & VIR_MIGRATE_AUTO_CONVERGE,
9119d9
                                      QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
-    if (flags & VIR_MIGRATE_RDMA_PIN_ALL &&
9119d9
-        qemuMigrationSetPinAll(driver, vm,
9119d9
+    if (qemuMigrationSetPinAll(driver, vm,
9119d9
+                               flags & VIR_MIGRATE_RDMA_PIN_ALL,
9119d9
                                QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
9119d9
index b516880..d2f0b46 100644
9119d9
--- a/src/qemu/qemu_monitor.c
9119d9
+++ b/src/qemu/qemu_monitor.c
9119d9
@@ -3907,7 +3907,8 @@ int qemuMonitorGetMigrationCapability(qemuMonitorPtr mon,
9119d9
 }
9119d9
 
9119d9
 int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
9119d9
-                                      qemuMonitorMigrationCaps capability)
9119d9
+                                      qemuMonitorMigrationCaps capability,
9119d9
+                                      bool state)
9119d9
 {
9119d9
     VIR_DEBUG("mon=%p capability=%d", mon, capability);
9119d9
 
9119d9
@@ -3923,7 +3924,7 @@ int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
9119d9
         return -1;
9119d9
     }
9119d9
 
9119d9
-    return qemuMonitorJSONSetMigrationCapability(mon, capability);
9119d9
+    return qemuMonitorJSONSetMigrationCapability(mon, capability, state);
9119d9
 }
9119d9
 
9119d9
 int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
9119d9
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
9119d9
index 69f41bf..70bb608 100644
9119d9
--- a/src/qemu/qemu_monitor.h
9119d9
+++ b/src/qemu/qemu_monitor.h
9119d9
@@ -506,7 +506,8 @@ int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
9119d9
 int qemuMonitorGetMigrationCapability(qemuMonitorPtr mon,
9119d9
                                       qemuMonitorMigrationCaps capability);
9119d9
 int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
9119d9
-                                      qemuMonitorMigrationCaps capability);
9119d9
+                                      qemuMonitorMigrationCaps capability,
9119d9
+                                      bool state);
9119d9
 
9119d9
 typedef enum {
9119d9
   QEMU_MONITOR_MIGRATE_BACKGROUND	= 1 << 0,
9119d9
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
9119d9
index 4fb1d81..f1f65ea 100644
9119d9
--- a/src/qemu/qemu_monitor_json.c
9119d9
+++ b/src/qemu/qemu_monitor_json.c
9119d9
@@ -5731,7 +5731,8 @@ qemuMonitorJSONGetMigrationCapability(qemuMonitorPtr mon,
9119d9
 
9119d9
 int
9119d9
 qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
9119d9
-                                      qemuMonitorMigrationCaps capability)
9119d9
+                                      qemuMonitorMigrationCaps capability,
9119d9
+                                      bool state)
9119d9
 {
9119d9
     int ret = -1;
9119d9
 
9119d9
@@ -5751,7 +5752,7 @@ qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
9119d9
                 qemuMonitorMigrationCapsTypeToString(capability)) < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
-    if (virJSONValueObjectAppendBoolean(cap, "state", 1) < 0)
9119d9
+    if (virJSONValueObjectAppendBoolean(cap, "state", state) < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
     if (virJSONValueArrayAppend(caps, cap) < 0)
9119d9
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
9119d9
index 8d88c6d..97397fe 100644
9119d9
--- a/src/qemu/qemu_monitor_json.h
9119d9
+++ b/src/qemu/qemu_monitor_json.h
9119d9
@@ -142,7 +142,8 @@ int qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
9119d9
 int qemuMonitorJSONGetMigrationCapability(qemuMonitorPtr mon,
9119d9
                                           qemuMonitorMigrationCaps capability);
9119d9
 int qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
9119d9
-                                          qemuMonitorMigrationCaps capability);
9119d9
+                                          qemuMonitorMigrationCaps capability,
9119d9
+                                          bool state);
9119d9
 
9119d9
 int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
9119d9
                            unsigned int flags,
9119d9
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
9119d9
index d53ab05..f7b7ea5 100644
9119d9
--- a/tests/qemumonitorjsontest.c
9119d9
+++ b/tests/qemumonitorjsontest.c
9119d9
@@ -1939,7 +1939,8 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapability(const void *data)
9119d9
     }
9119d9
 
9119d9
     if (qemuMonitorJSONSetMigrationCapability(qemuMonitorTestGetMonitor(test),
9119d9
-                                              QEMU_MONITOR_MIGRATION_CAPS_XBZRLE) < 0)
9119d9
+                                              QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
9119d9
+                                              true) < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
     ret = 0;
9119d9
-- 
9119d9
2.1.3
9119d9