[PATCH v2 3/7] cpu_x86: Introduce virCPUx86FeatureIsMSR

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

 



This function may be used as a virCPUDefFeatureFilter callback for
virCPUDefCheckFeatures, virCPUDefFilerFeatures, and similar functions to
filter or pick out features reported via MSR.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/cpu/cpu_x86.c        | 40 ++++++++++++++++++++++++++++++++++++++++
 src/cpu/cpu_x86.h        |  3 +++
 src/libvirt_private.syms |  1 +
 3 files changed, 44 insertions(+)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 6eef5cef00..a7ec0f7095 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3362,6 +3362,46 @@ virCPUx86DataAddFeature(virCPUDataPtr cpuData,
 }
 
 
+/**
+ * virCPUx86FeatureIsMSR:
+ * @name CPU feature name
+ * @opaque NULL or a pointer to bool
+ *
+ * This is a callback for functions filtering features in virCPUDef.
+ *
+ * Checks whether a given CPU feature is reported via MSR. When @opaque is NULL
+ * or a pointer to true, the function will pick out (return true for) MSR
+ * features. If @opaque is a pointer to false, the logic will be inverted and
+ * the function will filter out (return false for) MSR features.
+ */
+bool
+virCPUx86FeatureIsMSR(const char *name,
+                      void *opaque)
+{
+    virCPUx86FeaturePtr feature;
+    virCPUx86DataIterator iter;
+    virCPUx86DataItemPtr item;
+    virCPUx86MapPtr map;
+    bool inverted = false;
+
+    if (opaque)
+        inverted = !*(bool *)opaque;
+
+    if ((!(map = virCPUx86GetMap()) ||
+         !(feature = x86FeatureFind(map, name))) &&
+        !(feature = x86FeatureFindInternal(name)))
+        return inverted ? true : false;
+
+    virCPUx86DataIteratorInit(&iter, &feature->data);
+    while ((item = virCPUx86DataNext(&iter))) {
+        if (item->type == VIR_CPU_X86_DATA_MSR)
+            return inverted ? false : true;
+    }
+
+    return inverted ? true : false;
+}
+
+
 struct cpuArchDriver cpuDriverX86 = {
     .name = "x86",
     .arch = archs,
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index 28ae46647a..8ae78d5e34 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -40,3 +40,6 @@ uint32_t virCPUx86DataGetSignature(virCPUDataPtr cpuData,
 
 int virCPUx86DataSetVendor(virCPUDataPtr cpuData,
                            const char *vendor);
+
+bool virCPUx86FeatureIsMSR(const char *name,
+                           void *opaque);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 90a6d10666..aa64580d63 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1268,6 +1268,7 @@ virCPUx86DataAdd;
 virCPUx86DataGetSignature;
 virCPUx86DataSetSignature;
 virCPUx86DataSetVendor;
+virCPUx86FeatureIsMSR;
 
 
 # datatypes.h
-- 
2.22.0

--
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