render / rpms / libvirt

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