render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
3e5111
From 9281d9a8d447e8b066cc600f1dcca7775920f01e Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <9281d9a8d447e8b066cc600f1dcca7775920f01e@dist-git>
3e5111
From: Jiri Denemark <jdenemar@redhat.com>
3e5111
Date: Fri, 19 May 2017 15:20:31 +0200
3e5111
Subject: [PATCH] qemu: Report the original CPU in migratable xml
3e5111
3e5111
The destination host may not be able to start a domain using the live
3e5111
updated CPU definition because either libvirt or QEMU may not be new
3e5111
enough. Thus we need to send the original guest CPU definition.
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
(cherry picked from commit 356a2161e293eaab57448a8e68f489e0841efe19)
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1441662
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/qemu/qemu_domain.c    | 61 ++++++++++++++++++++++++++++++++++++++---------
3e5111
 src/qemu/qemu_domain.h    |  1 +
3e5111
 src/qemu/qemu_driver.c    | 13 ++++++----
3e5111
 src/qemu/qemu_migration.c |  5 ++--
3e5111
 4 files changed, 63 insertions(+), 17 deletions(-)
3e5111
3e5111
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
3e5111
index 89fd9f9abc..514b56b33c 100644
3e5111
--- a/src/qemu/qemu_domain.c
3e5111
+++ b/src/qemu/qemu_domain.c
3e5111
@@ -4175,11 +4175,13 @@ qemuDomainDefCopy(virQEMUDriverPtr driver,
3e5111
     return ret;
3e5111
 }
3e5111
 
3e5111
-int
3e5111
-qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
3e5111
-                       virDomainDefPtr def,
3e5111
-                       unsigned int flags,
3e5111
-                       virBuffer *buf)
3e5111
+
3e5111
+static int
3e5111
+qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
3e5111
+                               virDomainDefPtr def,
3e5111
+                               virCPUDefPtr origCPU,
3e5111
+                               unsigned int flags,
3e5111
+                               virBuffer *buf)
3e5111
 {
3e5111
     int ret = -1;
3e5111
     virDomainDefPtr copy = NULL;
3e5111
@@ -4300,6 +4302,16 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
3e5111
             if (qemuDomainChrDefDropDefaultPath(def->channels[i], driver) < 0)
3e5111
                 goto cleanup;
3e5111
         }
3e5111
+
3e5111
+        /* Replace the CPU definition updated according to QEMU with the one
3e5111
+         * used for starting the domain. The updated def will be sent
3e5111
+         * separately for backward compatibility.
3e5111
+         */
3e5111
+        if (origCPU) {
3e5111
+            virCPUDefFree(def->cpu);
3e5111
+            if (!(def->cpu = virCPUDefCopy(origCPU)))
3e5111
+                goto cleanup;
3e5111
+        }
3e5111
     }
3e5111
 
3e5111
  format:
3e5111
@@ -4313,13 +4325,26 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
3e5111
     return ret;
3e5111
 }
3e5111
 
3e5111
-char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
3e5111
-                             virDomainDefPtr def,
3e5111
-                             unsigned int flags)
3e5111
+
3e5111
+int
3e5111
+qemuDomainDefFormatBuf(virQEMUDriverPtr driver,
3e5111
+                       virDomainDefPtr def,
3e5111
+                       unsigned int flags,
3e5111
+                       virBufferPtr buf)
3e5111
+{
3e5111
+    return qemuDomainDefFormatBufInternal(driver, def, NULL, flags, buf);
3e5111
+}
3e5111
+
3e5111
+
3e5111
+static char *
3e5111
+qemuDomainDefFormatXMLInternal(virQEMUDriverPtr driver,
3e5111
+                               virDomainDefPtr def,
3e5111
+                               virCPUDefPtr origCPU,
3e5111
+                               unsigned int flags)
3e5111
 {
3e5111
     virBuffer buf = VIR_BUFFER_INITIALIZER;
3e5111
 
3e5111
-    if (qemuDomainDefFormatBuf(driver, def, flags, &buf) < 0) {
3e5111
+    if (qemuDomainDefFormatBufInternal(driver, def, origCPU, flags, &buf) < 0) {
3e5111
         virBufferFreeAndReset(&buf;;
3e5111
         return NULL;
3e5111
     }
3e5111
@@ -4333,26 +4358,40 @@ char *qemuDomainDefFormatXML(virQEMUDriverPtr driver,
3e5111
     return virBufferContentAndReset(&buf;;
3e5111
 }
3e5111
 
3e5111
+
3e5111
+char *
3e5111
+qemuDomainDefFormatXML(virQEMUDriverPtr driver,
3e5111
+                       virDomainDefPtr def,
3e5111
+                       unsigned int flags)
3e5111
+{
3e5111
+    return qemuDomainDefFormatXMLInternal(driver, def, NULL, flags);
3e5111
+}
3e5111
+
3e5111
+
3e5111
 char *qemuDomainFormatXML(virQEMUDriverPtr driver,
3e5111
                           virDomainObjPtr vm,
3e5111
                           unsigned int flags)
3e5111
 {
3e5111
     virDomainDefPtr def;
3e5111
+    qemuDomainObjPrivatePtr priv = vm->privateData;
3e5111
+    virCPUDefPtr origCPU = NULL;
3e5111
 
3e5111
     if ((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef) {
3e5111
         def = vm->newDef;
3e5111
     } else {
3e5111
         def = vm->def;
3e5111
+        origCPU = priv->origCPU;
3e5111
         if (virDomainObjIsActive(vm))
3e5111
             flags &= ~VIR_DOMAIN_XML_UPDATE_CPU;
3e5111
     }
3e5111
 
3e5111
-    return qemuDomainDefFormatXML(driver, def, flags);
3e5111
+    return qemuDomainDefFormatXMLInternal(driver, def, origCPU, flags);
3e5111
 }
3e5111
 
3e5111
 char *
3e5111
 qemuDomainDefFormatLive(virQEMUDriverPtr driver,
3e5111
                         virDomainDefPtr def,
3e5111
+                        virCPUDefPtr origCPU,
3e5111
                         bool inactive,
3e5111
                         bool compatible)
3e5111
 {
3e5111
@@ -4363,7 +4402,7 @@ qemuDomainDefFormatLive(virQEMUDriverPtr driver,
3e5111
     if (compatible)
3e5111
         flags |= VIR_DOMAIN_XML_MIGRATABLE;
3e5111
 
3e5111
-    return qemuDomainDefFormatXML(driver, def, flags);
3e5111
+    return qemuDomainDefFormatXMLInternal(driver, def, origCPU, flags);
3e5111
 }
3e5111
 
3e5111
 
3e5111
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
3e5111
index 0c5dad60e1..9567458849 100644
3e5111
--- a/src/qemu/qemu_domain.h
3e5111
+++ b/src/qemu/qemu_domain.h
3e5111
@@ -515,6 +515,7 @@ char *qemuDomainFormatXML(virQEMUDriverPtr driver,
3e5111
 
3e5111
 char *qemuDomainDefFormatLive(virQEMUDriverPtr driver,
3e5111
                               virDomainDefPtr def,
3e5111
+                              virCPUDefPtr origCPU,
3e5111
                               bool inactive,
3e5111
                               bool compatible);
3e5111
 
3e5111
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
3e5111
index dbb1ea9475..f5c5c302be 100644
3e5111
--- a/src/qemu/qemu_driver.c
3e5111
+++ b/src/qemu/qemu_driver.c
3e5111
@@ -3330,9 +3330,9 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDomainPtr dom,
3e5111
             virDomainDefFree(def);
3e5111
             goto endjob;
3e5111
         }
3e5111
-        xml = qemuDomainDefFormatLive(driver, def, true, true);
3e5111
+        xml = qemuDomainDefFormatLive(driver, def, NULL, true, true);
3e5111
     } else {
3e5111
-        xml = qemuDomainDefFormatLive(driver, vm->def, true, true);
3e5111
+        xml = qemuDomainDefFormatLive(driver, vm->def, priv->origCPU, true, true);
3e5111
     }
3e5111
     if (!xml) {
3e5111
         virReportError(VIR_ERR_OPERATION_FAILED,
3e5111
@@ -14512,7 +14512,8 @@ qemuDomainSnapshotCreateActiveExternal(virConnectPtr conn,
3e5111
                                                     "snapshot", false)) < 0)
3e5111
             goto cleanup;
3e5111
 
3e5111
-        if (!(xml = qemuDomainDefFormatLive(driver, vm->def, true, true)) ||
3e5111
+        if (!(xml = qemuDomainDefFormatLive(driver, vm->def, priv->origCPU,
3e5111
+                                            true, true)) ||
3e5111
             !(snap->def->cookie = (virObjectPtr) qemuDomainSaveCookieNew(vm)))
3e5111
             goto cleanup;
3e5111
 
3e5111
@@ -14623,6 +14624,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
3e5111
     bool align_match = true;
3e5111
     virQEMUDriverConfigPtr cfg = NULL;
3e5111
     virCapsPtr caps = NULL;
3e5111
+    qemuDomainObjPrivatePtr priv;
3e5111
 
3e5111
     virCheckFlags(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE |
3e5111
                   VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT |
3e5111
@@ -14740,6 +14742,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
3e5111
 
3e5111
     qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE);
3e5111
 
3e5111
+    priv = vm->privateData;
3e5111
+
3e5111
     if (redefine) {
3e5111
         if (virDomainSnapshotRedefinePrep(domain, vm, &def, &snap,
3e5111
                                           driver->xmlopt,
3e5111
@@ -14748,7 +14752,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
3e5111
     } else {
3e5111
         /* Easiest way to clone inactive portion of vm->def is via
3e5111
          * conversion in and back out of xml.  */
3e5111
-        if (!(xml = qemuDomainDefFormatLive(driver, vm->def, true, true)) ||
3e5111
+        if (!(xml = qemuDomainDefFormatLive(driver, vm->def, priv->origCPU,
3e5111
+                                            true, true)) ||
3e5111
             !(def->dom = virDomainDefParseString(xml, caps, driver->xmlopt, NULL,
3e5111
                                                  VIR_DOMAIN_DEF_PARSE_INACTIVE |
3e5111
                                                  VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
3e5111
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
3e5111
index 5bf9bd10f7..ec5af7a612 100644
3e5111
--- a/src/qemu/qemu_migration.c
3e5111
+++ b/src/qemu/qemu_migration.c
3e5111
@@ -2028,9 +2028,10 @@ qemuMigrationBeginPhase(virQEMUDriverPtr driver,
3e5111
         if (!qemuDomainDefCheckABIStability(driver, vm->def, def))
3e5111
             goto cleanup;
3e5111
 
3e5111
-        rv = qemuDomainDefFormatLive(driver, def, false, true);
3e5111
+        rv = qemuDomainDefFormatLive(driver, def, NULL, false, true);
3e5111
     } else {
3e5111
-        rv = qemuDomainDefFormatLive(driver, vm->def, false, true);
3e5111
+        rv = qemuDomainDefFormatLive(driver, vm->def, priv->origCPU,
3e5111
+                                     false, true);
3e5111
     }
3e5111
 
3e5111
  cleanup:
3e5111
-- 
3e5111
2.13.1
3e5111