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