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