mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 05:17:54 +03:00
cpu: Add optional list of allowed features to virCPUBaseline
When computing a baseline CPU for a specific hypervisor we have to make sure to include only CPU features supported by the hypervisor. Otherwise the computed CPU could not be used for starting a new domain. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Collin Walling <walling@linux.ibm.com>
This commit is contained in:
parent
f277fb39b7
commit
7fb950958a
@ -1398,7 +1398,7 @@ bhyveConnectBaselineCPU(virConnectPtr conn,
|
||||
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL,
|
||||
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL,
|
||||
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
|
||||
goto cleanup;
|
||||
|
||||
|
@ -485,6 +485,7 @@ virCPUProbeHost(virArch arch)
|
||||
* @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
|
||||
* @features: optional NULL terminated list of allowed features
|
||||
* @migratable: requests non-migratable features to be removed from the result
|
||||
*
|
||||
* Computes the most feature-rich CPU which is compatible with all given
|
||||
@ -499,13 +500,14 @@ virCPUBaseline(virArch arch,
|
||||
virCPUDefPtr *cpus,
|
||||
unsigned int ncpus,
|
||||
virDomainCapsCPUModelsPtr models,
|
||||
const char **features,
|
||||
bool migratable)
|
||||
{
|
||||
struct cpuArchDriver *driver;
|
||||
size_t i;
|
||||
|
||||
VIR_DEBUG("arch=%s, ncpus=%u, models=%p, migratable=%d",
|
||||
virArchToString(arch), ncpus, models, migratable);
|
||||
VIR_DEBUG("arch=%s, ncpus=%u, models=%p, features=%p, migratable=%d",
|
||||
virArchToString(arch), ncpus, models, features, migratable);
|
||||
if (cpus) {
|
||||
for (i = 0; i < ncpus; i++)
|
||||
VIR_DEBUG("cpus[%zu]=%p", i, cpus[i]);
|
||||
@ -552,7 +554,7 @@ virCPUBaseline(virArch arch,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return driver->baseline(cpus, ncpus, models, migratable);
|
||||
return driver->baseline(cpus, ncpus, models, features, migratable);
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,6 +76,7 @@ typedef virCPUDefPtr
|
||||
(*virCPUArchBaseline)(virCPUDefPtr *cpus,
|
||||
unsigned int ncpus,
|
||||
virDomainCapsCPUModelsPtr models,
|
||||
const char **features,
|
||||
bool migratable);
|
||||
|
||||
typedef int
|
||||
@ -198,6 +199,7 @@ virCPUBaseline(virArch arch,
|
||||
virCPUDefPtr *cpus,
|
||||
unsigned int ncpus,
|
||||
virDomainCapsCPUModelsPtr models,
|
||||
const char **features,
|
||||
bool migratable);
|
||||
|
||||
int
|
||||
|
@ -76,6 +76,7 @@ static virCPUDefPtr
|
||||
virCPUarmBaseline(virCPUDefPtr *cpus,
|
||||
unsigned int ncpus ATTRIBUTE_UNUSED,
|
||||
virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED,
|
||||
const char **features ATTRIBUTE_UNUSED,
|
||||
bool migratable ATTRIBUTE_UNUSED)
|
||||
{
|
||||
virCPUDefPtr cpu = NULL;
|
||||
|
@ -770,6 +770,7 @@ static virCPUDefPtr
|
||||
virCPUppc64Baseline(virCPUDefPtr *cpus,
|
||||
unsigned int ncpus,
|
||||
virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED,
|
||||
const char **features ATTRIBUTE_UNUSED,
|
||||
bool migratable ATTRIBUTE_UNUSED)
|
||||
{
|
||||
struct ppc64_map *map;
|
||||
|
@ -2467,6 +2467,7 @@ static virCPUDefPtr
|
||||
virCPUx86Baseline(virCPUDefPtr *cpus,
|
||||
unsigned int ncpus,
|
||||
virDomainCapsCPUModelsPtr models,
|
||||
const char **features,
|
||||
bool migratable)
|
||||
{
|
||||
virCPUx86MapPtr map = NULL;
|
||||
@ -2478,6 +2479,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
|
||||
bool outputVendor = true;
|
||||
const char *modelName;
|
||||
bool matchingNames = true;
|
||||
virCPUDataPtr featData = NULL;
|
||||
|
||||
if (!(map = virCPUx86GetMap()))
|
||||
goto error;
|
||||
@ -2550,6 +2552,21 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
|
||||
model = NULL;
|
||||
}
|
||||
|
||||
if (features) {
|
||||
virCPUx86FeaturePtr feat;
|
||||
|
||||
if (!(featData = virCPUDataNew(archs[0])))
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; features[i]; i++) {
|
||||
if ((feat = x86FeatureFind(map, features[i])) &&
|
||||
x86DataAdd(&featData->data.x86, &feat->data) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
x86DataIntersect(&base_model->data, &featData->data.x86);
|
||||
}
|
||||
|
||||
if (x86DataIsEmpty(&base_model->data)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
"%s", _("CPUs are incompatible"));
|
||||
@ -2571,6 +2588,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
|
||||
|
||||
cleanup:
|
||||
x86ModelFree(base_model);
|
||||
virCPUx86DataFree(featData);
|
||||
|
||||
return cpu;
|
||||
|
||||
|
@ -6349,7 +6349,7 @@ libxlConnectBaselineCPU(virConnectPtr conn,
|
||||
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL,
|
||||
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL,
|
||||
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
|
||||
goto cleanup;
|
||||
|
||||
|
@ -13315,7 +13315,7 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(baseline = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL,
|
||||
if (!(baseline = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL,
|
||||
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
|
||||
goto cleanup;
|
||||
|
||||
|
@ -1541,7 +1541,7 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false)))
|
||||
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, false)))
|
||||
goto cleanup;
|
||||
|
||||
if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
|
||||
|
@ -934,7 +934,7 @@ vzConnectBaselineCPU(virConnectPtr conn,
|
||||
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false)))
|
||||
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, false)))
|
||||
goto cleanup;
|
||||
|
||||
if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&
|
||||
|
@ -321,7 +321,7 @@ cpuTestBaseline(const void *arg)
|
||||
if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
|
||||
goto cleanup;
|
||||
|
||||
baseline = virCPUBaseline(data->arch, cpus, ncpus, NULL,
|
||||
baseline = virCPUBaseline(data->arch, cpus, ncpus, NULL, NULL,
|
||||
!!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE));
|
||||
|
||||
if (baseline &&
|
||||
|
Loading…
Reference in New Issue
Block a user