This is required for virCPUBaseline to accept a list of guest CPU
definitions since they do not have arch set.

Signed-off-by: Jiri Denemark <jdene...@redhat.com>
---
 src/bhyve/bhyve_driver.c |  2 +-
 src/cpu/cpu.c            | 16 +++++++++++-----
 src/cpu/cpu.h            |  3 ++-
 src/libxl/libxl_driver.c |  2 +-
 src/qemu/qemu_driver.c   |  2 +-
 src/test/test_driver.c   |  2 +-
 src/vz/vz_driver.c       |  2 +-
 tests/cputest.c          |  2 +-
 8 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 72c51434c7..26047d31e2 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1398,7 +1398,7 @@ bhyveConnectBaselineCPU(virConnectPtr conn,
     if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
         goto cleanup;
 
-    if (!(cpu = virCPUBaseline(cpus, ncpus, NULL,
+    if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL,
                                !!(flags & 
VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
         goto cleanup;
 
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 81b93a991b..2c60d27b17 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -481,20 +481,22 @@ virCPUProbeHost(virArch arch)
 /**
  * virCPUBaseline:
  *
+ * @arch: CPU architecture, use VIR_ARCH_NONE to autodetect from @cpus
  * @cpus: list of host CPU definitions
  * @ncpus: number of CPUs in @cpus
  * @models: list of CPU models that can be considered for the baseline CPU
  * @migratable: requests non-migratable features to be removed from the result
  *
  * Computes the most feature-rich CPU which is compatible with all given
- * host CPUs. If @models is NULL, all models supported by libvirt will
+ * CPUs. If @models is NULL, all models supported by libvirt will
  * be considered when computing the baseline CPU model, otherwise the baseline
  * CPU model will be one of the provided CPU @models.
  *
  * Returns baseline CPU definition or NULL on error.
  */
 virCPUDefPtr
-virCPUBaseline(virCPUDefPtr *cpus,
+virCPUBaseline(virArch arch,
+               virCPUDefPtr *cpus,
                unsigned int ncpus,
                virDomainCapsCPUModelsPtr models,
                bool migratable)
@@ -502,7 +504,8 @@ virCPUBaseline(virCPUDefPtr *cpus,
     struct cpuArchDriver *driver;
     size_t i;
 
-    VIR_DEBUG("ncpus=%u, models=%p, migratable=%d", ncpus, models, migratable);
+    VIR_DEBUG("arch=%s, ncpus=%u, models=%p, migratable=%d",
+              virArchToString(arch), ncpus, models, migratable);
     if (cpus) {
         for (i = 0; i < ncpus; i++)
             VIR_DEBUG("cpus[%zu]=%p", i, cpus[i]);
@@ -536,13 +539,16 @@ virCPUBaseline(virCPUDefPtr *cpus,
         }
     }
 
-    if ((driver = cpuGetSubDriver(cpus[0]->arch)) == NULL)
+    if (arch == VIR_ARCH_NONE)
+        arch = cpus[0]->arch;
+
+    if ((driver = cpuGetSubDriver(arch)) == NULL)
         return NULL;
 
     if (driver->baseline == NULL) {
         virReportError(VIR_ERR_NO_SUPPORT,
                        _("cannot compute baseline CPU of %s architecture"),
-                       virArchToString(cpus[0]->arch));
+                       virArchToString(arch));
         return NULL;
     }
 
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 529068a618..8c45bf8b31 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -194,7 +194,8 @@ virCPUDefPtr
 virCPUProbeHost(virArch arch);
 
 virCPUDefPtr
-virCPUBaseline(virCPUDefPtr *cpus,
+virCPUBaseline(virArch arch,
+               virCPUDefPtr *cpus,
                unsigned int ncpus,
                virDomainCapsCPUModelsPtr models,
                bool migratable);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index e11969dca7..a85ce84404 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6349,7 +6349,7 @@ libxlConnectBaselineCPU(virConnectPtr conn,
     if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
         goto cleanup;
 
-    if (!(cpu = virCPUBaseline(cpus, ncpus, NULL,
+    if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL,
                                !!(flags & 
VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
         goto cleanup;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 17167129da..b95e1f5296 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13179,7 +13179,7 @@ qemuConnectBaselineCPU(virConnectPtr conn 
ATTRIBUTE_UNUSED,
     if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
         goto cleanup;
 
-    if (!(baseline = virCPUBaseline(cpus, ncpus, NULL,
+    if (!(baseline = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL,
                                     !!(flags & 
VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
         goto cleanup;
 
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index abb856a5b2..3b4acaf7fe 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1536,7 +1536,7 @@ testConnectBaselineCPU(virConnectPtr conn 
ATTRIBUTE_UNUSED,
     if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
         goto cleanup;
 
-    if (!(cpu = virCPUBaseline(cpus, ncpus, NULL, false)))
+    if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false)))
         goto cleanup;
 
     if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index d4cf2d5f62..50cd0acfdf 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -934,7 +934,7 @@ vzConnectBaselineCPU(virConnectPtr conn,
     if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
         goto cleanup;
 
-    if (!(cpu = virCPUBaseline(cpus, ncpus, NULL, false)))
+    if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false)))
         goto cleanup;
 
     if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
diff --git a/tests/cputest.c b/tests/cputest.c
index beb9afabdf..9b84ffea86 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -321,7 +321,7 @@ cpuTestBaseline(const void *arg)
     if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
         goto cleanup;
 
-    baseline = virCPUBaseline(cpus, ncpus, NULL,
+    baseline = virCPUBaseline(data->arch, cpus, ncpus, NULL,
                               !!(data->flags & 
VIR_CONNECT_BASELINE_CPU_MIGRATABLE));
 
     if (baseline &&
-- 
2.17.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to