From 2d9d40cfec0aa5db556ca62395671dc340b6bf93 Mon Sep 17 00:00:00 2001
Message-Id: <2d9d40cfec0aa5db556ca62395671dc340b6bf93@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Mon, 9 Oct 2017 16:20:43 +0200
Subject: [PATCH] conf: Introduce virCPUDefFindFeature
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 3276416904393a06df664c5d849ee805d07688d8)
Conflicts:
src/conf/cpu_conf.h - context, two more new function prototypes
in the header file upstream
https://bugzilla.redhat.com/show_bug.cgi?id=1508549
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
src/conf/cpu_conf.c | 40 +++++++++++++++++++++++++++-------------
src/conf/cpu_conf.h | 4 ++++
src/libvirt_private.syms | 1 +
3 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index da40e9ba97..e570dffcd2 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -773,24 +773,22 @@ virCPUDefUpdateFeatureInternal(virCPUDefPtr def,
int policy,
bool update)
{
- size_t i;
+ virCPUFeatureDefPtr feat;
if (def->type == VIR_CPU_TYPE_HOST)
policy = -1;
- for (i = 0; i < def->nfeatures; i++) {
- if (STREQ(name, def->features[i].name)) {
- if (update) {
- def->features[i].policy = policy;
- return 0;
- }
-
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("CPU feature '%s' specified more than once"),
- name);
-
- return -1;
+ if ((feat = virCPUDefFindFeature(def, name))) {
+ if (update) {
+ feat->policy = policy;
+ return 0;
}
+
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("CPU feature '%s' specified more than once"),
+ name);
+
+ return -1;
}
if (VIR_RESIZE_N(def->features, def->nfeatures_max,
@@ -822,6 +820,22 @@ virCPUDefAddFeature(virCPUDefPtr def,
return virCPUDefUpdateFeatureInternal(def, name, policy, false);
}
+
+virCPUFeatureDefPtr
+virCPUDefFindFeature(virCPUDefPtr def,
+ const char *name)
+{
+ size_t i;
+
+ for (i = 0; i < def->nfeatures; i++) {
+ if (STREQ(name, def->features[i].name))
+ return def->features + i;
+ }
+
+ return NULL;
+}
+
+
bool
virCPUDefIsEqual(virCPUDefPtr src,
virCPUDefPtr dst,
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index b44974f47e..1978814d36 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -218,4 +218,8 @@ virCPUDefUpdateFeature(virCPUDefPtr cpu,
const char *name,
int policy);
+virCPUFeatureDefPtr
+virCPUDefFindFeature(virCPUDefPtr def,
+ const char *name);
+
#endif /* __VIR_CPU_CONF_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9c596e3f1c..62ebb8180e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -74,6 +74,7 @@ virCPUDefCopy;
virCPUDefCopyModel;
virCPUDefCopyModelFilter;
virCPUDefCopyWithoutModel;
+virCPUDefFindFeature;
virCPUDefFormat;
virCPUDefFormatBuf;
virCPUDefFormatBufFull;
--
2.15.0