[PATCH 12/32] cpu: Introduce virCPUCheckModel

Jiri Denemark posted 32 patches 2 weeks ago
There is a newer version of this series
[PATCH 12/32] cpu: Introduce virCPUCheckModel
Posted by Jiri Denemark 2 weeks ago
A helper for checking whether a given CPU model is defined in the CPU
map.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/cpu/cpu.c            | 25 +++++++++++++++++++++++++
 src/cpu/cpu.h            |  8 ++++++++
 src/cpu/cpu_x86.c        | 23 +++++++++++++++++++++++
 src/libvirt_private.syms |  1 +
 4 files changed, 57 insertions(+)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 2b0d641e78..a83904f08e 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -1367,3 +1367,28 @@ virCPUArchIsSupported(virArch arch)
 
     return false;
 }
+
+
+/**
+ * virCPUCheckModel:
+ * @arch: CPU architecture
+ * @name: CPU model name
+ *
+ * Checks whether the CPU model exists in the CPU map.
+ *
+ * Returns true if @name is found in the CPU map, false otherwise.
+ */
+bool
+virCPUCheckModel(virArch arch,
+                 const char *name)
+{
+    struct cpuArchDriver *driver;
+
+    if (!(driver = cpuGetSubDriver(arch)))
+        return false;
+
+    if (!driver->checkModel)
+        return false;
+
+    return driver->checkModel(name);
+}
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index ff68c5da2d..19edae6880 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -140,6 +140,9 @@ typedef int
 (*virCPUArchGetCheckMode)(const char *modelName,
                           bool *compat);
 
+typedef bool
+(*virCPUArchCheckModel)(const char *name);
+
 struct cpuArchDriver {
     const char *name;
     const virArch *arch;
@@ -168,6 +171,7 @@ struct cpuArchDriver {
     virCPUArchDataIsIdentical dataIsIdentical;
     virCPUArchDataGetHost dataGetHost;
     virCPUArchGetCheckMode getCheckMode;
+    virCPUArchCheckModel checkModel;
 };
 
 
@@ -327,6 +331,10 @@ virCPUGetCheckMode(virArch arch,
 bool
 virCPUArchIsSupported(virArch arch);
 
+bool
+virCPUCheckModel(virArch arch,
+                 const char *name);
+
 /* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
  * have no real-life usage
  */
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 7cfab8278d..a86e29064a 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3653,6 +3653,28 @@ virCPUx86GetCheckMode(const char *modelName,
 }
 
 
+/**
+ * virCPUx86CheckModel:
+ * @name: CPU model name
+ *
+ * Checks whether the CPU model exists in the CPU map.
+ *
+ * Returns true if @name is found in the CPU map, false otherwise.
+ */
+static bool
+virCPUx86CheckModel(const char *name)
+{
+    virCPUx86Map *map;
+    virCPUx86Model *model;
+
+    if (!(map = virCPUx86GetMap()))
+        return false;
+
+    model = x86ModelFind(map, name);
+    return !!model;
+}
+
+
 struct cpuArchDriver cpuDriverX86 = {
     .name = "x86",
     .arch = archs,
@@ -3686,4 +3708,5 @@ struct cpuArchDriver cpuDriverX86 = {
     .dataGetHost = virCPUx86DataGetHost,
 #endif
     .getCheckMode = virCPUx86GetCheckMode,
+    .checkModel = virCPUx86CheckModel,
 };
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5b9b44ef96..9b863b613e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1527,6 +1527,7 @@ virCPUArchIsSupported;
 virCPUBaseline;
 virCPUCheckFeature;
 virCPUCheckForbiddenFeatures;
+virCPUCheckModel;
 virCPUCompare;
 virCPUCompareUnusable;
 virCPUCompareXML;
-- 
2.47.0
Re: [PATCH 12/32] cpu: Introduce virCPUCheckModel
Posted by Daniel P. Berrangé 1 week, 6 days ago
On Tue, Nov 19, 2024 at 07:49:48PM +0100, Jiri Denemark wrote:
> A helper for checking whether a given CPU model is defined in the CPU
> map.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/cpu/cpu.c            | 25 +++++++++++++++++++++++++
>  src/cpu/cpu.h            |  8 ++++++++
>  src/cpu/cpu_x86.c        | 23 +++++++++++++++++++++++
>  src/libvirt_private.syms |  1 +
>  4 files changed, 57 insertions(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|