Blob Blame History Raw
From f047006a60d92f9c5e66ac9c2c532f8ac4c2ba28 Mon Sep 17 00:00:00 2001
Message-Id: <f047006a60d92f9c5e66ac9c2c532f8ac4c2ba28@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 21 Jun 2019 09:25:56 +0200
Subject: [PATCH] qemu: Translate feature names from query-cpu-model-expansion
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

By default query-cpu-model-expansion only reports canonical names of all
CPU features. We do some magic and call the command twice to get all
possible spellings of the features, but being able to consume canonical
names will allow us to drop this magic.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit ec232c5ddc3cc47651a815dcf4cff7cd31910b3e)

https://bugzilla.redhat.com/show_bug.cgi?id=1697627

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <5a50943665bc9df69bb99c25763f0b99a7364d8c.1561068591.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_capabilities.c | 19 +++++++++++--------
 src/qemu/qemu_capspriv.h     |  3 ++-
 tests/cputest.c              |  2 +-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index c48d66b39b..88c651ea7b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2868,11 +2868,12 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
     for (i = 0; i < modelInfo->nprops; i++) {
         virCPUFeatureDefPtr feature = cpu->features + cpu->nfeatures;
         qemuMonitorCPUPropertyPtr prop = modelInfo->props + i;
+        const char *name = virQEMUCapsCPUFeatureFromQEMU(qemuCaps, prop->name);
 
         if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN)
             continue;
 
-        if (VIR_STRDUP(feature->name, prop->name) < 0)
+        if (VIR_STRDUP(feature->name, name) < 0)
             return -1;
 
         if (!prop->value.boolean ||
@@ -2888,7 +2889,8 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
 
 
 virCPUDataPtr
-virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model,
+virQEMUCapsGetCPUModelX86Data(virQEMUCapsPtr qemuCaps,
+                              qemuMonitorCPUModelInfoPtr model,
                               bool migratable)
 {
     unsigned long long sigFamily = 0;
@@ -2903,6 +2905,7 @@ virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model,
 
     for (i = 0; i < model->nprops; i++) {
         qemuMonitorCPUPropertyPtr prop = model->props + i;
+        const char *name = virQEMUCapsCPUFeatureFromQEMU(qemuCaps, prop->name);
 
         switch (prop->type) {
         case QEMU_MONITOR_CPU_PROPERTY_BOOLEAN:
@@ -2910,23 +2913,23 @@ virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model,
                 (migratable && prop->migratable == VIR_TRISTATE_BOOL_NO))
                 continue;
 
-            if (virCPUx86DataAddFeature(data, prop->name) < 0)
+            if (virCPUx86DataAddFeature(data, name) < 0)
                 goto cleanup;
 
             break;
 
         case QEMU_MONITOR_CPU_PROPERTY_STRING:
-            if (STREQ(prop->name, "vendor") &&
+            if (STREQ(name, "vendor") &&
                 virCPUx86DataSetVendor(data, prop->value.string) < 0)
                 goto cleanup;
             break;
 
         case QEMU_MONITOR_CPU_PROPERTY_NUMBER:
-            if (STREQ(prop->name, "family"))
+            if (STREQ(name, "family"))
                 sigFamily = prop->value.number;
-            else if (STREQ(prop->name, "model"))
+            else if (STREQ(name, "model"))
                 sigModel = prop->value.number;
-            else if (STREQ(prop->name, "stepping"))
+            else if (STREQ(name, "stepping"))
                 sigStepping = prop->value.number;
             break;
 
@@ -2964,7 +2967,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
     if (!model)
         return 1;
 
-    if (!(data = virQEMUCapsGetCPUModelX86Data(model, migratable)))
+    if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable)))
         goto cleanup;
 
     if (cpuDecode(cpu, data, virQEMUCapsGetCPUDefinitions(qemuCaps, type)) < 0)
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index c3b7f934a9..b17deb01d7 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -85,7 +85,8 @@ virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
                            qemuMonitorCPUModelInfoPtr modelInfo);
 
 virCPUDataPtr
-virQEMUCapsGetCPUModelX86Data(qemuMonitorCPUModelInfoPtr model,
+virQEMUCapsGetCPUModelX86Data(virQEMUCapsPtr qemuCaps,
+                              qemuMonitorCPUModelInfoPtr model,
                               bool migratable);
 
 virCPUDefPtr
diff --git a/tests/cputest.c b/tests/cputest.c
index e62cda34b7..1ce50caccd 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -941,7 +941,7 @@ cpuTestJSONSignature(const void *arg)
         goto cleanup;
 
     modelInfo = virQEMUCapsGetCPUModelInfo(qemuCaps, VIR_DOMAIN_VIRT_KVM);
-    if (!(hostData = virQEMUCapsGetCPUModelX86Data(modelInfo, false)))
+    if (!(hostData = virQEMUCapsGetCPUModelX86Data(qemuCaps, modelInfo, false)))
         goto cleanup;
 
     ret = cpuTestCompareSignature(data, hostData);
-- 
2.22.0