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