cpu: Drop cpuBaselineXML

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@redhat.com>
This commit is contained in:
Jiri Denemark 2017-09-13 16:27:15 +02:00
parent 7816de498b
commit abec725ab1
8 changed files with 97 additions and 79 deletions

View File

@ -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

View File

@ -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:
*

View File

@ -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,

View File

@ -1077,7 +1077,6 @@ virStoragePoolObjVolumeListExport;
# cpu/cpu.h
cpuBaseline;
cpuBaselineXML;
cpuDecode;
cpuEncode;
virCPUCheckFeature;

View File

@ -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 = {

View File

@ -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;
}

View File

@ -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,

View File

@ -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;
}