[PATCH 2/4] cpu: Add virCPUDefUpdateFeature()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This new function updates or adds a feature to a existing cpu model
definition. This function will be helpful to allow tuning of
"host-model" features in later patches.
---
 src/conf/cpu_conf.c      | 38 ++++++++++++++++++++++++++++++--------
 src/conf/cpu_conf.h      |  5 +++++
 src/libvirt_private.syms |  1 +
 3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index e313cad..40fed96 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -656,19 +656,28 @@ virCPUDefFormatBuf(virBufferPtr buf,
     return 0;
 }

-
-int
-virCPUDefAddFeature(virCPUDefPtr def,
-                    const char *name,
-                    int policy)
+static int
+virCPUDefUpdateFeatureInternal(virCPUDefPtr def,
+                               const char *name,
+                               int policy,
+                               bool update)
 {
     size_t i;

+    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;
         }
     }
@@ -677,9 +686,6 @@ virCPUDefAddFeature(virCPUDefPtr def,
                      def->nfeatures, 1) < 0)
         return -1;

-    if (def->type == VIR_CPU_TYPE_HOST)
-        policy = -1;
-
     if (VIR_STRDUP(def->features[def->nfeatures].name, name) < 0)
         return -1;

@@ -689,6 +695,22 @@ virCPUDefAddFeature(virCPUDefPtr def,
     return 0;
 }

+int
+virCPUDefUpdateFeature(virCPUDefPtr def,
+                       const char *name,
+                       int policy)
+{
+    return virCPUDefUpdateFeatureInternal(def, name, policy, true);
+}
+
+int
+virCPUDefAddFeature(virCPUDefPtr def,
+                    const char *name,
+                    int policy)
+{
+    return virCPUDefUpdateFeatureInternal(def, name, policy, false);
+}
+
 bool
 virCPUDefIsEqual(virCPUDefPtr src,
                  virCPUDefPtr dst)
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 23ea455..2d1854f 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -164,4 +164,9 @@ virCPUDefAddFeature(virCPUDefPtr cpu,
                     const char *name,
                     int policy);

+int
+virCPUDefUpdateFeature(virCPUDefPtr cpu,
+                       const char *name,
+                       int policy);
+
 #endif /* __VIR_CPU_CONF_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0ab7632..3c27041 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -70,6 +70,7 @@ virCPUDefFormatBuf;
 virCPUDefFree;
 virCPUDefFreeModel;
 virCPUDefParseXML;
+virCPUDefUpdateFeature;
 virCPUModeTypeToString;


-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]