render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
Pablo Greco 40546a
From e1b42297bc41c8f356693f2756e806a8c7275f4f Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <e1b42297bc41c8f356693f2756e806a8c7275f4f@dist-git>
Pablo Greco 40546a
From: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Date: Fri, 21 Jun 2019 09:24:56 +0200
Pablo Greco 40546a
Subject: [PATCH] cpu_x86: Separate vendor 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 x86ModelParseVendor 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 232266839c994dcf2958f1efdfe74cfb7973a749)
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: <aaa0e5fac04ccd7b267e6912ceb3308249d9217e.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 | 50 ++++++++++++++++++++++++++++++-----------------
Pablo Greco 40546a
 1 file changed, 32 insertions(+), 18 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 119ece4758..62894cae9b 100644
Pablo Greco 40546a
--- a/src/cpu/cpu_x86.c
Pablo Greco 40546a
+++ b/src/cpu/cpu_x86.c
Pablo Greco 40546a
@@ -1217,6 +1217,36 @@ x86ModelParseSignature(virCPUx86ModelPtr model,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+x86ModelParseVendor(virCPUx86ModelPtr model,
Pablo Greco 40546a
+                    xmlXPathContextPtr ctxt,
Pablo Greco 40546a
+                    virCPUx86MapPtr map)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    VIR_AUTOFREE(char *) vendor = NULL;
Pablo Greco 40546a
+    int rc;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if ((rc = virXPathBoolean("boolean(./vendor)", ctxt)) <= 0)
Pablo Greco 40546a
+        return rc;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    vendor = virXPathString("string(./vendor/@name)", ctxt);
Pablo Greco 40546a
+    if (!vendor) {
Pablo Greco 40546a
+        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                       _("Invalid vendor element in CPU model %s"),
Pablo Greco 40546a
+                       model->name);
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (!(model->vendor = x86VendorFind(map, vendor))) {
Pablo Greco 40546a
+        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                       _("Unknown vendor %s referenced by CPU model %s"),
Pablo Greco 40546a
+                       vendor, model->name);
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
@@ -1225,7 +1255,6 @@ x86ModelParse(xmlXPathContextPtr ctxt,
Pablo Greco 40546a
     virCPUx86MapPtr map = data;
Pablo Greco 40546a
     xmlNodePtr *nodes = NULL;
Pablo Greco 40546a
     virCPUx86ModelPtr model;
Pablo Greco 40546a
-    char *vendor = NULL;
Pablo Greco 40546a
     size_t i;
Pablo Greco 40546a
     int n;
Pablo Greco 40546a
     int ret = -1;
Pablo Greco 40546a
@@ -1242,22 +1271,8 @@ x86ModelParse(xmlXPathContextPtr ctxt,
Pablo Greco 40546a
     if (x86ModelParseSignature(model, ctxt) < 0)
Pablo Greco 40546a
         goto cleanup;
Pablo Greco 40546a
 
Pablo Greco 40546a
-    if (virXPathBoolean("boolean(./vendor)", ctxt)) {
Pablo Greco 40546a
-        vendor = virXPathString("string(./vendor/@name)", ctxt);
Pablo Greco 40546a
-        if (!vendor) {
Pablo Greco 40546a
-            virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                           _("Invalid vendor element in CPU model %s"),
Pablo Greco 40546a
-                           model->name);
Pablo Greco 40546a
-            goto cleanup;
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-
Pablo Greco 40546a
-        if (!(model->vendor = x86VendorFind(map, vendor))) {
Pablo Greco 40546a
-            virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                           _("Unknown vendor %s referenced by CPU model %s"),
Pablo Greco 40546a
-                           vendor, model->name);
Pablo Greco 40546a
-            goto cleanup;
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-    }
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
@@ -1293,7 +1308,6 @@ x86ModelParse(xmlXPathContextPtr ctxt,
Pablo Greco 40546a
 
Pablo Greco 40546a
  cleanup:
Pablo Greco 40546a
     x86ModelFree(model);
Pablo Greco 40546a
-    VIR_FREE(vendor);
Pablo Greco 40546a
     VIR_FREE(nodes);
Pablo Greco 40546a
     return ret;
Pablo Greco 40546a
 }
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a