cpu: Use virDomainCapsCPUModelsPtr in cpu driver APIs

All APIs which expect a list of CPU models supported by hypervisors were
switched from char **models and int models to just accept a pointer to
virDomainCapsCPUModels object stored in domain capabilities. This avoids
the need to transform virDomainCapsCPUModelsPtr into a NULL-terminated
list of model names and also allows the various cpu driver APIs to
access additional details (such as its usability) about each CPU model.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Jiri Denemark 2017-09-22 15:51:33 +02:00
parent e9f8e1b8e6
commit fd885a06a0
13 changed files with 137 additions and 185 deletions

View File

@ -192,7 +192,6 @@ virCPUCompare(virArch arch,
* @cpu: CPU definition stub to be filled in * @cpu: CPU definition stub to be filled in
* @data: internal CPU data to be decoded into @cpu definition * @data: internal CPU data to be decoded into @cpu definition
* @models: list of CPU models that can be considered when decoding @data * @models: list of CPU models that can be considered when decoding @data
* @nmodels: number of CPU models in @models
* @preferred: CPU models that should be used if possible * @preferred: CPU models that should be used if possible
* *
* Decodes internal CPU data into a CPU definition consisting of a CPU model * Decodes internal CPU data into a CPU definition consisting of a CPU model
@ -214,24 +213,17 @@ virCPUCompare(virArch arch,
int int
cpuDecode(virCPUDefPtr cpu, cpuDecode(virCPUDefPtr cpu,
const virCPUData *data, const virCPUData *data,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
const char *preferred) const char *preferred)
{ {
struct cpuArchDriver *driver; struct cpuArchDriver *driver;
VIR_DEBUG("cpu=%p, data=%p, nmodels=%u, preferred=%s", VIR_DEBUG("cpu=%p, data=%p, models=%p, preferred=%s",
cpu, data, nmodels, NULLSTR(preferred)); cpu, data, models, NULLSTR(preferred));
if (models) { if (models) {
size_t i; size_t i;
for (i = 0; i < nmodels; i++) for (i = 0; i < models->nmodels; i++)
VIR_DEBUG("models[%zu]=%s", i, NULLSTR(models[i])); VIR_DEBUG("models[%zu]=%s", i, models->models[i].name);
}
if (models == NULL && nmodels != 0) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("nonzero nmodels doesn't match with NULL models"));
return -1;
} }
if (cpu->type > VIR_CPU_TYPE_GUEST || if (cpu->type > VIR_CPU_TYPE_GUEST ||
@ -251,7 +243,7 @@ cpuDecode(virCPUDefPtr cpu,
return -1; return -1;
} }
return driver->decode(cpu, data, models, nmodels, preferred); return driver->decode(cpu, data, models, preferred);
} }
@ -384,7 +376,6 @@ virCPUGetHostIsSupported(virArch arch)
* @type: requested type of the CPU * @type: requested type of the CPU
* @nodeInfo: simplified CPU topology (optional) * @nodeInfo: simplified CPU topology (optional)
* @models: list of CPU models that can be considered for host CPU * @models: list of CPU models that can be considered for host CPU
* @nmodels: number of CPU models in @models
* *
* Create CPU definition describing the host's CPU. * Create CPU definition describing the host's CPU.
* *
@ -412,15 +403,14 @@ virCPUDefPtr
virCPUGetHost(virArch arch, virCPUGetHost(virArch arch,
virCPUType type, virCPUType type,
virNodeInfoPtr nodeInfo, virNodeInfoPtr nodeInfo,
const char **models, virDomainCapsCPUModelsPtr models)
unsigned int nmodels)
{ {
struct cpuArchDriver *driver; struct cpuArchDriver *driver;
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p, models=%p, nmodels=%u", VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p, models=%p",
virArchToString(arch), virCPUTypeToString(type), nodeInfo, virArchToString(arch), virCPUTypeToString(type), nodeInfo,
models, nmodels); models);
if (!(driver = cpuGetSubDriver(arch))) if (!(driver = cpuGetSubDriver(arch)))
return NULL; return NULL;
@ -462,7 +452,7 @@ virCPUGetHost(virArch arch,
* filled in. * filled in.
*/ */
if (driver->getHost) { if (driver->getHost) {
if (driver->getHost(cpu, models, nmodels) < 0 && if (driver->getHost(cpu, models) < 0 &&
!nodeInfo) !nodeInfo)
goto error; goto error;
} else if (nodeInfo) { } else if (nodeInfo) {
@ -491,7 +481,7 @@ virCPUProbeHost(virArch arch)
if (virCapabilitiesGetNodeInfo(&nodeinfo)) if (virCapabilitiesGetNodeInfo(&nodeinfo))
return NULL; return NULL;
return virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo, NULL, 0); return virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo, NULL);
} }
@ -501,11 +491,10 @@ virCPUProbeHost(virArch arch)
* @cpus: list of host CPU definitions * @cpus: list of host CPU definitions
* @ncpus: number of CPUs in @cpus * @ncpus: number of CPUs in @cpus
* @models: list of CPU models that can be considered for the baseline CPU * @models: list of CPU models that can be considered for the baseline CPU
* @nmodels: number of CPU models in @models
* @migratable: requests non-migratable features to be removed from the result * @migratable: requests non-migratable features to be removed from the result
* *
* Computes the most feature-rich CPU which is compatible with all given * 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 * host CPUs. If @models is NULL, all models supported by libvirt will
* be considered when computing the baseline CPU model, otherwise the baseline * be considered when computing the baseline CPU model, otherwise the baseline
* CPU model will be one of the provided CPU @models. * CPU model will be one of the provided CPU @models.
* *
@ -514,21 +503,20 @@ virCPUProbeHost(virArch arch)
virCPUDefPtr virCPUDefPtr
cpuBaseline(virCPUDefPtr *cpus, cpuBaseline(virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
bool migratable) bool migratable)
{ {
struct cpuArchDriver *driver; struct cpuArchDriver *driver;
size_t i; size_t i;
VIR_DEBUG("ncpus=%u, nmodels=%u", ncpus, nmodels); VIR_DEBUG("ncpus=%u, models=%p, migratable=%d", ncpus, models, migratable);
if (cpus) { if (cpus) {
for (i = 0; i < ncpus; i++) for (i = 0; i < ncpus; i++)
VIR_DEBUG("cpus[%zu]=%p", i, cpus[i]); VIR_DEBUG("cpus[%zu]=%p", i, cpus[i]);
} }
if (models) { if (models) {
for (i = 0; i < nmodels; i++) for (i = 0; i < models->nmodels; i++)
VIR_DEBUG("models[%zu]=%s", i, NULLSTR(models[i])); VIR_DEBUG("models[%zu]=%s", i, models->models[i].name);
} }
if (cpus == NULL && ncpus != 0) { if (cpus == NULL && ncpus != 0) {
@ -555,12 +543,6 @@ cpuBaseline(virCPUDefPtr *cpus,
} }
} }
if (models == NULL && nmodels != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("nonzero nmodels doesn't match with NULL models"));
return NULL;
}
if ((driver = cpuGetSubDriver(cpus[0]->arch)) == NULL) if ((driver = cpuGetSubDriver(cpus[0]->arch)) == NULL)
return NULL; return NULL;
@ -571,7 +553,7 @@ cpuBaseline(virCPUDefPtr *cpus,
return NULL; return NULL;
} }
return driver->baseline(cpus, ncpus, models, nmodels, migratable); return driver->baseline(cpus, ncpus, models, migratable);
} }
@ -844,25 +826,23 @@ virCPUDataParse(const char *xmlStr)
* *
* @model: CPU model to be checked * @model: CPU model to be checked
* @models: list of supported CPU models * @models: list of supported CPU models
* @nmodels: number of models in @models
* *
* Checks whether @model can be found in the list of supported @models. * Checks whether @model can be found in the list of supported @models.
* If @models is empty, all models are supported. * If @models is NULL, all models are supported.
* *
* Returns true if @model is supported, false otherwise. * Returns true if @model is supported, false otherwise.
*/ */
bool bool
virCPUModelIsAllowed(const char *model, virCPUModelIsAllowed(const char *model,
const char **models, virDomainCapsCPUModelsPtr models)
unsigned int nmodels)
{ {
size_t i; size_t i;
if (!models || !nmodels) if (!models)
return true; return true;
for (i = 0; i < nmodels; i++) { for (i = 0; i < models->nmodels; i++) {
if (models[i] && STREQ(models[i], model)) if (STREQ(models->models[i].name, model))
return true; return true;
} }
return false; return false;
@ -908,8 +888,7 @@ virCPUGetModels(virArch arch, char ***models)
* *
* @arch: CPU architecture * @arch: CPU architecture
* @cpu: CPU definition to be translated * @cpu: CPU definition to be translated
* @models: NULL-terminated list of allowed CPU models (NULL if all are allowed) * @models: list of allowed CPU models (NULL if all are allowed)
* @nmodels: number of CPU models in @models
* *
* Translates @cpu model (if allowed by @cpu->fallback) to a closest CPU model * Translates @cpu model (if allowed by @cpu->fallback) to a closest CPU model
* from @models list. * from @models list.
@ -922,13 +901,12 @@ virCPUGetModels(virArch arch, char ***models)
int int
virCPUTranslate(virArch arch, virCPUTranslate(virArch arch,
virCPUDefPtr cpu, virCPUDefPtr cpu,
const char **models, virDomainCapsCPUModelsPtr models)
unsigned int nmodels)
{ {
struct cpuArchDriver *driver; struct cpuArchDriver *driver;
VIR_DEBUG("arch=%s, cpu=%p, model=%s, models=%p, nmodels=%u", VIR_DEBUG("arch=%s, cpu=%p, model=%s, models=%p",
virArchToString(arch), cpu, NULLSTR(cpu->model), models, nmodels); virArchToString(arch), cpu, NULLSTR(cpu->model), models);
if (!(driver = cpuGetSubDriver(arch))) if (!(driver = cpuGetSubDriver(arch)))
return -1; return -1;
@ -937,7 +915,7 @@ virCPUTranslate(virArch arch,
cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH) cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH)
return 0; return 0;
if (virCPUModelIsAllowed(cpu->model, models, nmodels)) if (virCPUModelIsAllowed(cpu->model, models))
return 0; return 0;
if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) { if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) {
@ -954,7 +932,7 @@ virCPUTranslate(virArch arch,
return -1; return -1;
} }
if (driver->translate(cpu, models, nmodels) < 0) if (driver->translate(cpu, models) < 0)
return -1; return -1;
VIR_DEBUG("model=%s", NULLSTR(cpu->model)); VIR_DEBUG("model=%s", NULLSTR(cpu->model));

View File

@ -27,6 +27,7 @@
# include "virerror.h" # include "virerror.h"
# include "datatypes.h" # include "datatypes.h"
# include "virarch.h" # include "virarch.h"
# include "domain_capabilities.h"
# include "cpu_conf.h" # include "cpu_conf.h"
# include "cpu_x86_data.h" # include "cpu_x86_data.h"
# include "cpu_ppc64_data.h" # include "cpu_ppc64_data.h"
@ -52,8 +53,7 @@ typedef virCPUCompareResult
typedef int typedef int
(*cpuArchDecode) (virCPUDefPtr cpu, (*cpuArchDecode) (virCPUDefPtr cpu,
const virCPUData *data, const virCPUData *data,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
const char *preferred); const char *preferred);
typedef int typedef int
@ -71,14 +71,12 @@ typedef void
typedef int typedef int
(*virCPUArchGetHost)(virCPUDefPtr cpu, (*virCPUArchGetHost)(virCPUDefPtr cpu,
const char **models, virDomainCapsCPUModelsPtr models);
unsigned int nmodels);
typedef virCPUDefPtr typedef virCPUDefPtr
(*cpuArchBaseline) (virCPUDefPtr *cpus, (*cpuArchBaseline) (virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
bool migratable); bool migratable);
typedef int typedef int
@ -109,8 +107,7 @@ typedef int
typedef int typedef int
(*virCPUArchTranslate)(virCPUDefPtr cpu, (*virCPUArchTranslate)(virCPUDefPtr cpu,
const char **models, virDomainCapsCPUModelsPtr models);
unsigned int nmodels);
typedef int typedef int
(*virCPUArchConvertLegacy)(virCPUDefPtr cpu); (*virCPUArchConvertLegacy)(virCPUDefPtr cpu);
@ -165,8 +162,7 @@ virCPUCompare(virArch arch,
int int
cpuDecode (virCPUDefPtr cpu, cpuDecode (virCPUDefPtr cpu,
const virCPUData *data, const virCPUData *data,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
const char *preferred) const char *preferred)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
@ -194,8 +190,7 @@ virCPUDefPtr
virCPUGetHost(virArch arch, virCPUGetHost(virArch arch,
virCPUType type, virCPUType type,
virNodeInfoPtr nodeInfo, virNodeInfoPtr nodeInfo,
const char **models, virDomainCapsCPUModelsPtr models);
unsigned int nmodels);
virCPUDefPtr virCPUDefPtr
virCPUProbeHost(virArch arch); virCPUProbeHost(virArch arch);
@ -203,8 +198,7 @@ virCPUProbeHost(virArch arch);
virCPUDefPtr virCPUDefPtr
cpuBaseline (virCPUDefPtr *cpus, cpuBaseline (virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
bool migratable); bool migratable);
int int
@ -235,8 +229,7 @@ virCPUDataCheckFeature(const virCPUData *data,
bool bool
virCPUModelIsAllowed(const char *model, virCPUModelIsAllowed(const char *model,
const char **models, virDomainCapsCPUModelsPtr models)
unsigned int nmodels)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
int int
@ -245,8 +238,7 @@ virCPUGetModels(virArch arch, char ***models);
int int
virCPUTranslate(virArch arch, virCPUTranslate(virArch arch,
virCPUDefPtr cpu, virCPUDefPtr cpu,
const char **models, virDomainCapsCPUModelsPtr models)
unsigned int nmodels)
ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(2);
int int

View File

@ -75,8 +75,7 @@ virCPUarmUpdate(virCPUDefPtr guest,
static virCPUDefPtr static virCPUDefPtr
armBaseline(virCPUDefPtr *cpus, armBaseline(virCPUDefPtr *cpus,
unsigned int ncpus ATTRIBUTE_UNUSED, unsigned int ncpus ATTRIBUTE_UNUSED,
const char **models ATTRIBUTE_UNUSED, virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED,
unsigned int nmodels ATTRIBUTE_UNUSED,
bool migratable ATTRIBUTE_UNUSED) bool migratable ATTRIBUTE_UNUSED)
{ {
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;

View File

@ -669,8 +669,7 @@ virCPUppc64Compare(virCPUDefPtr host,
static int static int
ppc64DriverDecode(virCPUDefPtr cpu, ppc64DriverDecode(virCPUDefPtr cpu,
const virCPUData *data, const virCPUData *data,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
const char *preferred ATTRIBUTE_UNUSED) const char *preferred ATTRIBUTE_UNUSED)
{ {
int ret = -1; int ret = -1;
@ -687,7 +686,7 @@ ppc64DriverDecode(virCPUDefPtr cpu,
goto cleanup; goto cleanup;
} }
if (!virCPUModelIsAllowed(model->name, models, nmodels)) { if (!virCPUModelIsAllowed(model->name, models)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("CPU model %s is not supported by hypervisor"), _("CPU model %s is not supported by hypervisor"),
model->name); model->name);
@ -720,8 +719,7 @@ virCPUppc64DataFree(virCPUDataPtr data)
static int static int
virCPUppc64GetHost(virCPUDefPtr cpu, virCPUppc64GetHost(virCPUDefPtr cpu,
const char **models, virDomainCapsCPUModelsPtr models)
unsigned int nmodels)
{ {
virCPUDataPtr cpuData = NULL; virCPUDataPtr cpuData = NULL;
virCPUppc64Data *data; virCPUppc64Data *data;
@ -743,7 +741,7 @@ virCPUppc64GetHost(virCPUDefPtr cpu,
#endif #endif
data->pvr[0].mask = 0xfffffffful; data->pvr[0].mask = 0xfffffffful;
ret = ppc64DriverDecode(cpu, cpuData, models, nmodels, NULL); ret = ppc64DriverDecode(cpu, cpuData, models, NULL);
cleanup: cleanup:
virCPUppc64DataFree(cpuData); virCPUppc64DataFree(cpuData);
@ -772,8 +770,7 @@ virCPUppc64Update(virCPUDefPtr guest,
static virCPUDefPtr static virCPUDefPtr
ppc64DriverBaseline(virCPUDefPtr *cpus, ppc64DriverBaseline(virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
const char **models ATTRIBUTE_UNUSED, virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED,
unsigned int nmodels ATTRIBUTE_UNUSED,
bool migratable ATTRIBUTE_UNUSED) bool migratable ATTRIBUTE_UNUSED)
{ {
struct ppc64_map *map; struct ppc64_map *map;

View File

@ -1820,8 +1820,7 @@ x86DataFilterTSX(virCPUx86Data *data,
static int static int
x86Decode(virCPUDefPtr cpu, x86Decode(virCPUDefPtr cpu,
const virCPUx86Data *cpuData, const virCPUx86Data *cpuData,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
const char *preferred, const char *preferred,
bool migratable) bool migratable)
{ {
@ -1855,7 +1854,7 @@ x86Decode(virCPUDefPtr cpu,
*/ */
for (i = map->nmodels - 1; i >= 0; i--) { for (i = map->nmodels - 1; i >= 0; i--) {
candidate = map->models[i]; candidate = map->models[i];
if (!virCPUModelIsAllowed(candidate->name, models, nmodels)) { if (!virCPUModelIsAllowed(candidate->name, models)) {
if (preferred && STREQ(candidate->name, preferred)) { if (preferred && STREQ(candidate->name, preferred)) {
if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) { if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -1946,11 +1945,10 @@ x86Decode(virCPUDefPtr cpu,
static int static int
x86DecodeCPUData(virCPUDefPtr cpu, x86DecodeCPUData(virCPUDefPtr cpu,
const virCPUData *data, const virCPUData *data,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
const char *preferred) const char *preferred)
{ {
return x86Decode(cpu, &data->data.x86, models, nmodels, preferred, false); return x86Decode(cpu, &data->data.x86, models, preferred, false);
} }
@ -2402,8 +2400,7 @@ cpuidSet(uint32_t base, virCPUDataPtr data)
static int static int
virCPUx86GetHost(virCPUDefPtr cpu, virCPUx86GetHost(virCPUDefPtr cpu,
const char **models, virDomainCapsCPUModelsPtr models)
unsigned int nmodels)
{ {
virCPUDataPtr cpuData = NULL; virCPUDataPtr cpuData = NULL;
int ret = -1; int ret = -1;
@ -2415,7 +2412,7 @@ virCPUx86GetHost(virCPUDefPtr cpu,
cpuidSet(CPUX86_EXTENDED, cpuData) < 0) cpuidSet(CPUX86_EXTENDED, cpuData) < 0)
goto cleanup; goto cleanup;
ret = x86DecodeCPUData(cpu, cpuData, models, nmodels, NULL); ret = x86DecodeCPUData(cpu, cpuData, models, NULL);
cleanup: cleanup:
virCPUx86DataFree(cpuData); virCPUx86DataFree(cpuData);
@ -2427,8 +2424,7 @@ virCPUx86GetHost(virCPUDefPtr cpu,
static virCPUDefPtr static virCPUDefPtr
x86Baseline(virCPUDefPtr *cpus, x86Baseline(virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
const char **models, virDomainCapsCPUModelsPtr models,
unsigned int nmodels,
bool migratable) bool migratable)
{ {
virCPUx86MapPtr map = NULL; virCPUx86MapPtr map = NULL;
@ -2523,7 +2519,7 @@ x86Baseline(virCPUDefPtr *cpus,
virCPUx86DataAddCPUIDInt(&base_model->data, &vendor->cpuid) < 0) virCPUx86DataAddCPUIDInt(&base_model->data, &vendor->cpuid) < 0)
goto error; goto error;
if (x86Decode(cpu, &base_model->data, models, nmodels, modelName, migratable) < 0) if (x86Decode(cpu, &base_model->data, models, modelName, migratable) < 0)
goto error; goto error;
if (STREQ_NULLABLE(cpu->model, modelName)) if (STREQ_NULLABLE(cpu->model, modelName))
@ -2805,8 +2801,7 @@ virCPUx86GetModels(char ***models)
static int static int
virCPUx86Translate(virCPUDefPtr cpu, virCPUx86Translate(virCPUDefPtr cpu,
const char **models, virDomainCapsCPUModelsPtr models)
unsigned int nmodels)
{ {
virCPUDefPtr translated = NULL; virCPUDefPtr translated = NULL;
virCPUx86MapPtr map; virCPUx86MapPtr map;
@ -2830,7 +2825,7 @@ virCPUx86Translate(virCPUDefPtr cpu,
if (!(translated = virCPUDefCopyWithoutModel(cpu))) if (!(translated = virCPUDefCopyWithoutModel(cpu)))
goto cleanup; goto cleanup;
if (x86Decode(translated, &model->data, models, nmodels, NULL, false) < 0) if (x86Decode(translated, &model->data, models, NULL, false) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < cpu->nfeatures; i++) { for (i = 0; i < cpu->nfeatures; i++) {

View File

@ -192,7 +192,7 @@ libxlCapsInitCPU(virCapsPtr caps, libxl_physinfo *phy_info,
ret = 0; ret = 0;
if (!(data = libxlCapsNodeData(cpu, phy_info->hw_cap, version)) || if (!(data = libxlCapsNodeData(cpu, phy_info->hw_cap, version)) ||
cpuDecode(cpu, data, NULL, 0, NULL) < 0) { cpuDecode(cpu, data, NULL, NULL) < 0) {
VIR_WARN("Failed to initialize host cpu features"); VIR_WARN("Failed to initialize host cpu features");
goto error; goto error;
} }

View File

@ -6457,7 +6457,7 @@ libxlConnectBaselineCPU(virConnectPtr conn,
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
goto cleanup; goto cleanup;
if (!(cpu = cpuBaseline(cpus, ncpus, NULL, 0, if (!(cpu = cpuBaseline(cpus, ncpus, NULL,
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)))) !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
goto cleanup; goto cleanup;

View File

@ -1168,18 +1168,8 @@ virQEMUCapsProbeHostCPUForEmulator(virArch hostArch,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
virDomainVirtType type) virDomainVirtType type)
{ {
size_t nmodels; return virCPUGetHost(hostArch, VIR_CPU_TYPE_GUEST, NULL,
char **models; virQEMUCapsGetCPUDefinitions(qemuCaps, type));
virCPUDefPtr cpu;
if (virQEMUCapsGetCPUDefinitions(qemuCaps, type, &models, &nmodels) < 0)
return NULL;
cpu = virCPUGetHost(hostArch, VIR_CPU_TYPE_GUEST, NULL,
(const char **) models, nmodels);
virStringListFreeCount(models, nmodels);
return cpu;
} }
@ -2534,45 +2524,14 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
} }
int virDomainCapsCPUModelsPtr
virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps, virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type, virDomainVirtType type)
char ***names,
size_t *count)
{ {
size_t i;
char **models = NULL;
virDomainCapsCPUModelsPtr cpus;
*count = 0;
if (names)
*names = NULL;
if (type == VIR_DOMAIN_VIRT_KVM) if (type == VIR_DOMAIN_VIRT_KVM)
cpus = qemuCaps->kvmCPUModels; return qemuCaps->kvmCPUModels;
else else
cpus = qemuCaps->tcgCPUModels; return qemuCaps->tcgCPUModels;
if (!cpus)
return 0;
if (names && VIR_ALLOC_N(models, cpus->nmodels) < 0)
return -1;
for (i = 0; i < cpus->nmodels; i++) {
virDomainCapsCPUModelPtr cpu = cpus->models + i;
if (models && VIR_STRDUP(models[i], cpu->name) < 0)
goto error;
}
if (names)
*names = models;
*count = cpus->nmodels;
return 0;
error:
virStringListFreeCount(models, i);
return -1;
} }
@ -3394,8 +3353,6 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
virCPUDataPtr data = NULL; virCPUDataPtr data = NULL;
unsigned long long sigFamily = 0; unsigned long long sigFamily = 0;
unsigned long long sigModel = 0; unsigned long long sigModel = 0;
size_t nmodels = 0;
char **models = NULL;
int ret = -1; int ret = -1;
size_t i; size_t i;
@ -3440,15 +3397,15 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
if (virCPUx86DataSetSignature(data, sigFamily, sigModel) < 0) if (virCPUx86DataSetSignature(data, sigFamily, sigModel) < 0)
goto cleanup; goto cleanup;
if (virQEMUCapsGetCPUDefinitions(qemuCaps, type, &models, &nmodels) < 0 || if (cpuDecode(cpu, data,
cpuDecode(cpu, data, (const char **) models, nmodels, NULL) < 0) virQEMUCapsGetCPUDefinitions(qemuCaps, type),
NULL) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
virCPUDataFree(data); virCPUDataFree(data);
virStringListFreeCount(models, nmodels);
return ret; return ret;
} }
@ -3534,7 +3491,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
} else if (type == VIR_DOMAIN_VIRT_KVM && } else if (type == VIR_DOMAIN_VIRT_KVM &&
virCPUGetHostIsSupported(qemuCaps->arch)) { virCPUGetHostIsSupported(qemuCaps->arch)) {
if (!(fullCPU = virCPUGetHost(qemuCaps->arch, VIR_CPU_TYPE_GUEST, if (!(fullCPU = virCPUGetHost(qemuCaps->arch, VIR_CPU_TYPE_GUEST,
NULL, NULL, 0))) NULL, NULL)))
goto error; goto error;
for (i = 0; i < cpu->nfeatures; i++) { for (i = 0; i < cpu->nfeatures; i++) {

View File

@ -470,10 +470,8 @@ int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
const char **name, const char **name,
size_t count, size_t count,
virDomainCapsCPUUsable usable); virDomainCapsCPUUsable usable);
int virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps, virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type, virDomainVirtType type);
char ***names,
size_t *count);
typedef enum { typedef enum {
/* Host CPU definition reported in domain capabilities. */ /* Host CPU definition reported in domain capabilities. */

View File

@ -13042,7 +13042,7 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
goto cleanup; goto cleanup;
if (!(baseline = cpuBaseline(cpus, ncpus, NULL, 0, if (!(baseline = cpuBaseline(cpus, ncpus, NULL,
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)))) !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
goto cleanup; goto cleanup;

View File

@ -5166,8 +5166,6 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
unsigned int flags) unsigned int flags)
{ {
int ret = -1; int ret = -1;
size_t nmodels = 0;
char **models = NULL;
if (!def->cpu) if (!def->cpu)
return 0; return 0;
@ -5219,17 +5217,14 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0) VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
goto cleanup; goto cleanup;
if (virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType, if (virCPUTranslate(def->os.arch, def->cpu,
&models, &nmodels) < 0 || virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType)) < 0)
virCPUTranslate(def->os.arch, def->cpu,
(const char **) models, nmodels) < 0)
goto cleanup; goto cleanup;
def->cpu->fallback = VIR_CPU_FALLBACK_FORBID; def->cpu->fallback = VIR_CPU_FALLBACK_FORBID;
ret = 0; ret = 0;
cleanup: cleanup:
virStringListFreeCount(models, nmodels);
return ret; return ret;
} }

View File

@ -1536,7 +1536,7 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
goto cleanup; goto cleanup;
if (!(cpu = cpuBaseline(cpus, ncpus, NULL, 0, false))) if (!(cpu = cpuBaseline(cpus, ncpus, NULL, false)))
goto cleanup; goto cleanup;
if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&

View File

@ -61,9 +61,8 @@ struct data {
virArch arch; virArch arch;
const char *host; const char *host;
const char *name; const char *name;
const char **models; virDomainCapsCPUModelsPtr models;
const char *modelsName; const char *modelsName;
unsigned int nmodels;
unsigned int flags; unsigned int flags;
int result; int result;
}; };
@ -264,13 +263,13 @@ cpuTestGuestCPU(const void *arg)
} }
if (virCPUUpdate(host->arch, cpu, host) < 0 || if (virCPUUpdate(host->arch, cpu, host) < 0 ||
virCPUTranslate(host->arch, cpu, data->models, data->nmodels) < 0) { virCPUTranslate(host->arch, cpu, data->models) < 0) {
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }
virBufferAsprintf(&buf, "%s+%s", data->host, data->name); virBufferAsprintf(&buf, "%s+%s", data->host, data->name);
if (data->nmodels) if (data->modelsName)
virBufferAsprintf(&buf, ",%s", data->modelsName); virBufferAsprintf(&buf, ",%s", data->modelsName);
virBufferAddLit(&buf, "-result"); virBufferAddLit(&buf, "-result");
@ -322,7 +321,7 @@ cpuTestBaseline(const void *arg)
if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus))) if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
goto cleanup; goto cleanup;
baseline = cpuBaseline(cpus, ncpus, NULL, 0, baseline = cpuBaseline(cpus, ncpus, NULL,
!!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)); !!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE));
if (baseline && if (baseline &&
@ -492,7 +491,7 @@ cpuTestCPUID(bool guest, const void *arg)
cpu->type = VIR_CPU_TYPE_HOST; cpu->type = VIR_CPU_TYPE_HOST;
} }
if (cpuDecode(cpu, hostData, NULL, 0, NULL) < 0) if (cpuDecode(cpu, hostData, NULL, NULL) < 0)
goto cleanup; goto cleanup;
if (virAsprintf(&result, "cpuid-%s-%s", if (virAsprintf(&result, "cpuid-%s-%s",
@ -729,15 +728,43 @@ cpuTestJSONCPUID(const void *arg)
#endif #endif
static const char *model486[] = { "486" }; static const char *model486_list[] = { "486", NULL };
static const char *nomodel[] = { "nomodel" }; static const char *nomodel_list[] = { "nomodel", NULL };
static const char *models[] = { "qemu64", "core2duo", "Nehalem" }; static const char *models_list[] = { "qemu64", "core2duo", "Nehalem", NULL };
static const char *haswell[] = { "SandyBridge", "Haswell" }; static const char *haswell_list[] = { "SandyBridge", "Haswell", NULL };
static const char *ppc_models[] = { "POWER6", "POWER7", "POWER8" }; static const char *ppc_models_list[] = { "POWER6", "POWER7", "POWER8", NULL };
static virDomainCapsCPUModelsPtr
cpuTestInitModels(const char **list)
{
virDomainCapsCPUModelsPtr cpus;
const char **model;
if (!(cpus = virDomainCapsCPUModelsNew(0)))
return NULL;
for (model = list; *model; model++) {
if (virDomainCapsCPUModelsAdd(cpus, *model, -1,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL) < 0)
goto error;
}
return cpus;
error:
virObjectUnref(cpus);
return NULL;
}
static int static int
mymain(void) mymain(void)
{ {
virDomainCapsCPUModelsPtr model486 = NULL;
virDomainCapsCPUModelsPtr nomodel = NULL;
virDomainCapsCPUModelsPtr models = NULL;
virDomainCapsCPUModelsPtr haswell = NULL;
virDomainCapsCPUModelsPtr ppc_models = NULL;
int ret = 0; int ret = 0;
#if WITH_QEMU && WITH_YAJL #if WITH_QEMU && WITH_YAJL
@ -747,13 +774,22 @@ mymain(void)
virEventRegisterDefaultImpl(); virEventRegisterDefaultImpl();
#endif #endif
if (!(model486 = cpuTestInitModels(model486_list)) ||
!(nomodel = cpuTestInitModels(nomodel_list)) ||
!(models = cpuTestInitModels(models_list)) ||
!(haswell = cpuTestInitModels(haswell_list)) ||
!(ppc_models = cpuTestInitModels(ppc_models_list))) {
ret = -1;
goto cleanup;
}
#define DO_TEST(arch, api, name, host, cpu, \ #define DO_TEST(arch, api, name, host, cpu, \
models, nmodels, flags, result) \ models, flags, result) \
do { \ do { \
struct data data = { \ struct data data = { \
arch, host, cpu, models, \ arch, host, cpu, models, \
models == NULL ? NULL : #models, \ models == NULL ? NULL : #models, \
nmodels, flags, result \ flags, result \
}; \ }; \
char *testLabel; \ char *testLabel; \
char *tmp; \ char *tmp; \
@ -784,12 +820,12 @@ mymain(void)
#define DO_TEST_COMPARE(arch, host, cpu, result) \ #define DO_TEST_COMPARE(arch, host, cpu, result) \
DO_TEST(arch, cpuTestCompare, \ DO_TEST(arch, cpuTestCompare, \
host "/" cpu " (" #result ")", \ host "/" cpu " (" #result ")", \
host, cpu, NULL, 0, 0, result) host, cpu, NULL, 0, result)
#define DO_TEST_UPDATE_ONLY(arch, host, cpu) \ #define DO_TEST_UPDATE_ONLY(arch, host, cpu) \
DO_TEST(arch, cpuTestUpdate, \ DO_TEST(arch, cpuTestUpdate, \
cpu " on " host, \ cpu " on " host, \
host, cpu, NULL, 0, 0, 0) host, cpu, NULL, 0, 0)
#define DO_TEST_UPDATE(arch, host, cpu, result) \ #define DO_TEST_UPDATE(arch, host, cpu, result) \
do { \ do { \
@ -809,7 +845,7 @@ mymain(void)
ret = -1; \ ret = -1; \
} else { \ } else { \
DO_TEST(arch, cpuTestBaseline, label, NULL, \ DO_TEST(arch, cpuTestBaseline, label, NULL, \
"baseline-" name, NULL, 0, flags, result); \ "baseline-" name, NULL, flags, result); \
} \ } \
VIR_FREE(label); \ VIR_FREE(label); \
} while (0) } while (0)
@ -817,21 +853,19 @@ mymain(void)
#define DO_TEST_HASFEATURE(arch, host, feature, result) \ #define DO_TEST_HASFEATURE(arch, host, feature, result) \
DO_TEST(arch, cpuTestHasFeature, \ DO_TEST(arch, cpuTestHasFeature, \
host "/" feature " (" #result ")", \ host "/" feature " (" #result ")", \
host, feature, NULL, 0, 0, result) host, feature, NULL, 0, result)
#define DO_TEST_GUESTCPU(arch, host, cpu, models, result) \ #define DO_TEST_GUESTCPU(arch, host, cpu, models, result) \
DO_TEST(arch, cpuTestGuestCPU, \ DO_TEST(arch, cpuTestGuestCPU, \
host "/" cpu " (" #models ")", \ host "/" cpu " (" #models ")", \
host, cpu, models, \ host, cpu, models, 0, result)
models == NULL ? 0 : sizeof(models) / sizeof(char *), \
0, result)
#if WITH_QEMU && WITH_YAJL #if WITH_QEMU && WITH_YAJL
# define DO_TEST_CPUID_JSON(arch, host, json) \ # define DO_TEST_CPUID_JSON(arch, host, json) \
do { \ do { \
if (json) { \ if (json) { \
DO_TEST(arch, cpuTestJSONCPUID, host, host, \ DO_TEST(arch, cpuTestJSONCPUID, host, host, \
NULL, NULL, 0, 0, 0); \ NULL, NULL, 0, 0); \
} \ } \
} while (0) } while (0)
#else #else
@ -841,13 +875,13 @@ mymain(void)
#define DO_TEST_CPUID(arch, host, json) \ #define DO_TEST_CPUID(arch, host, json) \
do { \ do { \
DO_TEST(arch, cpuTestHostCPUID, host, host, \ DO_TEST(arch, cpuTestHostCPUID, host, host, \
NULL, NULL, 0, 0, 0); \ NULL, NULL, 0, 0); \
DO_TEST(arch, cpuTestGuestCPUID, host, host, \ DO_TEST(arch, cpuTestGuestCPUID, host, host, \
NULL, NULL, 0, 0, 0); \ NULL, NULL, 0, 0); \
DO_TEST_CPUID_JSON(arch, host, json); \ DO_TEST_CPUID_JSON(arch, host, json); \
if (json) { \ if (json) { \
DO_TEST(arch, cpuTestUpdateLive, host, host, \ DO_TEST(arch, cpuTestUpdateLive, host, host, \
NULL, NULL, 0, 0, 0); \ NULL, NULL, 0, 0); \
} \ } \
} while (0) } while (0)
@ -1012,10 +1046,17 @@ mymain(void)
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-W3520", true); DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-W3520", true);
DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-X5460", false); DO_TEST_CPUID(VIR_ARCH_X86_64, "Xeon-X5460", false);
cleanup:
#if WITH_QEMU && WITH_YAJL #if WITH_QEMU && WITH_YAJL
qemuTestDriverFree(&driver); qemuTestDriverFree(&driver);
#endif #endif
virObjectUnref(model486);
virObjectUnref(nomodel);
virObjectUnref(models);
virObjectUnref(haswell);
virObjectUnref(ppc_models);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }