This new function adds a feature to a CPU definition only if it is not
present there yet.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/conf/cpu_conf.c | 14 ++++++++++++++
src/conf/cpu_conf.h | 5 +++++
src/libvirt_private.syms | 1 +
3 files changed, 20 insertions(+)
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 2367d36c32..5ff87cb41c 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -861,6 +861,7 @@ virCPUDefFormatBuf(virBufferPtr buf,
typedef enum {
VIR_CPU_ADD_FEATURE_MODE_EXCLUSIVE, /* Fail if feature exists */
VIR_CPU_ADD_FEATURE_MODE_UPDATE, /* Add feature or update policy */
+ VIR_CPU_ADD_FEATURE_MODE_NEW, /* Add feature if it does not exist */
} virCPUDefAddFeatureMode;
static int
@@ -876,6 +877,9 @@ virCPUDefAddFeatureInternal(virCPUDefPtr def,
if ((feat = virCPUDefFindFeature(def, name))) {
switch (mode) {
+ case VIR_CPU_ADD_FEATURE_MODE_NEW:
+ return 0;
+
case VIR_CPU_ADD_FEATURE_MODE_UPDATE:
feat->policy = policy;
return 0;
@@ -920,6 +924,16 @@ virCPUDefAddFeature(virCPUDefPtr def,
}
+int
+virCPUDefAddFeatureIfMissing(virCPUDefPtr def,
+ const char *name,
+ int policy)
+{
+ return virCPUDefAddFeatureInternal(def, name, policy,
+ VIR_CPU_ADD_FEATURE_MODE_NEW);
+}
+
+
virCPUFeatureDefPtr
virCPUDefFindFeature(virCPUDefPtr def,
const char *name)
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 3ef14b7932..b744b06c2d 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -229,6 +229,11 @@ virCPUDefUpdateFeature(virCPUDefPtr cpu,
const char *name,
int policy);
+int
+virCPUDefAddFeatureIfMissing(virCPUDefPtr def,
+ const char *name,
+ int policy);
+
virCPUFeatureDefPtr
virCPUDefFindFeature(virCPUDefPtr def,
const char *name);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 79a23f34cb..f5a8209efd 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -96,6 +96,7 @@ virDomainCheckpointTypeToString;
virCPUCacheModeTypeFromString;
virCPUCacheModeTypeToString;
virCPUDefAddFeature;
+virCPUDefAddFeatureIfMissing;
virCPUDefCheckFeatures;
virCPUDefCopy;
virCPUDefCopyModel;
--
2.29.2