The implementation of virConnectBaselineCPU may be different for each
hypervisor. Thus it shouldn't really be implmented in the cpu code.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/bhyve/bhyve_driver.c | 22 +++++++++++++++---
src/cpu/cpu.c | 58 ------------------------------------------------
src/cpu/cpu.h | 7 ------
src/libvirt_private.syms | 1 -
src/libxl/libxl_driver.c | 22 +++++++++++++++---
src/qemu/qemu_driver.c | 22 +++++++++++++++---
src/test/test_driver.c | 22 +++++++++++++++---
src/vz/vz_driver.c | 22 +++++++++++++++++-
8 files changed, 97 insertions(+), 79 deletions(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 3bcff88975..e8241f39ff 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1420,7 +1420,9 @@ bhyveConnectBaselineCPU(virConnectPtr conn,
unsigned int ncpus,
unsigned int flags)
{
- char *cpu = NULL;
+ virCPUDefPtr *cpus = NULL;
+ virCPUDefPtr cpu = NULL;
+ char *cpustr = NULL;
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES |
VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL);
@@ -1428,10 +1430,24 @@ bhyveConnectBaselineCPU(virConnectPtr conn,
if (virConnectBaselineCPUEnsureACL(conn) < 0)
goto cleanup;
- cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0, flags);
+ if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
+ goto cleanup;
+
+ if (!(cpu = cpuBaseline(cpus, ncpus, NULL, 0,
+ !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
+ goto cleanup;
+
+ if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
+ virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
+ goto cleanup;
+
+ cpustr = virCPUDefFormat(cpu, NULL, false);
cleanup:
- return cpu;
+ virCPUDefListFree(cpus);
+ virCPUDefFree(cpu);
+
+ return cpustr;
}
static int
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index e75f406040..a7c7c381b9 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -495,64 +495,6 @@ virCPUProbeHost(virArch arch)
}
-/**
- * cpuBaselineXML:
- *
- * @xmlCPUs: list of host CPU XML descriptions
- * @ncpus: number of CPUs in @xmlCPUs
- * @models: list of CPU models that can be considered for the baseline CPU
- * @nmodels: number of CPU models in @models
- * @flags: bitwise-OR of virConnectBaselineCPUFlags
- *
- * Computes the most feature-rich CPU which is compatible with all given
- * host CPUs. If @models array 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.
- *
- * If @flags includes VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES then libvirt
- * will explicitly list all CPU features that are part of the host CPU,
- * without this flag features that are part of the CPU model will not be
- * listed.
- *
- * Returns XML description of the baseline CPU or NULL on error.
- */
-char *
-cpuBaselineXML(const char **xmlCPUs,
- unsigned int ncpus,
- const char **models,
- unsigned int nmodels,
- unsigned int flags)
-{
- virCPUDefPtr *cpus = NULL;
- virCPUDefPtr cpu = NULL;
- char *cpustr = NULL;
-
- VIR_DEBUG("ncpus=%u, nmodels=%u", ncpus, nmodels);
-
- virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES |
- VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL);
-
- if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
- goto cleanup;
-
- if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels,
- !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
- goto cleanup;
-
- if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
- virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
- goto cleanup;
-
- cpustr = virCPUDefFormat(cpu, NULL, false);
-
- cleanup:
- virCPUDefListFree(cpus);
- virCPUDefFree(cpu);
-
- return cpustr;
-}
-
-
/**
* cpuBaseline:
*
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index c6ca111e97..5dda46ee70 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -196,13 +196,6 @@ virCPUGetHost(virArch arch,
virCPUDefPtr
virCPUProbeHost(virArch arch);
-char *
-cpuBaselineXML(const char **xmlCPUs,
- unsigned int ncpus,
- const char **models,
- unsigned int nmodels,
- unsigned int flags);
-
virCPUDefPtr
cpuBaseline (virCPUDefPtr *cpus,
unsigned int ncpus,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 857e417f94..888e4e329b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1077,7 +1077,6 @@ virStoragePoolObjVolumeListExport;
# cpu/cpu.h
cpuBaseline;
-cpuBaselineXML;
cpuDecode;
cpuEncode;
virCPUCheckFeature;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 8fefce6631..4861e5db21 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6450,7 +6450,9 @@ libxlConnectBaselineCPU(virConnectPtr conn,
unsigned int ncpus,
unsigned int flags)
{
- char *cpu = NULL;
+ virCPUDefPtr *cpus = NULL;
+ virCPUDefPtr cpu = NULL;
+ char *cpustr = NULL;
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES |
VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL);
@@ -6458,10 +6460,24 @@ libxlConnectBaselineCPU(virConnectPtr conn,
if (virConnectBaselineCPUEnsureACL(conn) < 0)
goto cleanup;
- cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0, flags);
+ if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
+ goto cleanup;
+
+ if (!(cpu = cpuBaseline(cpus, ncpus, NULL, 0,
+ !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
+ goto cleanup;
+
+ if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
+ virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
+ goto cleanup;
+
+ cpustr = virCPUDefFormat(cpu, NULL, false);
cleanup:
- return cpu;
+ virCPUDefListFree(cpus);
+ virCPUDefFree(cpu);
+
+ return cpustr;
}
static virHypervisorDriver libxlHypervisorDriver = {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b334cf20be..e92c114f3e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12989,7 +12989,9 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
unsigned int ncpus,
unsigned int flags)
{
- char *cpu = NULL;
+ virCPUDefPtr *cpus = NULL;
+ virCPUDefPtr cpu = NULL;
+ char *cpustr = NULL;
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES |
VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL);
@@ -12997,10 +12999,24 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
if (virConnectBaselineCPUEnsureACL(conn) < 0)
goto cleanup;
- cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0, flags);
+ if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
+ goto cleanup;
+
+ if (!(cpu = cpuBaseline(cpus, ncpus, NULL, 0,
+ !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
+ goto cleanup;
+
+ if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
+ virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
+ goto cleanup;
+
+ cpustr = virCPUDefFormat(cpu, NULL, false);
cleanup:
- return cpu;
+ virCPUDefListFree(cpus);
+ virCPUDefFree(cpu);
+
+ return cpustr;
}
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index aa38f54dd9..6e8a4b5782 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1535,13 +1535,29 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
unsigned int ncpus,
unsigned int flags)
{
- char *cpu;
+ virCPUDefPtr *cpus = NULL;
+ virCPUDefPtr cpu = NULL;
+ char *cpustr = NULL;
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, NULL);
- cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0, flags);
+ if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
+ goto cleanup;
- return cpu;
+ if (!(cpu = cpuBaseline(cpus, ncpus, NULL, 0, false)))
+ goto cleanup;
+
+ if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
+ virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
+ goto cleanup;
+
+ cpustr = virCPUDefFormat(cpu, NULL, false);
+
+ cleanup:
+ virCPUDefListFree(cpus);
+ virCPUDefFree(cpu);
+
+ return cpustr;
}
static int testNodeGetInfo(virConnectPtr conn,
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 6f4aee3652..daeed5f114 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -945,12 +945,32 @@ vzConnectBaselineCPU(virConnectPtr conn,
unsigned int ncpus,
unsigned int flags)
{
+ virCPUDefPtr *cpus = NULL;
+ virCPUDefPtr cpu = NULL;
+ char *cpustr = NULL;
+
virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, NULL);
if (virConnectBaselineCPUEnsureACL(conn) < 0)
return NULL;
- return cpuBaselineXML(xmlCPUs, ncpus, NULL, 0, flags);
+ if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
+ goto cleanup;
+
+ if (!(cpu = cpuBaseline(cpus, ncpus, NULL, 0, false)))
+ goto cleanup;
+
+ if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
+ virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
+ goto cleanup;
+
+ cpustr = virCPUDefFormat(cpu, NULL, false);
+
+ cleanup:
+ virCPUDefListFree(cpus);
+ virCPUDefFree(cpu);
+
+ return cpustr;
}
--
2.14.1