[PATCH 1/4] cpu: Introduce virCPUValidateFeatures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/cpu/cpu.c            | 29 +++++++++++++++++++++++++++++
 src/cpu/cpu.h            |  9 +++++++++
 src/libvirt_private.syms |  1 +
 3 files changed, 39 insertions(+)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index a7c7c381b9..dc72ed42d8 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -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;
+}
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 5dda46ee70..5daff186c4 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -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
  */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 888e4e329b..6670c5fc92 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1097,6 +1097,7 @@ virCPUProbeHost;
 virCPUTranslate;
 virCPUUpdate;
 virCPUUpdateLive;
+virCPUValidateFeatures;
 
 
 # cpu/cpu_x86.h
-- 
2.14.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux