]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Introduce virCPUValidateFeatures
authorJiri Denemark <jdenemar@redhat.com>
Thu, 14 Sep 2017 14:04:13 +0000 (16:04 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 18 Sep 2017 08:40:12 +0000 (10:40 +0200)
This new API may be used to check whether all features used in a CPU
definition are valid (e.g., libvirt knows their name, their policy is
supported, etc.). Leaving this API unimplemented in an arch subdriver
means libvirt does not restrict CPU features usable on the associated
architectures.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/cpu/cpu.c
src/cpu/cpu.h
src/libvirt_private.syms

index a7c7c381b9c977eaf65884c1e8c45af9d8211853..dc72ed42d837772b9f97264e60e9feebb8214fec 100644 (file)
@@ -1076,3 +1076,32 @@ virCPUCopyMigratable(virArch arch,
     else
         return virCPUDefCopy(cpu);
 }
+
+
+/**
+ * virCPUValidateFeatures:
+ *
+ * @arch: CPU architecture
+ * @cpu: CPU definition to be checked
+ *
+ * Checks whether all CPU features specified in @cpu are valid.
+ *
+ * Returns 0 on success (all features are valid), -1 on error.
+ */
+int
+virCPUValidateFeatures(virArch arch,
+                       virCPUDefPtr cpu)
+{
+    struct cpuArchDriver *driver;
+
+    VIR_DEBUG("arch=%s, cpu=%p, nfeatures=%zu",
+              virArchToString(arch), cpu, cpu->nfeatures);
+
+    if (!(driver = cpuGetSubDriver(arch)))
+        return -1;
+
+    if (driver->validateFeatures)
+        return driver->validateFeatures(cpu);
+    else
+        return 0;
+}
index 5dda46ee708b476f9812364c0ee2241a0c900a4a..5daff186c494c7c1a122e5a5ca09309e13d3a227 100644 (file)
@@ -121,6 +121,9 @@ typedef int
 typedef virCPUDefPtr
 (*virCPUArchCopyMigratable)(virCPUDefPtr cpu);
 
+typedef int
+(*virCPUArchValidateFeatures)(virCPUDefPtr cpu);
+
 struct cpuArchDriver {
     const char *name;
     const virArch *arch;
@@ -142,6 +145,7 @@ struct cpuArchDriver {
     virCPUArchConvertLegacy convertLegacy;
     virCPUArchExpandFeatures expandFeatures;
     virCPUArchCopyMigratable copyMigratable;
+    virCPUArchValidateFeatures validateFeatures;
 };
 
 
@@ -258,6 +262,11 @@ virCPUDefPtr
 virCPUCopyMigratable(virArch arch,
                      virCPUDefPtr cpu);
 
+int
+virCPUValidateFeatures(virArch arch,
+                       virCPUDefPtr cpu)
+    ATTRIBUTE_NONNULL(2);
+
 /* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and
  * have no real-life usage
  */
index df9db78c65f8d62b3723fd56dcd399d2da9d2350..d12db9b3ff5aa83395d8314615e859aa91b2ea8f 100644 (file)
@@ -1097,6 +1097,7 @@ virCPUProbeHost;
 virCPUTranslate;
 virCPUUpdate;
 virCPUUpdateLive;
+virCPUValidateFeatures;
 
 
 # cpu/cpu_x86.h