c313de
From 0bed2e17ea6469ccabb374c0520a97706b281911 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <0bed2e17ea6469ccabb374c0520a97706b281911@dist-git>
c313de
From: Jiri Denemark <jdenemar@redhat.com>
c313de
Date: Fri, 21 Jun 2019 09:26:06 +0200
c313de
Subject: [PATCH] conf: Introduce virCPUDefCheckFeatures
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
This API can be used to check whether a CPU definition contains features
c313de
matching a given filter.
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
(cherry picked from commit 4e6f58b8d55d44fa9f80736b2745b44710f6e25a)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
c313de
c313de
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c313de
Message-Id: <ea489f203e2d52250acb1b9656de6aba8355f3a6.1561068591.git.jdenemar@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/conf/cpu_conf.c      | 33 +++++++++++++++++++++++++++++++++
c313de
 src/conf/cpu_conf.h      |  6 ++++++
c313de
 src/libvirt_private.syms |  1 +
c313de
 3 files changed, 40 insertions(+)
c313de
c313de
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
c313de
index 51e2a83eae..4cccea9981 100644
c313de
--- a/src/conf/cpu_conf.c
c313de
+++ b/src/conf/cpu_conf.c
c313de
@@ -872,6 +872,39 @@ virCPUDefFilterFeatures(virCPUDefPtr cpu,
c313de
 }
c313de
 
c313de
 
c313de
+/**
c313de
+ * virCPUDefCheckFeatures:
c313de
+ *
c313de
+ * Check CPU features for which @filter reports true and store them in a NULL
c313de
+ * terminated list returned via @features.
c313de
+ *
c313de
+ * Returns the number of features matching @filter or -1 on error.
c313de
+ */
c313de
+int
c313de
+virCPUDefCheckFeatures(virCPUDefPtr cpu,
c313de
+                       virCPUDefFeatureFilter filter,
c313de
+                       void *opaque,
c313de
+                       char ***features)
c313de
+{
c313de
+    VIR_AUTOSTRINGLIST list = NULL;
c313de
+    size_t n = 0;
c313de
+    size_t i;
c313de
+
c313de
+    *features = NULL;
c313de
+
c313de
+    for (i = 0; i < cpu->nfeatures; i++) {
c313de
+        if (filter(cpu->features[i].name, opaque)) {
c313de
+            if (virStringListAdd(&list, cpu->features[i].name) < 0)
c313de
+                return -1;
c313de
+            n++;
c313de
+        }
c313de
+    }
c313de
+
c313de
+    VIR_STEAL_PTR(*features, list);
c313de
+    return n;
c313de
+}
c313de
+
c313de
+
c313de
 bool
c313de
 virCPUDefIsEqual(virCPUDefPtr src,
c313de
                  virCPUDefPtr dst,
c313de
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
c313de
index ad25932b9b..cba0ec7c81 100644
c313de
--- a/src/conf/cpu_conf.h
c313de
+++ b/src/conf/cpu_conf.h
c313de
@@ -225,6 +225,12 @@ virCPUDefFilterFeatures(virCPUDefPtr cpu,
c313de
                         virCPUDefFeatureFilter filter,
c313de
                         void *opaque);
c313de
 
c313de
+int
c313de
+virCPUDefCheckFeatures(virCPUDefPtr cpu,
c313de
+                       virCPUDefFeatureFilter filter,
c313de
+                       void *opaque,
c313de
+                       char ***features);
c313de
+
c313de
 virCPUDefPtr *
c313de
 virCPUDefListParse(const char **xmlCPUs,
c313de
                    unsigned int ncpus,
c313de
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c313de
index 06374deaae..0290f960a0 100644
c313de
--- a/src/libvirt_private.syms
c313de
+++ b/src/libvirt_private.syms
c313de
@@ -72,6 +72,7 @@ virCapabilitiesSetNetPrefix;
c313de
 virCPUCacheModeTypeFromString;
c313de
 virCPUCacheModeTypeToString;
c313de
 virCPUDefAddFeature;
c313de
+virCPUDefCheckFeatures;
c313de
 virCPUDefCopy;
c313de
 virCPUDefCopyModel;
c313de
 virCPUDefCopyModelFilter;
c313de
-- 
c313de
2.22.0
c313de