3e5111
From 5a76947526023484d27b6f43853602e6e0510063 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <5a76947526023484d27b6f43853602e6e0510063@dist-git>
3e5111
From: Jiri Denemark <jdenemar@redhat.com>
3e5111
Date: Wed, 14 Jun 2017 14:56:21 +0200
3e5111
Subject: [PATCH] qemu: Use qemuDomainCheckABIStability where needed
3e5111
3e5111
Most places which want to check ABI stability for an active domain need
3e5111
to call this API rather than the original
3e5111
qemuDomainDefCheckABIStability. The only exception is in snapshots where
3e5111
we need to decide what to do depending on the saved image data.
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1460952
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
(cherry picked from commit f0a3fe1b0a2996272dd167501bb5de752d9d1956)
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/qemu/qemu_driver.c    | 71 +++++++++++++++++++++++++++--------------------
3e5111
 src/qemu/qemu_migration.c |  2 +-
3e5111
 2 files changed, 42 insertions(+), 31 deletions(-)
3e5111
3e5111
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
3e5111
index 5567103c37..c7c5e28ca3 100644
3e5111
--- a/src/qemu/qemu_driver.c
3e5111
+++ b/src/qemu/qemu_driver.c
3e5111
@@ -3326,7 +3326,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDomainPtr dom,
3e5111
                                             VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) {
3e5111
             goto endjob;
3e5111
         }
3e5111
-        if (!qemuDomainDefCheckABIStability(driver, vm->def, def)) {
3e5111
+        if (!qemuDomainCheckABIStability(driver, vm, def)) {
3e5111
             virDomainDefFree(def);
3e5111
             goto endjob;
3e5111
         }
3e5111
@@ -15415,39 +15415,50 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
3e5111
          * to have finer control.  */
3e5111
         if (virDomainObjIsActive(vm)) {
3e5111
             /* Transitions 5, 6, 8, 9 */
3e5111
-            /* Replace the CPU in config and put the original one in priv
3e5111
-             * once we're done.
3e5111
-             */
3e5111
-            if (cookie && cookie->cpu && config->cpu) {
3e5111
-                origCPU = config->cpu;
3e5111
-                if (!(config->cpu = virCPUDefCopy(cookie->cpu)))
3e5111
-                    goto endjob;
3e5111
-            }
3e5111
-
3e5111
             /* Check for ABI compatibility. We need to do this check against
3e5111
              * the migratable XML or it will always fail otherwise */
3e5111
-            if (config &&
3e5111
-                !qemuDomainDefCheckABIStability(driver, vm->def, config)) {
3e5111
-                virErrorPtr err = virGetLastError();
3e5111
+            if (config) {
3e5111
+                bool compatible;
3e5111
 
3e5111
-                if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
3e5111
-                    /* Re-spawn error using correct category. */
3e5111
-                    if (err->code == VIR_ERR_CONFIG_UNSUPPORTED)
3e5111
-                        virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
3e5111
-                                       err->str2);
3e5111
-                    goto endjob;
3e5111
+                /* Replace the CPU in config and put the original one in priv
3e5111
+                 * once we're done. When we have the updated CPU def in the
3e5111
+                 * cookie, we don't want to replace the CPU in migratable def
3e5111
+                 * when doing ABI checks to make sure the current CPU exactly
3e5111
+                 * matches the one used at the time the snapshot was taken.
3e5111
+                 */
3e5111
+                if (cookie && cookie->cpu && config->cpu) {
3e5111
+                    origCPU = config->cpu;
3e5111
+                    if (!(config->cpu = virCPUDefCopy(cookie->cpu)))
3e5111
+                        goto endjob;
3e5111
+
3e5111
+                    compatible = qemuDomainDefCheckABIStability(driver, vm->def,
3e5111
+                                                                config);
3e5111
+                } else {
3e5111
+                    compatible = qemuDomainCheckABIStability(driver, vm, config);
3e5111
+                }
3e5111
+
3e5111
+                if (!compatible) {
3e5111
+                    virErrorPtr err = virGetLastError();
3e5111
+
3e5111
+                    if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)) {
3e5111
+                        /* Re-spawn error using correct category. */
3e5111
+                        if (err->code == VIR_ERR_CONFIG_UNSUPPORTED)
3e5111
+                            virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, "%s",
3e5111
+                                           err->str2);
3e5111
+                        goto endjob;
3e5111
+                    }
3e5111
+                    virResetError(err);
3e5111
+                    qemuProcessStop(driver, vm,
3e5111
+                                    VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT,
3e5111
+                                    QEMU_ASYNC_JOB_START, 0);
3e5111
+                    virDomainAuditStop(vm, "from-snapshot");
3e5111
+                    detail = VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT;
3e5111
+                    event = virDomainEventLifecycleNewFromObj(vm,
3e5111
+                                                     VIR_DOMAIN_EVENT_STOPPED,
3e5111
+                                                     detail);
3e5111
+                    qemuDomainEventQueue(driver, event);
3e5111
+                    goto load;
3e5111
                 }
3e5111
-                virResetError(err);
3e5111
-                qemuProcessStop(driver, vm,
3e5111
-                                VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT,
3e5111
-                                QEMU_ASYNC_JOB_START, 0);
3e5111
-                virDomainAuditStop(vm, "from-snapshot");
3e5111
-                detail = VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT;
3e5111
-                event = virDomainEventLifecycleNewFromObj(vm,
3e5111
-                                                 VIR_DOMAIN_EVENT_STOPPED,
3e5111
-                                                 detail);
3e5111
-                qemuDomainEventQueue(driver, event);
3e5111
-                goto load;
3e5111
             }
3e5111
 
3e5111
             priv = vm->privateData;
3e5111
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
3e5111
index a4540ce3c4..5eed933a3c 100644
3e5111
--- a/src/qemu/qemu_migration.c
3e5111
+++ b/src/qemu/qemu_migration.c
3e5111
@@ -2028,7 +2028,7 @@ qemuMigrationBeginPhase(virQEMUDriverPtr driver,
3e5111
                                             VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
3e5111
             goto cleanup;
3e5111
 
3e5111
-        if (!qemuDomainDefCheckABIStability(driver, vm->def, def))
3e5111
+        if (!qemuDomainCheckABIStability(driver, vm, def))
3e5111
             goto cleanup;
3e5111
 
3e5111
         rv = qemuDomainDefFormatLive(driver, def, NULL, false, true);
3e5111
-- 
3e5111
2.13.1
3e5111