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(a)redhat.com>
---
src/cpu/cpu.c | 31 +++++++++++++++++++++++++++++++
src/cpu/cpu.h | 10 ++++++++++
src/cpu/cpu_x86.c | 33 +++++++++++++++++++++++++++++++++
src/libvirt_private.syms | 1 +
4 files changed, 75 insertions(+)
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index a2518d7cc7..1734561215 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -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:
*
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index d092b4f3f0..ceb6eb0944 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -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);
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 70893f8a62..97d6e00007 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -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,
};
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e09fb98596..551cea989b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1538,6 +1538,7 @@ virCPUDataNewCopy;
virCPUDataParse;
virCPUDataParseNode;
virCPUExpandFeatures;
+virCPUGetCheckMode;
virCPUGetHost;
virCPUGetHostIsSupported;
virCPUGetModels;
--
2.47.0