]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Introduce virCPUGetCheckMode
authorJiri Denemark <jdenemar@redhat.com>
Wed, 9 Oct 2024 14:52:08 +0000 (16:52 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 23 Oct 2024 14:00:44 +0000 (16:00 +0200)
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>
src/cpu/cpu.c
src/cpu/cpu.h
src/cpu/cpu_x86.c
src/libvirt_private.syms

index a2518d7cc7b35adc981ab5990e0977ceac23960f..17345612157508d5260ec492b4499cb158d13c7b 100644 (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:
  *
index d092b4f3f0653f168ae54e981fd353199d597c8b..ceb6eb09442d9a9d473a3ddcdfc3f958e10de68e 100644 (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);
 
index 70893f8a62fca5c83a79b7dae3aea77e8547ae9c..97d6e00007817c567383f05c55fbd1969985f121 100644 (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,
 };
index e09fb98596e240a2e9951eb84ed8a3a1ddf9189f..551cea989bef543b6ebda3c878a0ace53c0f95c7 100644 (file)
@@ -1538,6 +1538,7 @@ virCPUDataNewCopy;
 virCPUDataParse;
 virCPUDataParseNode;
 virCPUExpandFeatures;
+virCPUGetCheckMode;
 virCPUGetHost;
 virCPUGetHostIsSupported;
 virCPUGetModels;