cpu: Introduce virCPUGetCanonicalModel

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Jiri Denemark 2024-11-22 19:00:26 +01:00
parent cb6463d803
commit ca0ea085d7
4 changed files with 53 additions and 0 deletions

View File

@ -1345,6 +1345,31 @@ virCPUGetCheckMode(virArch arch,
}
/** virCPUGetCanonicalModel:
*
* @arch: CPU architecture
* @model: CPU model to be checked
*
* Returns @model's canonical name if @model is an alias or NULL otherwise.
*/
const char *
virCPUGetCanonicalModel(virArch arch,
const char *model)
{
struct cpuArchDriver *driver;
VIR_DEBUG("arch=%s model=%s", virArchToString(arch), model);
if (!(driver = cpuGetSubDriver(arch)))
return NULL;
if (!driver->getCanonicalModel)
return NULL;
return driver->getCanonicalModel(model);
}
/**
* virCPUArchIsSupported:
*

View File

@ -140,6 +140,9 @@ typedef int
(*virCPUArchGetCheckMode)(const char *modelName,
bool *compat);
typedef const char *
(*virCPUArchGetCanonicalModel)(const char *model);
struct cpuArchDriver {
const char *name;
const virArch *arch;
@ -168,6 +171,7 @@ struct cpuArchDriver {
virCPUArchDataIsIdentical dataIsIdentical;
virCPUArchDataGetHost dataGetHost;
virCPUArchGetCheckMode getCheckMode;
virCPUArchGetCanonicalModel getCanonicalModel;
};
@ -324,6 +328,10 @@ virCPUGetCheckMode(virArch arch,
const virCPUDef *cpu,
bool *compat);
const char *
virCPUGetCanonicalModel(virArch arch,
const char *model);
bool
virCPUArchIsSupported(virArch arch);

View File

@ -3697,6 +3697,24 @@ virCPUx86GetCheckMode(const char *modelName,
}
static const char *
virCPUx86GetCanonicalModel(const char *modelName)
{
virCPUx86Map *map;
virCPUx86Model *model;
if (!(map = virCPUx86GetMap()))
return NULL;
model = x86ModelFind(map, modelName);
if (!model || !model->canonical)
return NULL;
return model->canonical->name;
}
struct cpuArchDriver cpuDriverX86 = {
.name = "x86",
.arch = archs,
@ -3730,4 +3748,5 @@ struct cpuArchDriver cpuDriverX86 = {
.dataGetHost = virCPUx86DataGetHost,
#endif
.getCheckMode = virCPUx86GetCheckMode,
.getCanonicalModel = virCPUx86GetCanonicalModel,
};

View File

@ -1543,6 +1543,7 @@ virCPUDataNewCopy;
virCPUDataParse;
virCPUDataParseNode;
virCPUExpandFeatures;
virCPUGetCanonicalModel;
virCPUGetCheckMode;
virCPUGetHost;
virCPUGetHostIsSupported;