render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
Pablo Greco 40546a
From 6438640b53fef3e889c21a2ed016638b91c5ac80 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <6438640b53fef3e889c21a2ed016638b91c5ac80@dist-git>
Pablo Greco 40546a
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Pablo Greco 40546a
Date: Fri, 21 Jun 2019 09:24:44 +0200
Pablo Greco 40546a
Subject: [PATCH] cpu: allow include files for CPU definition
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
Allow for syntax
Pablo Greco 40546a
Pablo Greco 40546a
    <include filename="subdir/fooo.xml"/>
Pablo Greco 40546a
Pablo Greco 40546a
to reference other files in the CPU database directory
Pablo Greco 40546a
Pablo Greco 40546a
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Pablo Greco 40546a
(cherry picked from commit eda5f575f2a7530fc7f6471f88496778a9bc9fcb)
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: <800e5ebbc30502fd780a3ef84fe524f1dc0ffd67.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_map.c | 92 +++++++++++++++++++++++++++++++++++++++++++++--
Pablo Greco 40546a
 1 file changed, 89 insertions(+), 3 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
Pablo Greco 40546a
index d263eb8cdd..333c7ef24f 100644
Pablo Greco 40546a
--- a/src/cpu/cpu_map.c
Pablo Greco 40546a
+++ b/src/cpu/cpu_map.c
Pablo Greco 40546a
@@ -1,7 +1,7 @@
Pablo Greco 40546a
 /*
Pablo Greco 40546a
  * cpu_map.c: internal functions for handling CPU mapping configuration
Pablo Greco 40546a
  *
Pablo Greco 40546a
- * Copyright (C) 2009-2010 Red Hat, Inc.
Pablo Greco 40546a
+ * Copyright (C) 2009-2018 Red Hat, Inc.
Pablo Greco 40546a
  *
Pablo Greco 40546a
  * This library is free software; you can redistribute it and/or
Pablo Greco 40546a
  * modify it under the terms of the GNU Lesser General Public
Pablo Greco 40546a
@@ -70,6 +70,89 @@ static int load(xmlXPathContextPtr ctxt,
Pablo Greco 40546a
     return ret;
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+cpuMapLoadInclude(const char *filename,
Pablo Greco 40546a
+                  cpuMapLoadCallback cb,
Pablo Greco 40546a
+                  void *data)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    xmlDocPtr xml = NULL;
Pablo Greco 40546a
+    xmlXPathContextPtr ctxt = NULL;
Pablo Greco 40546a
+    int ret = -1;
Pablo Greco 40546a
+    int element;
Pablo Greco 40546a
+    char *mapfile;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (!(mapfile = virFileFindResource(filename,
Pablo Greco 40546a
+                                        abs_topsrcdir "/src/cpu",
Pablo Greco 40546a
+                                        PKGDATADIR)))
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    VIR_DEBUG("Loading CPU map include from %s", mapfile);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (!(xml = virXMLParseFileCtxt(mapfile, &ctxt)))
Pablo Greco 40546a
+        goto cleanup;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    ctxt->node = xmlDocGetRootElement(xml);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    for (element = 0; element < CPU_MAP_ELEMENT_LAST; element++) {
Pablo Greco 40546a
+        if (load(ctxt, element, cb, data) < 0) {
Pablo Greco 40546a
+            virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                           _("cannot parse CPU map '%s'"), mapfile);
Pablo Greco 40546a
+            goto cleanup;
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    ret = 0;
Pablo Greco 40546a
+
Pablo Greco 40546a
+ cleanup:
Pablo Greco 40546a
+    xmlXPathFreeContext(ctxt);
Pablo Greco 40546a
+    xmlFreeDoc(xml);
Pablo Greco 40546a
+    VIR_FREE(mapfile);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return ret;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+loadIncludes(xmlXPathContextPtr ctxt,
Pablo Greco 40546a
+             cpuMapLoadCallback callback,
Pablo Greco 40546a
+             void *data)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    int ret = -1;
Pablo Greco 40546a
+    xmlNodePtr ctxt_node;
Pablo Greco 40546a
+    xmlNodePtr *nodes = NULL;
Pablo Greco 40546a
+    int n;
Pablo Greco 40546a
+    size_t i;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    ctxt_node = ctxt->node;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    n = virXPathNodeSet("include", ctxt, &nodes);
Pablo Greco 40546a
+    if (n < 0)
Pablo Greco 40546a
+        goto cleanup;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    for (i = 0; i < n; i++) {
Pablo Greco 40546a
+        char *filename = virXMLPropString(nodes[i], "filename");
Pablo Greco 40546a
+        if (!filename) {
Pablo Greco 40546a
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
Pablo Greco 40546a
+                           _("Missing 'filename' in CPU map include"));
Pablo Greco 40546a
+            goto cleanup;
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+        VIR_DEBUG("Finding CPU map include '%s'", filename);
Pablo Greco 40546a
+        if (cpuMapLoadInclude(filename, callback, data) < 0) {
Pablo Greco 40546a
+            VIR_FREE(filename);
Pablo Greco 40546a
+            goto cleanup;
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+        VIR_FREE(filename);
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    ret = 0;
Pablo Greco 40546a
+
Pablo Greco 40546a
+ cleanup:
Pablo Greco 40546a
+    ctxt->node = ctxt_node;
Pablo Greco 40546a
+    VIR_FREE(nodes);
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return ret;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
 
Pablo Greco 40546a
 int cpuMapLoad(const char *arch,
Pablo Greco 40546a
                cpuMapLoadCallback cb,
Pablo Greco 40546a
@@ -88,7 +171,7 @@ int cpuMapLoad(const char *arch,
Pablo Greco 40546a
                                         PKGDATADIR)))
Pablo Greco 40546a
         return -1;
Pablo Greco 40546a
 
Pablo Greco 40546a
-    VIR_DEBUG("Loading CPU map from %s", mapfile);
Pablo Greco 40546a
+    VIR_DEBUG("Loading '%s' CPU map from %s", NULLSTR(arch), mapfile);
Pablo Greco 40546a
 
Pablo Greco 40546a
     if (arch == NULL) {
Pablo Greco 40546a
         virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
@@ -122,11 +205,14 @@ int cpuMapLoad(const char *arch,
Pablo Greco 40546a
     for (element = 0; element < CPU_MAP_ELEMENT_LAST; element++) {
Pablo Greco 40546a
         if (load(ctxt, element, cb, data) < 0) {
Pablo Greco 40546a
             virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
-                           _("cannot parse CPU map for %s architecture"), arch);
Pablo Greco 40546a
+                           _("cannot parse CPU map '%s'"), mapfile);
Pablo Greco 40546a
             goto cleanup;
Pablo Greco 40546a
         }
Pablo Greco 40546a
     }
Pablo Greco 40546a
 
Pablo Greco 40546a
+    if (loadIncludes(ctxt, cb, data) < 0)
Pablo Greco 40546a
+        goto cleanup;
Pablo Greco 40546a
+
Pablo Greco 40546a
     ret = 0;
Pablo Greco 40546a
 
Pablo Greco 40546a
  cleanup:
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a