render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 4111804c77930ebcda4fa5fae751074f75da4f1c Mon Sep 17 00:00:00 2001
Message-Id: <4111804c77930ebcda4fa5fae751074f75da4f1c@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 21 Jun 2019 09:24:54 +0200
Subject: [PATCH] cpu_x86: Separate ancestor model parsing from x86ModelParse
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The code is separated into a new x86ModelParseAncestor function.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 2e1e2b910c6a9d31f2fb6d388ed72dc8f561b845)

https://bugzilla.redhat.com/show_bug.cgi?id=1686895

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <0e941dce0077eb7d7a31dffa60f7d647d66b95e6.1561068591.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/cpu/cpu_x86.c | 65 +++++++++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 27 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index ce48ca6867..64788d60b3 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1148,6 +1148,42 @@ x86ModelCompare(virCPUx86ModelPtr model1,
 }
 
 
+static int
+x86ModelParseAncestor(virCPUx86ModelPtr model,
+                      xmlXPathContextPtr ctxt,
+                      virCPUx86MapPtr map)
+{
+    VIR_AUTOFREE(char *) name = NULL;
+    virCPUx86ModelPtr ancestor;
+    int rc;
+
+    if ((rc = virXPathBoolean("boolean(./model)", ctxt)) <= 0)
+        return rc;
+
+    name = virXPathString("string(./model/@name)", ctxt);
+    if (!name) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Missing ancestor's name in CPU model %s"),
+                       model->name);
+        return -1;
+    }
+
+    if (!(ancestor = x86ModelFind(map, name))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Ancestor model %s not found for CPU model %s"),
+                       name, model->name);
+        return -1;
+    }
+
+    model->vendor = ancestor->vendor;
+    model->signature = ancestor->signature;
+    if (x86DataCopy(&model->data, &ancestor->data) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 x86ModelParse(xmlXPathContextPtr ctxt,
               const char *name,
@@ -1167,33 +1203,8 @@ x86ModelParse(xmlXPathContextPtr ctxt,
     if (VIR_STRDUP(model->name, name) < 0)
         goto cleanup;
 
-    if (virXPathNode("./model", ctxt)) {
-        virCPUx86ModelPtr ancestor;
-        char *anname;
-
-        anname = virXPathString("string(./model/@name)", ctxt);
-        if (!anname) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Missing ancestor's name in CPU model %s"),
-                           model->name);
-            goto cleanup;
-        }
-
-        if (!(ancestor = x86ModelFind(map, anname))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Ancestor model %s not found for CPU model %s"),
-                           anname, model->name);
-            VIR_FREE(anname);
-            goto cleanup;
-        }
-
-        VIR_FREE(anname);
-
-        model->vendor = ancestor->vendor;
-        model->signature = ancestor->signature;
-        if (x86DataCopy(&model->data, &ancestor->data) < 0)
-            goto cleanup;
-    }
+    if (x86ModelParseAncestor(model, ctxt, map) < 0)
+        goto cleanup;
 
     if (virXPathBoolean("boolean(./signature)", ctxt)) {
         unsigned int sigFamily = 0;
-- 
2.22.0