render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3e5111
From f4038af76b0b8b4f8fb7b4ea7e957a6eb0614ea5 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <f4038af76b0b8b4f8fb7b4ea7e957a6eb0614ea5@dist-git>
3e5111
From: Jiri Denemark <jdenemar@redhat.com>
3e5111
Date: Tue, 16 May 2017 13:26:54 +0200
3e5111
Subject: [PATCH] qemu: Remember CPU def from domain start
3e5111
3e5111
When starting a domain we update the guest CPU definition to match what
3e5111
QEMU actually provided (since it is allowed to add or removed some
3e5111
features unless check='full' is specified). Let's store the original CPU
3e5111
in domain private data so that we can use it to provide a backward
3e5111
compatible domain XML.
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
(cherry picked from commit ea6d89831198ae1854dca15b2bcf081df2d866a2)
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1441662
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/libvirt_private.syms |  2 ++
3e5111
 src/qemu/qemu_domain.c   |  7 +++++++
3e5111
 src/qemu/qemu_domain.h   |  4 ++++
3e5111
 src/qemu/qemu_process.c  | 13 +++++++++++--
3e5111
 4 files changed, 24 insertions(+), 2 deletions(-)
3e5111
3e5111
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
3e5111
index 88e3f4b8ac..8c088316c4 100644
3e5111
--- a/src/libvirt_private.syms
3e5111
+++ b/src/libvirt_private.syms
3e5111
@@ -76,9 +76,11 @@ virCPUDefCopyModelFilter;
3e5111
 virCPUDefCopyWithoutModel;
3e5111
 virCPUDefFormat;
3e5111
 virCPUDefFormatBuf;
3e5111
+virCPUDefFormatBufFull;
3e5111
 virCPUDefFree;
3e5111
 virCPUDefFreeFeatures;
3e5111
 virCPUDefFreeModel;
3e5111
+virCPUDefIsEqual;
3e5111
 virCPUDefParseXML;
3e5111
 virCPUDefStealModel;
3e5111
 virCPUDefUpdateFeature;
3e5111
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
3e5111
index 63fcde8024..89fd9f9abc 100644
3e5111
--- a/src/qemu/qemu_domain.c
3e5111
+++ b/src/qemu/qemu_domain.c
3e5111
@@ -1705,6 +1705,8 @@ qemuDomainObjPrivateFree(void *data)
3e5111
     VIR_FREE(priv->migTLSAlias);
3e5111
     qemuDomainMasterKeyFree(priv);
3e5111
 
3e5111
+    virCPUDefFree(priv->origCPU);
3e5111
+
3e5111
     VIR_FREE(priv);
3e5111
 }
3e5111
 
3e5111
@@ -1860,6 +1862,8 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf,
3e5111
     virBufferEscapeString(buf, "<channelTargetDir path='%s'/>\n",
3e5111
                           priv->channelTargetDir);
3e5111
 
3e5111
+    virCPUDefFormatBufFull(buf, priv->origCPU, NULL, false);
3e5111
+
3e5111
     return 0;
3e5111
 }
3e5111
 
3e5111
@@ -2128,6 +2132,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
3e5111
     if (qemuDomainSetPrivatePathsOld(driver, vm) < 0)
3e5111
         goto error;
3e5111
 
3e5111
+    if (virCPUDefParseXML(ctxt, "./cpu", VIR_CPU_TYPE_GUEST, &priv->origCPU) < 0)
3e5111
+        goto error;
3e5111
+
3e5111
     return 0;
3e5111
 
3e5111
  error:
3e5111
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
3e5111
index 80d80e4554..0c5dad60e1 100644
3e5111
--- a/src/qemu/qemu_domain.h
3e5111
+++ b/src/qemu/qemu_domain.h
3e5111
@@ -293,6 +293,10 @@ struct _qemuDomainObjPrivate {
3e5111
     /* Used when fetching/storing the current 'tls-creds' migration setting */
3e5111
     /* (not to be saved in our private XML). */
3e5111
     char *migTLSAlias;
3e5111
+
3e5111
+    /* CPU def used to start the domain when it differs from the one actually
3e5111
+     * provided by QEMU. */
3e5111
+    virCPUDefPtr origCPU;
3e5111
 };
3e5111
 
3e5111
 # define QEMU_DOMAIN_PRIVATE(vm)	\
3e5111
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
3e5111
index 7e51ca819a..79f780ed46 100644
3e5111
--- a/src/qemu/qemu_process.c
3e5111
+++ b/src/qemu/qemu_process.c
3e5111
@@ -3915,6 +3915,7 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver,
3e5111
     qemuDomainObjPrivatePtr priv = vm->privateData;
3e5111
     int rc;
3e5111
     int ret = -1;
3e5111
+    virCPUDefPtr orig = NULL;
3e5111
 
3e5111
     if (ARCH_IS_X86(def->os.arch)) {
3e5111
         if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
3e5111
@@ -3945,10 +3946,17 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver,
3e5111
         if (qemuProcessVerifyCPUFeatures(def, cpu) < 0)
3e5111
             goto cleanup;
3e5111
 
3e5111
-        if ((rc = virCPUUpdateLive(def->os.arch, def->cpu, cpu, disabled)) < 0)
3e5111
+        if (!(orig = virCPUDefCopy(def->cpu)))
3e5111
             goto cleanup;
3e5111
-        else if (rc == 0)
3e5111
+
3e5111
+        if ((rc = virCPUUpdateLive(def->os.arch, def->cpu, cpu, disabled)) < 0) {
3e5111
+            goto cleanup;
3e5111
+        } else if (rc == 0) {
3e5111
+            if (!virCPUDefIsEqual(def->cpu, orig, false))
3e5111
+                VIR_STEAL_PTR(priv->origCPU, orig);
3e5111
+
3e5111
             def->cpu->check = VIR_CPU_CHECK_FULL;
3e5111
+        }
3e5111
     }
3e5111
 
3e5111
     ret = 0;
3e5111
@@ -3956,6 +3964,7 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver,
3e5111
  cleanup:
3e5111
     virCPUDataFree(cpu);
3e5111
     virCPUDataFree(disabled);
3e5111
+    virCPUDefFree(orig);
3e5111
     return ret;
3e5111
 }
3e5111
 
3e5111
-- 
3e5111
2.13.1
3e5111