cpu: Introduce virCPUGetCheckMode

On x86 the function returns whether an old style compat check mode
should be used for a specified CPU model according to the CPU map. All
other architectures will always use compat mode.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2024-10-09 16:52:08 +02:00
parent cd93f7ddab
commit 5475688a29
4 changed files with 75 additions and 0 deletions

View File

@ -1241,6 +1241,37 @@ virCPUDataGetHost(void)
}
/**
* virCPUGetCheckMode:
* @arch: CPU architecture
* @cpu: CPU definition
* @compat: where to store compatible partial checking is required
*
* Gets the mode required for "partial" check of the CPU definition @cpu
* based on the CPU model used. On success @compat will be set to true if
* a compatible check needs to be done, false otherwise.
*
* Returns 0 on success, -1 otherwise.
*/
int
virCPUGetCheckMode(virArch arch,
const virCPUDef *cpu,
bool *compat)
{
struct cpuArchDriver *driver;
if (!(driver = cpuGetSubDriver(arch)))
return -1;
if (!driver->getCheckMode) {
*compat = true;
return 0;
}
return driver->getCheckMode(cpu->model, compat);
}
/**
* virCPUArchIsSupported:
*

View File

@ -136,6 +136,10 @@ typedef virCPUCompareResult
typedef virCPUData *
(*virCPUArchDataGetHost)(void);
typedef int
(*virCPUArchGetCheckMode)(const char *modelName,
bool *compat);
struct cpuArchDriver {
const char *name;
const virArch *arch;
@ -163,6 +167,7 @@ struct cpuArchDriver {
virCPUArchDataAddFeature dataAddFeature;
virCPUArchDataIsIdentical dataIsIdentical;
virCPUArchDataGetHost dataGetHost;
virCPUArchGetCheckMode getCheckMode;
};
@ -307,6 +312,11 @@ virCPUDataIsIdentical(const virCPUData *a,
virCPUData*
virCPUDataGetHost(void);
int
virCPUGetCheckMode(virArch arch,
const virCPUDef *cpu,
bool *compat);
bool
virCPUArchIsSupported(virArch arch);

View File

@ -3608,6 +3608,38 @@ virCPUx86GetAddedFeatures(const char *modelName,
}
/**
* virCPUx86GetCheckMode:
* @modelName: CPU model
* @compat: where to store compatible partial checking is required
*
* Gets the mode required for "partial" check of a CPU definition which uses
* the @modelName. On success @compat will be set to true if a compatible
* check needs to be done, false otherwise.
*
* Returns 0 on success, -1 otherwise.
*/
static int
virCPUx86GetCheckMode(const char *modelName,
bool *compat)
{
virCPUx86Map *map;
virCPUx86Model *model;
if (!(map = virCPUx86GetMap()))
return -1;
if (!(model = x86ModelFind(map, modelName))) {
virReportError(VIR_ERR_INVALID_ARG,
_("unknown CPU model %1$s"), modelName);
return -1;
}
*compat = model->compatCheck;
return 0;
}
struct cpuArchDriver cpuDriverX86 = {
.name = "x86",
.arch = archs,
@ -3640,4 +3672,5 @@ struct cpuArchDriver cpuDriverX86 = {
(defined(__linux__) || defined(__FreeBSD__))
.dataGetHost = virCPUx86DataGetHost,
#endif
.getCheckMode = virCPUx86GetCheckMode,
};

View File

@ -1538,6 +1538,7 @@ virCPUDataNewCopy;
virCPUDataParse;
virCPUDataParseNode;
virCPUExpandFeatures;
virCPUGetCheckMode;
virCPUGetHost;
virCPUGetHostIsSupported;
virCPUGetModels;