[libvirt] [PATCH 2/2] qemu: Adapt to changed ppc64 CPU model names

Jiri Denemark jdenemar at redhat.com
Tue Oct 8 12:53:10 UTC 2019


QEMU 2.11 for ppc64 changed all CPU model names to lower case. Since
libvirt can't change the model names for compatibility reasons, we need
to translate the matching lower case models to the names known by
libvirt.

Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---
 src/qemu/qemu_capabilities.c                  | 26 +++++++++++++++++--
 src/qemu/qemu_capabilities.h                  |  3 ++-
 src/qemu/qemu_process.c                       |  2 +-
 .../qemu_2.12.0.ppc64.xml                     |  6 ++++-
 .../caps_2.12.0.ppc64.xml                     | 12 ++++-----
 .../qemucapabilitiesdata/caps_3.0.0.ppc64.xml | 12 ++++-----
 .../qemucapabilitiesdata/caps_3.1.0.ppc64.xml | 12 ++++-----
 .../qemucapabilitiesdata/caps_4.0.0.ppc64.xml | 12 ++++-----
 8 files changed, 56 insertions(+), 29 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 46a056340b..a340973f14 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2437,7 +2437,8 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
 
 
 virDomainCapsCPUModelsPtr
-virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon)
+virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
+                               virArch arch)
 {
     virDomainCapsCPUModelsPtr models = NULL;
     qemuMonitorCPUDefInfoPtr *cpus = NULL;
@@ -2447,6 +2448,27 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon)
     if ((ncpus = qemuMonitorGetCPUDefinitions(mon, &cpus)) < 0)
         return NULL;
 
+    /* QEMU 2.11 for Power renamed all CPU models to lower case, we need to
+     * translate them back to libvirt's upper case model names. */
+    if (ARCH_IS_PPC(arch)) {
+        VIR_AUTOSTRINGLIST libvirtModels = NULL;
+        char **name;
+
+        if (virCPUGetModels(arch, &libvirtModels) < 0)
+            goto error;
+
+        for (name = libvirtModels; name && *name; name++) {
+            for (i = 0; i < ncpus; i++) {
+                if (STRCASENEQ(cpus[i]->name, *name))
+                    continue;
+
+                VIR_FREE(cpus[i]->name);
+                if (VIR_STRDUP(cpus[i]->name, *name) < 0)
+                    goto error;
+            }
+        }
+    }
+
     if (!(models = virDomainCapsCPUModelsNew(ncpus)))
         goto error;
 
@@ -2486,7 +2508,7 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
     if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS))
         return 0;
 
-    if (!(models = virQEMUCapsFetchCPUDefinitions(mon)))
+    if (!(models = virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch)))
         return -1;
 
     if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 72da3691f2..6c77b9d943 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -567,7 +567,8 @@ int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
                                  virDomainCapsCPUUsable usable);
 virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
                                                        virDomainVirtType type);
-virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon);
+virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
+                                                         virArch arch);
 
 typedef enum {
     /* Host CPU definition reported in domain capabilities. */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index a50cd54393..7774a82972 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4379,7 +4379,7 @@ qemuProcessFetchCPUDefinitions(virQEMUDriverPtr driver,
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
         goto error;
 
-    models = virQEMUCapsFetchCPUDefinitions(priv->mon);
+    models = virQEMUCapsFetchCPUDefinitions(priv->mon, vm->def->os.arch);
 
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         goto error;
diff --git a/tests/domaincapsschemadata/qemu_2.12.0.ppc64.xml b/tests/domaincapsschemadata/qemu_2.12.0.ppc64.xml
index 99de2b0a8e..e8d3c22337 100644
--- a/tests/domaincapsschemadata/qemu_2.12.0.ppc64.xml
+++ b/tests/domaincapsschemadata/qemu_2.12.0.ppc64.xml
@@ -29,7 +29,11 @@
     <mode name='host-model' supported='yes'>
       <model fallback='allow'>POWER8</model>
     </mode>
-    <mode name='custom' supported='no'/>
+    <mode name='custom' supported='yes'>
+      <model usable='unknown'>POWER9</model>
+      <model usable='unknown'>POWER8</model>
+      <model usable='unknown'>POWER7</model>
+    </mode>
   </cpu>
   <devices>
     <disk supported='yes'>
diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml b/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml
index fd9ae0bcb8..ede28439cd 100644
--- a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml
@@ -163,12 +163,12 @@
   <cpu type='kvm' name='970mp'/>
   <cpu type='kvm' name='970fx'/>
   <cpu type='kvm' name='970'/>
-  <cpu type='kvm' name='power9'/>
+  <cpu type='kvm' name='POWER9'/>
   <cpu type='kvm' name='power8nvl'/>
-  <cpu type='kvm' name='power8'/>
+  <cpu type='kvm' name='POWER8'/>
   <cpu type='kvm' name='power8e'/>
   <cpu type='kvm' name='power7+'/>
-  <cpu type='kvm' name='power7'/>
+  <cpu type='kvm' name='POWER7'/>
   <cpu type='kvm' name='power5gs'/>
   <cpu type='kvm' name='power5+'/>
   <cpu type='kvm' name='apollo7pm'/>
@@ -601,12 +601,12 @@
   <cpu type='tcg' name='970mp'/>
   <cpu type='tcg' name='970fx'/>
   <cpu type='tcg' name='970'/>
-  <cpu type='tcg' name='power9'/>
+  <cpu type='tcg' name='POWER9'/>
   <cpu type='tcg' name='power8nvl'/>
-  <cpu type='tcg' name='power8'/>
+  <cpu type='tcg' name='POWER8'/>
   <cpu type='tcg' name='power8e'/>
   <cpu type='tcg' name='power7+'/>
-  <cpu type='tcg' name='power7'/>
+  <cpu type='tcg' name='POWER7'/>
   <cpu type='tcg' name='power5gs'/>
   <cpu type='tcg' name='power5+'/>
   <cpu type='tcg' name='apollo7pm'/>
diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml b/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml
index 61be1df782..221e0d1756 100644
--- a/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml
@@ -164,12 +164,12 @@
   <cpu type='kvm' name='970mp'/>
   <cpu type='kvm' name='970fx'/>
   <cpu type='kvm' name='970'/>
-  <cpu type='kvm' name='power9'/>
+  <cpu type='kvm' name='POWER9'/>
   <cpu type='kvm' name='power8nvl'/>
-  <cpu type='kvm' name='power8'/>
+  <cpu type='kvm' name='POWER8'/>
   <cpu type='kvm' name='power8e'/>
   <cpu type='kvm' name='power7+'/>
-  <cpu type='kvm' name='power7'/>
+  <cpu type='kvm' name='POWER7'/>
   <cpu type='kvm' name='power5gs'/>
   <cpu type='kvm' name='power5+'/>
   <cpu type='kvm' name='apollo7pm'/>
@@ -602,12 +602,12 @@
   <cpu type='tcg' name='970mp'/>
   <cpu type='tcg' name='970fx'/>
   <cpu type='tcg' name='970'/>
-  <cpu type='tcg' name='power9'/>
+  <cpu type='tcg' name='POWER9'/>
   <cpu type='tcg' name='power8nvl'/>
-  <cpu type='tcg' name='power8'/>
+  <cpu type='tcg' name='POWER8'/>
   <cpu type='tcg' name='power8e'/>
   <cpu type='tcg' name='power7+'/>
-  <cpu type='tcg' name='power7'/>
+  <cpu type='tcg' name='POWER7'/>
   <cpu type='tcg' name='power5gs'/>
   <cpu type='tcg' name='power5+'/>
   <cpu type='tcg' name='apollo7pm'/>
diff --git a/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml b/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml
index 400dc45be4..4685081945 100644
--- a/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml
@@ -166,12 +166,12 @@
   <cpu type='kvm' name='ppc'/>
   <cpu type='kvm' name='ppc32'/>
   <cpu type='kvm' name='ppc64'/>
-  <cpu type='kvm' name='power9'/>
+  <cpu type='kvm' name='POWER9'/>
   <cpu type='kvm' name='power8nvl'/>
-  <cpu type='kvm' name='power8'/>
+  <cpu type='kvm' name='POWER8'/>
   <cpu type='kvm' name='power8e'/>
   <cpu type='kvm' name='power7+'/>
-  <cpu type='kvm' name='power7'/>
+  <cpu type='kvm' name='POWER7'/>
   <cpu type='kvm' name='power5gs'/>
   <cpu type='kvm' name='power5+'/>
   <cpu type='kvm' name='970mp'/>
@@ -604,12 +604,12 @@
   <cpu type='tcg' name='ppc'/>
   <cpu type='tcg' name='ppc32'/>
   <cpu type='tcg' name='ppc64'/>
-  <cpu type='tcg' name='power9'/>
+  <cpu type='tcg' name='POWER9'/>
   <cpu type='tcg' name='power8nvl'/>
-  <cpu type='tcg' name='power8'/>
+  <cpu type='tcg' name='POWER8'/>
   <cpu type='tcg' name='power8e'/>
   <cpu type='tcg' name='power7+'/>
-  <cpu type='tcg' name='power7'/>
+  <cpu type='tcg' name='POWER7'/>
   <cpu type='tcg' name='power5gs'/>
   <cpu type='tcg' name='power5+'/>
   <cpu type='tcg' name='970mp'/>
diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml b/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml
index 9ea6f4d046..86e146effc 100644
--- a/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml
@@ -179,12 +179,12 @@
   <cpu type='kvm' name='ppc'/>
   <cpu type='kvm' name='ppc32'/>
   <cpu type='kvm' name='ppc64'/>
-  <cpu type='kvm' name='power9'/>
+  <cpu type='kvm' name='POWER9'/>
   <cpu type='kvm' name='power8nvl'/>
-  <cpu type='kvm' name='power8'/>
+  <cpu type='kvm' name='POWER8'/>
   <cpu type='kvm' name='power8e'/>
   <cpu type='kvm' name='power7+'/>
-  <cpu type='kvm' name='power7'/>
+  <cpu type='kvm' name='POWER7'/>
   <cpu type='kvm' name='power5gs'/>
   <cpu type='kvm' name='power5+'/>
   <cpu type='kvm' name='970mp'/>
@@ -617,12 +617,12 @@
   <cpu type='tcg' name='ppc'/>
   <cpu type='tcg' name='ppc32'/>
   <cpu type='tcg' name='ppc64'/>
-  <cpu type='tcg' name='power9'/>
+  <cpu type='tcg' name='POWER9'/>
   <cpu type='tcg' name='power8nvl'/>
-  <cpu type='tcg' name='power8'/>
+  <cpu type='tcg' name='POWER8'/>
   <cpu type='tcg' name='power8e'/>
   <cpu type='tcg' name='power7+'/>
-  <cpu type='tcg' name='power7'/>
+  <cpu type='tcg' name='POWER7'/>
   <cpu type='tcg' name='power5gs'/>
   <cpu type='tcg' name='power5+'/>
   <cpu type='tcg' name='970mp'/>
-- 
2.23.0




More information about the libvir-list mailing list