a41c76
From 37b27a297ecb87e65f41c212aaabde7311b042d6 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <37b27a297ecb87e65f41c212aaabde7311b042d6@dist-git>
a41c76
From: Jiri Denemark <jdenemar@redhat.com>
a41c76
Date: Thu, 20 Feb 2020 09:08:05 +0100
a41c76
Subject: [PATCH] cpu_conf: Format vendor_id for host-model CPUs
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
In commit v5.9.0-400-gaf8e39921a I removed printing model's fallback and
a41c76
vendor_id attributes when no model is specified. However, vendor_id
a41c76
makes sense even without a specific CPU model (for host-model CPUs).
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1804549
a41c76
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 0905f222f1bfd9d741e94a8d653e05bb174846d3)
a41c76
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a41c76
Message-Id: <0b46ae9e26d1c7dbaa7f2dd58fd1156db237a853.1582186015.git.jdenemar@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/conf/cpu_conf.c                                | 14 +++++++++-----
a41c76
 tests/qemuxml2xmloutdata/cpu-host-model-vendor.xml |  4 +++-
a41c76
 2 files changed, 12 insertions(+), 6 deletions(-)
a41c76
a41c76
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
a41c76
index 837d77581c..1a2948ce11 100644
a41c76
--- a/src/conf/cpu_conf.c
a41c76
+++ b/src/conf/cpu_conf.c
a41c76
@@ -791,10 +791,10 @@ virCPUDefFormatBuf(virBufferPtr buf,
a41c76
         return -1;
a41c76
     }
a41c76
 
a41c76
-    if (formatModel && def->model) {
a41c76
+    if (formatModel && (def->model || def->vendor_id)) {
a41c76
         virBufferAddLit(buf, "
a41c76
 
a41c76
-        if (def->type == VIR_CPU_TYPE_GUEST) {
a41c76
+        if (def->type == VIR_CPU_TYPE_GUEST && def->model) {
a41c76
             const char *fallback;
a41c76
 
a41c76
             fallback = virCPUFallbackTypeToString(def->fallback);
a41c76
@@ -805,11 +805,15 @@ virCPUDefFormatBuf(virBufferPtr buf,
a41c76
                 return -1;
a41c76
             }
a41c76
             virBufferAsprintf(buf, " fallback='%s'", fallback);
a41c76
-            if (def->vendor_id)
a41c76
-                virBufferEscapeString(buf, " vendor_id='%s'", def->vendor_id);
a41c76
         }
a41c76
 
a41c76
-        virBufferEscapeString(buf, ">%s</model>\n", def->model);
a41c76
+        if (def->type == VIR_CPU_TYPE_GUEST)
a41c76
+            virBufferEscapeString(buf, " vendor_id='%s'", def->vendor_id);
a41c76
+
a41c76
+        if (def->model)
a41c76
+            virBufferEscapeString(buf, ">%s</model>\n", def->model);
a41c76
+        else
a41c76
+            virBufferAddLit(buf, "/>\n");
a41c76
     }
a41c76
 
a41c76
     if (formatModel && def->vendor)
a41c76
diff --git a/tests/qemuxml2xmloutdata/cpu-host-model-vendor.xml b/tests/qemuxml2xmloutdata/cpu-host-model-vendor.xml
a41c76
index d2447ccd10..2a7d0246cc 100644
a41c76
--- a/tests/qemuxml2xmloutdata/cpu-host-model-vendor.xml
a41c76
+++ b/tests/qemuxml2xmloutdata/cpu-host-model-vendor.xml
a41c76
@@ -8,7 +8,9 @@
a41c76
     <type arch='x86_64' machine='pc'>hvm</type>
a41c76
     <boot dev='network'/>
a41c76
   </os>
a41c76
-  <cpu mode='host-model' check='partial'/>
a41c76
+  <cpu mode='host-model' check='partial'>
a41c76
+    <model vendor_id='Libvirt QEMU'/>
a41c76
+  </cpu>
a41c76
   <clock offset='utc'/>
a41c76
   <on_poweroff>destroy</on_poweroff>
a41c76
   <on_reboot>restart</on_reboot>
a41c76
-- 
a41c76
2.25.0
a41c76