render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From 8d2f5155be8834db501930716e2cd2e1be14785c Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <8d2f5155be8834db501930716e2cd2e1be14785c@dist-git>
Pablo Greco 40546a
From: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Date: Fri, 21 Jun 2019 09:24:57 +0200
Pablo Greco 40546a
Subject: [PATCH] cpu_x86: Separate feature list parsing from x86ModelParse
Pablo Greco 40546a
MIME-Version: 1.0
Pablo Greco 40546a
Content-Type: text/plain; charset=UTF-8
Pablo Greco 40546a
Content-Transfer-Encoding: 8bit
Pablo Greco 40546a
Pablo Greco 40546a
The code is separated into a new x86ModelParseFeatures function.
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
(cherry picked from commit 8d249df9c917040d180202343e5cf7f70c3e4fe1)
Pablo Greco 40546a
Pablo Greco 40546a
https://bugzilla.redhat.com/show_bug.cgi?id=1686895
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Message-Id: <5a741350b39394a93aee99a3b98142548936bc2d.1561068591.git.jdenemar@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/cpu/cpu_x86.c | 68 +++++++++++++++++++++++++++--------------------
Pablo Greco 40546a
 1 file changed, 39 insertions(+), 29 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
Pablo Greco 40546a
index 62894cae9b..91362198ab 100644
Pablo Greco 40546a
--- a/src/cpu/cpu_x86.c
Pablo Greco 40546a
+++ b/src/cpu/cpu_x86.c
Pablo Greco 40546a
@@ -1247,16 +1247,51 @@ x86ModelParseVendor(virCPUx86ModelPtr model,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+x86ModelParseFeatures(virCPUx86ModelPtr model,
Pablo Greco 40546a
+                      xmlXPathContextPtr ctxt,
Pablo Greco 40546a
+                      virCPUx86MapPtr map)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
Pablo Greco 40546a
+    size_t i;
Pablo Greco 40546a
+    int n;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) <= 0)
Pablo Greco 40546a
+        return n;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    for (i = 0; i < n; i++) {
Pablo Greco 40546a
+        VIR_AUTOFREE(char *) ftname = NULL;
Pablo Greco 40546a
+        virCPUx86FeaturePtr feature;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if (!(ftname = virXMLPropString(nodes[i], "name"))) {
Pablo Greco 40546a
+            virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                           _("Missing feature name for CPU model %s"),
Pablo Greco 40546a
+                           model->name);
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if (!(feature = x86FeatureFind(map, ftname))) {
Pablo Greco 40546a
+            virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                           _("Feature %s required by CPU model %s not found"),
Pablo Greco 40546a
+                           ftname, model->name);
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if (x86DataAdd(&model->data, &feature->data))
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return 0;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 static int
Pablo Greco 40546a
 x86ModelParse(xmlXPathContextPtr ctxt,
Pablo Greco 40546a
               const char *name,
Pablo Greco 40546a
               void *data)
Pablo Greco 40546a
 {
Pablo Greco 40546a
     virCPUx86MapPtr map = data;
Pablo Greco 40546a
-    xmlNodePtr *nodes = NULL;
Pablo Greco 40546a
     virCPUx86ModelPtr model;
Pablo Greco 40546a
-    size_t i;
Pablo Greco 40546a
-    int n;
Pablo Greco 40546a
     int ret = -1;
Pablo Greco 40546a
 
Pablo Greco 40546a
     if (!(model = x86ModelNew()))
Pablo Greco 40546a
@@ -1274,33 +1309,9 @@ x86ModelParse(xmlXPathContextPtr ctxt,
Pablo Greco 40546a
     if (x86ModelParseVendor(model, ctxt, map) < 0)
Pablo Greco 40546a
         goto cleanup;
Pablo Greco 40546a
 
Pablo Greco 40546a
-    n = virXPathNodeSet("./feature", ctxt, &nodes);
Pablo Greco 40546a
-    if (n < 0)
Pablo Greco 40546a
+    if (x86ModelParseFeatures(model, ctxt, map) < 0)
Pablo Greco 40546a
         goto cleanup;
Pablo Greco 40546a
 
Pablo Greco 40546a
-    for (i = 0; i < n; i++) {
Pablo Greco 40546a
-        virCPUx86FeaturePtr feature;
Pablo Greco 40546a
-        char *ftname;
Pablo Greco 40546a
-
Pablo Greco 40546a
-        if (!(ftname = virXMLPropString(nodes[i], "name"))) {
Pablo Greco 40546a
-            virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                           _("Missing feature name for CPU model %s"), model->name);
Pablo Greco 40546a
-            goto cleanup;
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-
Pablo Greco 40546a
-        if (!(feature = x86FeatureFind(map, ftname))) {
Pablo Greco 40546a
-            virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                           _("Feature %s required by CPU model %s not found"),
Pablo Greco 40546a
-                           ftname, model->name);
Pablo Greco 40546a
-            VIR_FREE(ftname);
Pablo Greco 40546a
-            goto cleanup;
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-        VIR_FREE(ftname);
Pablo Greco 40546a
-
Pablo Greco 40546a
-        if (x86DataAdd(&model->data, &feature->data))
Pablo Greco 40546a
-            goto cleanup;
Pablo Greco 40546a
-    }
Pablo Greco 40546a
-
Pablo Greco 40546a
     if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
Pablo Greco 40546a
         goto cleanup;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -1308,7 +1319,6 @@ x86ModelParse(xmlXPathContextPtr ctxt,
Pablo Greco 40546a
 
Pablo Greco 40546a
  cleanup:
Pablo Greco 40546a
     x86ModelFree(model);
Pablo Greco 40546a
-    VIR_FREE(nodes);
Pablo Greco 40546a
     return ret;
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a