render / rpms / libvirt

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