[libvirt PATCH 09/11] qemu_capabilities: Translate CPU blockers

Jiri Denemark jdenemar at redhat.com
Tue Oct 4 14:28:52 UTC 2022


The list of features reported by QEMU as blocking a particular CPU model
on the current host cannot be directly used by libvirt (or its users) as
QEMU uses different names for some features. We need to translate them
before using them or presenting them to users.

Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---
 src/qemu/qemu_capabilities.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 8e8a84e614..a19622c878 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3907,7 +3907,8 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *caps,
 
 
 static int
-virQEMUCapsLoadCPUModels(virQEMUCapsAccel *caps,
+virQEMUCapsLoadCPUModels(virArch arch,
+                         virQEMUCapsAccel *caps,
                          xmlXPathContextPtr ctxt,
                          const char *typeStr)
 {
@@ -3972,12 +3973,16 @@ virQEMUCapsLoadCPUModels(virQEMUCapsAccel *caps,
             cpu->blockers = g_new0(char *, nblockers + 1);
 
             for (j = 0; j < nblockers; j++) {
-                if (!(cpu->blockers[j] = virXMLPropString(blockerNodes[j], "name"))) {
+                g_autofree char *blocker = NULL;
+
+                if (!(blocker = virXMLPropString(blockerNodes[j], "name"))) {
                     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                    _("missing blocker name in QEMU "
                                      "capabilities cache"));
                     return -1;
                 }
+
+                cpu->blockers[j] = g_strdup(virQEMUCapsCPUFeatureFromQEMU(arch, blocker));
             }
         }
 
@@ -4072,7 +4077,7 @@ virQEMUCapsLoadAccel(virQEMUCaps *qemuCaps,
     if (virQEMUCapsLoadHostCPUModelInfo(caps, ctxt, typeStr) < 0)
         return -1;
 
-    if (virQEMUCapsLoadCPUModels(caps, ctxt, typeStr) < 0)
+    if (virQEMUCapsLoadCPUModels(qemuCaps->arch, caps, ctxt, typeStr) < 0)
         return -1;
 
     if (virQEMUCapsLoadMachines(caps, ctxt, typeStr) < 0)
@@ -4547,7 +4552,8 @@ virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsAccel *caps,
 
 
 static void
-virQEMUCapsFormatCPUModels(virQEMUCapsAccel *caps,
+virQEMUCapsFormatCPUModels(virArch arch,
+                           virQEMUCapsAccel *caps,
                            virBuffer *buf,
                            const char *typeStr)
 {
@@ -4576,8 +4582,10 @@ virQEMUCapsFormatCPUModels(virQEMUCapsAccel *caps,
             virBufferAddLit(buf, ">\n");
             virBufferAdjustIndent(buf, 2);
 
-            for (j = 0; cpu->blockers[j]; j++)
-                virBufferAsprintf(buf, "<blocker name='%s'/>\n", cpu->blockers[j]);
+            for (j = 0; cpu->blockers[j]; j++) {
+                virBufferAsprintf(buf, "<blocker name='%s'/>\n",
+                                  virQEMUCapsCPUFeatureToQEMU(arch, cpu->blockers[j]));
+            }
 
             virBufferAdjustIndent(buf, -2);
             virBufferAddLit(buf, "</cpu>\n");
@@ -4629,7 +4637,7 @@ virQEMUCapsFormatAccel(virQEMUCaps *qemuCaps,
     const char *typeStr = virQEMUCapsAccelStr(type);
 
     virQEMUCapsFormatHostCPUModelInfo(caps, buf, typeStr);
-    virQEMUCapsFormatCPUModels(caps, buf, typeStr);
+    virQEMUCapsFormatCPUModels(qemuCaps->arch, caps, buf, typeStr);
     virQEMUCapsFormatMachines(caps, buf, typeStr);
 
 }
-- 
2.37.3



More information about the libvir-list mailing list