[libvirt] [PATCH 1/6] cpu_conf: Pass policy to CPU feature filtering callbacks

Jiri Denemark posted 6 patches 5 years ago
[libvirt] [PATCH 1/6] cpu_conf: Pass policy to CPU feature filtering callbacks
Posted by Jiri Denemark 5 years ago
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/cpu_conf.c          |  6 +++---
 src/conf/cpu_conf.h          |  1 +
 src/cpu/cpu_x86.c            | 13 ++++++++++++-
 src/cpu/cpu_x86.h            |  2 ++
 src/qemu/qemu_capabilities.c |  1 +
 src/qemu/qemu_capabilities.h |  1 +
 6 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 2b644638a7..a38101d024 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -147,7 +147,7 @@ virCPUDefCopyModelFilter(virCPUDefPtr dst,
     dst->nfeatures = 0;
 
     for (i = 0; i < src->nfeatures; i++) {
-        if (filter && !filter(src->features[i].name, opaque))
+        if (filter && !filter(src->features[i].name, src->features[i].policy, opaque))
             continue;
 
         n = dst->nfeatures++;
@@ -937,7 +937,7 @@ virCPUDefFilterFeatures(virCPUDefPtr cpu,
     size_t i = 0;
 
     while (i < cpu->nfeatures) {
-        if (filter(cpu->features[i].name, opaque)) {
+        if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)) {
             i++;
             continue;
         }
@@ -972,7 +972,7 @@ virCPUDefCheckFeatures(virCPUDefPtr cpu,
     *features = NULL;
 
     for (i = 0; i < cpu->nfeatures; i++) {
-        if (filter(cpu->features[i].name, opaque)) {
+        if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)) {
             if (virStringListAdd(&list, cpu->features[i].name) < 0)
                 return -1;
             n++;
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 30904fab95..a9f8abeef1 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -161,6 +161,7 @@ virCPUDefCopyModel(virCPUDefPtr dst,
  * Returns true if feature @name should copied, false otherwise.
  */
 typedef bool (*virCPUDefFeatureFilter)(const char *name,
+                                       virCPUFeaturePolicy policy,
                                        void *opaque);
 
 int
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index abe4865ec2..db34cbdb5c 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3238,6 +3238,15 @@ virCPUx86ExpandFeatures(virCPUDefPtr cpu)
 }
 
 
+static bool
+x86FeatureFilterMigratable(const char *name,
+                           virCPUFeaturePolicy policy G_GNUC_UNUSED,
+                           void *cpu_map)
+{
+    return x86FeatureIsMigratable(name, cpu_map);
+}
+
+
 static virCPUDefPtr
 virCPUx86CopyMigratable(virCPUDefPtr cpu)
 {
@@ -3251,7 +3260,7 @@ virCPUx86CopyMigratable(virCPUDefPtr cpu)
         return NULL;
 
     if (virCPUDefCopyModelFilter(copy, cpu, false,
-                                 x86FeatureIsMigratable, map) < 0)
+                                 x86FeatureFilterMigratable, map) < 0)
         goto error;
 
     return copy;
@@ -3386,6 +3395,7 @@ virCPUx86FeatureIsMSR(const char *name)
  */
 bool
 virCPUx86FeatureFilterSelectMSR(const char *name,
+                                virCPUFeaturePolicy policy G_GNUC_UNUSED,
                                 void *opaque G_GNUC_UNUSED)
 {
     return virCPUx86FeatureIsMSR(name);
@@ -3402,6 +3412,7 @@ virCPUx86FeatureFilterSelectMSR(const char *name,
  */
 bool
 virCPUx86FeatureFilterDropMSR(const char *name,
+                              virCPUFeaturePolicy policy G_GNUC_UNUSED,
                               void *opaque G_GNUC_UNUSED)
 {
     return !virCPUx86FeatureIsMSR(name);
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index 3ea38d1701..3b1aabe98d 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -42,7 +42,9 @@ int virCPUx86DataSetVendor(virCPUDataPtr cpuData,
                            const char *vendor);
 
 bool virCPUx86FeatureFilterSelectMSR(const char *name,
+                                     virCPUFeaturePolicy policy,
                                      void *opaque);
 
 bool virCPUx86FeatureFilterDropMSR(const char *name,
+                                   virCPUFeaturePolicy policy,
                                    void *opaque);
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index fc6473651c..29e2d6d5d7 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2910,6 +2910,7 @@ virQEMUCapsProbeQMPSEVCapabilities(virQEMUCapsPtr qemuCaps,
  */
 bool
 virQEMUCapsCPUFilterFeatures(const char *name,
+                             virCPUFeaturePolicy policy G_GNUC_UNUSED,
                              void *opaque)
 {
     virArch *arch = opaque;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 32e9798cda..aa593396ce 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -667,6 +667,7 @@ bool virQEMUCapsGuestIsNative(virArch host,
                               virArch guest);
 
 bool virQEMUCapsCPUFilterFeatures(const char *name,
+                                  virCPUFeaturePolicy policy,
                                   void *opaque);
 
 const char *
-- 
2.24.0

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