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