This new internal API can be used for in place filtering of CPU features
in virCPUDef.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/conf/cpu_conf.c | 22 ++++++++++++++++++++++
src/conf/cpu_conf.h | 5 +++++
src/libvirt_private.syms | 1 +
3 files changed, 28 insertions(+)
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 825df88246..675d214c50 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -908,6 +908,28 @@ virCPUDefFindFeature(virCPUDefPtr def,
}
+int
+virCPUDefFilterFeatures(virCPUDefPtr cpu,
+ virCPUDefFeatureFilter filter,
+ void *opaque)
+{
+ size_t i = 0;
+
+ while (i < cpu->nfeatures) {
+ if (filter(cpu->features[i].name, opaque)) {
+ i++;
+ continue;
+ }
+
+ VIR_FREE(cpu->features[i].name);
+ if (VIR_DELETE_ELEMENT_INPLACE(cpu->features, i, cpu->nfeatures) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+
bool
virCPUDefIsEqual(virCPUDefPtr src,
virCPUDefPtr dst,
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 562e0de531..906ef5368e 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -219,6 +219,11 @@ virCPUFeatureDefPtr
virCPUDefFindFeature(virCPUDefPtr def,
const char *name);
+int
+virCPUDefFilterFeatures(virCPUDefPtr cpu,
+ virCPUDefFeatureFilter filter,
+ void *opaque);
+
virCPUDefPtr *
virCPUDefListParse(const char **xmlCPUs,
unsigned int ncpus,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0e6a39b59b..228cd929b4 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -77,6 +77,7 @@ virCPUDefCopy;
virCPUDefCopyModel;
virCPUDefCopyModelFilter;
virCPUDefCopyWithoutModel;
+virCPUDefFilterFeatures;
virCPUDefFindFeature;
virCPUDefFormat;
virCPUDefFormatBuf;
--
2.22.0