[PATCH 1/4] cpu: allow include files for CPU definition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow for syntax

    <include filename="fooo.xml"/>

to reference other files in the CPU database directory

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 libvirt.spec.in       |  2 +-
 mingw-libvirt.spec.in |  4 +--
 src/Makefile.am       |  2 +-
 src/cpu/cpu_map.c     | 84 +++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 86 insertions(+), 6 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 19ae55cdaf..b6745dbffa 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1856,7 +1856,7 @@ exit 0
 %{_datadir}/libvirt/schemas/storagepool.rng
 %{_datadir}/libvirt/schemas/storagevol.rng
 
-%{_datadir}/libvirt/cpu_map.xml
+%{_datadir}/libvirt/cpu_map*.xml
 
 %{_datadir}/libvirt/test-screenshot.png
 
diff --git a/mingw-libvirt.spec.in b/mingw-libvirt.spec.in
index cc1e619927..22fe7a000f 100644
--- a/mingw-libvirt.spec.in
+++ b/mingw-libvirt.spec.in
@@ -260,7 +260,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-guests.sh
 %{mingw32_datadir}/libvirt/api/libvirt-qemu-api.xml
 %{mingw32_datadir}/libvirt/api/libvirt-admin-api.xml
 
-%{mingw32_datadir}/libvirt/cpu_map.xml
+%{mingw32_datadir}/libvirt/cpu_map*.xml
 
 %{mingw32_datadir}/libvirt/test-screenshot.png
 
@@ -347,7 +347,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-guests.sh
 %{mingw64_datadir}/libvirt/api/libvirt-qemu-api.xml
 %{mingw64_datadir}/libvirt/api/libvirt-admin-api.xml
 
-%{mingw64_datadir}/libvirt/cpu_map.xml
+%{mingw64_datadir}/libvirt/cpu_map*.xml
 
 %{mingw64_datadir}/libvirt/test-screenshot.png
 
diff --git a/src/Makefile.am b/src/Makefile.am
index a4f213480e..11a7ac81e2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -366,7 +366,7 @@ check-local: check-protocol check-symfile check-symsorting \
 
 
 
-pkgdata_DATA =	cpu/cpu_map.xml
+pkgdata_DATA =	$(wildcard $(srcdir)/cpu/cpu_map*.xml)
 
 EXTRA_DIST +=	$(pkgdata_DATA)
 
diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
index d263eb8cdd..9e090919ed 100644
--- a/src/cpu/cpu_map.c
+++ b/src/cpu/cpu_map.c
@@ -70,6 +70,83 @@ static int load(xmlXPathContextPtr ctxt,
     return ret;
 }
 
+static int
+cpuMapLoadInclude(const char *filename,
+                  cpuMapLoadCallback cb,
+                  void *data)
+{
+    xmlDocPtr xml = NULL;
+    xmlXPathContextPtr ctxt = NULL;
+    int ret = -1;
+    int element;
+    char *mapfile;
+
+    if (!(mapfile = virFileFindResource(filename,
+                                        abs_topsrcdir "/src/cpu",
+                                        PKGDATADIR)))
+        return -1;
+
+    VIR_DEBUG("Loading CPU map include from %s", mapfile);
+
+    if (!(xml = virXMLParseFileCtxt(mapfile, &ctxt)))
+        goto cleanup;
+
+    ctxt->node = xmlDocGetRootElement(xml);
+
+    for (element = 0; element < CPU_MAP_ELEMENT_LAST; element++) {
+        if (load(ctxt, element, cb, data) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("cannot parse CPU map '%s'"), mapfile);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+ cleanup:
+    xmlXPathFreeContext(ctxt);
+    xmlFreeDoc(xml);
+    VIR_FREE(mapfile);
+
+    return ret;
+}
+
+
+static int loadIncludes(xmlXPathContextPtr ctxt,
+                        cpuMapLoadCallback callback,
+                        void *data)
+{
+    int ret = -1;
+    xmlNodePtr ctxt_node;
+    xmlNodePtr *nodes = NULL;
+    int n;
+    size_t i;
+
+    ctxt_node = ctxt->node;
+
+    n = virXPathNodeSet("include", ctxt, &nodes);
+    if (n < 0)
+        goto cleanup;
+
+    for (i = 0; i < n; i++) {
+        char *filename = virXMLPropString(nodes[i], "filename");
+        VIR_DEBUG("Finding CPU map include '%s'", filename);
+        if (cpuMapLoadInclude(filename, callback, data) < 0) {
+            VIR_FREE(filename);
+            goto cleanup;
+        }
+        VIR_FREE(filename);
+    }
+
+    ret = 0;
+
+ cleanup:
+    ctxt->node = ctxt_node;
+    VIR_FREE(nodes);
+
+    return ret;
+}
+
 
 int cpuMapLoad(const char *arch,
                cpuMapLoadCallback cb,
@@ -88,7 +165,7 @@ int cpuMapLoad(const char *arch,
                                         PKGDATADIR)))
         return -1;
 
-    VIR_DEBUG("Loading CPU map from %s", mapfile);
+    VIR_DEBUG("Loading '%s' CPU map from %s", arch, mapfile);
 
     if (arch == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -122,11 +199,14 @@ int cpuMapLoad(const char *arch,
     for (element = 0; element < CPU_MAP_ELEMENT_LAST; element++) {
         if (load(ctxt, element, cb, data) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("cannot parse CPU map for %s architecture"), arch);
+                           _("cannot parse CPU map '%s'"), mapfile);
             goto cleanup;
         }
     }
 
+    if (loadIncludes(ctxt, cb, data) < 0)
+        goto cleanup;
+
     ret = 0;
 
  cleanup:
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux