[PATCH 9/9] Use virFileFindResource to locate CPU map XML

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

 



Replace use of cpuMapOverride with virFileFindResource
to locate CPU map from build dir.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 daemon/libvirtd.c        | 19 -------------------
 src/cpu/cpu_map.c        | 31 ++++++++++---------------------
 src/cpu/cpu_map.h        |  3 ---
 tests/cputest.c          | 14 --------------
 tests/qemuxml2argvtest.c |  7 -------
 tests/qemuxmlnstest.c    |  7 -------
 6 files changed, 10 insertions(+), 71 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index e549783..4c926b3 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1158,25 +1158,6 @@ int main(int argc, char **argv) {
 
     virFileActivateDirOverride(argv[0]);
 
-    if (strstr(argv[0], "lt-libvirtd") ||
-        strstr(argv[0], "/daemon/.libs/libvirtd")) {
-        char *tmp = strrchr(argv[0], '/');
-        char *cpumap;
-        if (!tmp) {
-            fprintf(stderr, _("%s: cannot identify driver directory\n"), argv[0]);
-            exit(EXIT_FAILURE);
-        }
-        *tmp = '\0';
-        if (virAsprintfQuiet(&cpumap, "%s/../../src/cpu/cpu_map.xml",
-                             argv[0]) < 0) {
-            fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
-            exit(EXIT_FAILURE);
-        }
-        cpuMapOverride(cpumap);
-        VIR_FREE(cpumap);
-        *tmp = '/';
-    }
-
     while (1) {
         int optidx = 0;
         int c;
diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
index fca306e..68d287a 100644
--- a/src/cpu/cpu_map.c
+++ b/src/cpu/cpu_map.c
@@ -24,6 +24,7 @@
 #include <config.h>
 
 #include "viralloc.h"
+#include "virfile.h"
 #include "cpu.h"
 #include "cpu_map.h"
 #include "configmake.h"
@@ -34,10 +35,6 @@
 
 VIR_LOG_INIT("cpu.cpu_map");
 
-#define CPUMAPFILE PKGDATADIR "/cpu_map.xml"
-
-static char *cpumap;
-
 VIR_ENUM_IMPL(cpuMapElement, CPU_MAP_ELEMENT_LAST,
     "vendor",
     "feature",
@@ -87,20 +84,25 @@ int cpuMapLoad(const char *arch,
     char *xpath = NULL;
     int ret = -1;
     int element;
-    const char *mapfile = (cpumap ? cpumap : CPUMAPFILE);
+    char *mapfile;
+
+    if (!(mapfile = virFileFindResource("cpu_map.xml",
+                                        "src/cpu",
+                                        PKGDATADIR)))
+        return -1;
 
     VIR_DEBUG("Loading CPU map from %s", mapfile);
 
     if (arch == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("undefined hardware architecture"));
-        return -1;
+        goto cleanup;
     }
 
     if (cb == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("no callback provided"));
-        return -1;
+        goto cleanup;
     }
 
     if ((xml = xmlParseFile(mapfile)) == NULL) {
@@ -141,6 +143,7 @@ int cpuMapLoad(const char *arch,
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     VIR_FREE(xpath);
+    VIR_FREE(mapfile);
 
     return ret;
 
@@ -148,17 +151,3 @@ int cpuMapLoad(const char *arch,
     virReportOOMError();
     goto cleanup;
 }
-
-
-int
-cpuMapOverride(const char *path)
-{
-    char *map;
-
-    if (VIR_STRDUP(map, path) < 0)
-        return -1;
-
-    VIR_FREE(cpumap);
-    cpumap = map;
-    return 0;
-}
diff --git a/src/cpu/cpu_map.h b/src/cpu/cpu_map.h
index 8d27bcd..23ce888 100644
--- a/src/cpu/cpu_map.h
+++ b/src/cpu/cpu_map.h
@@ -48,7 +48,4 @@ cpuMapLoad(const char *arch,
            cpuMapLoadCallback cb,
            void *data);
 
-extern int
-cpuMapOverride(const char *path);
-
 #endif /* __VIR_CPU_MAP_H__ */
diff --git a/tests/cputest.c b/tests/cputest.c
index 8903f82..3766c2f 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -40,8 +40,6 @@
 #include "cpu/cpu_map.h"
 #include "virstring.h"
 
-static const char *abs_top_srcdir;
-
 #define VIR_FROM_THIS VIR_FROM_CPU
 
 enum cpuTestBoolWithError {
@@ -504,17 +502,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    char *map = NULL;
-
-    abs_top_srcdir = getenv("abs_top_srcdir");
-    if (!abs_top_srcdir)
-        abs_top_srcdir = abs_srcdir "/..";
-
-    if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
-        cpuMapOverride(map) < 0) {
-        VIR_FREE(map);
-        return EXIT_FAILURE;
-    }
 
 #define DO_TEST(arch, api, name, host, cpu,                             \
                 models, nmodels, preferred, flags, result)              \
@@ -657,7 +644,6 @@ mymain(void)
     DO_TEST_GUESTDATA("ppc64", "host", "guest", ppc_models, NULL, 0);
     DO_TEST_GUESTDATA("ppc64", "host", "guest-nofallback", ppc_models, "POWER7_v2.1", -1);
 
-    VIR_FREE(map);
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index d43a4de..a1ef2b8 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -483,7 +483,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    char *map = NULL;
     bool skipLegacyCPUs = false;
 
     abs_top_srcdir = getenv("abs_top_srcdir");
@@ -530,11 +529,6 @@ mymain(void)
     driver.config->spiceTLS = 1;
     if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0)
         return EXIT_FAILURE;
-    if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
-        cpuMapOverride(map) < 0) {
-        VIR_FREE(map);
-        return EXIT_FAILURE;
-    }
 
 # define DO_TEST_FULL(name, migrateFrom, migrateFd, flags, ...)         \
     do {                                                                \
@@ -1364,7 +1358,6 @@ mymain(void)
     virObjectUnref(driver.config);
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);
-    VIR_FREE(map);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c
index 30bb723..e8f70d6 100644
--- a/tests/qemuxmlnstest.c
+++ b/tests/qemuxmlnstest.c
@@ -205,7 +205,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    char *map = NULL;
     bool json = false;
 
     abs_top_srcdir = getenv("abs_top_srcdir");
@@ -217,11 +216,6 @@ mymain(void)
         return EXIT_FAILURE;
     if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
         return EXIT_FAILURE;
-    if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
-        cpuMapOverride(map) < 0) {
-        VIR_FREE(map);
-        return EXIT_FAILURE;
-    }
 
 # define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...)   \
     do {                                                                \
@@ -266,7 +260,6 @@ mymain(void)
     virObjectUnref(driver.config);
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);
-    VIR_FREE(map);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
1.9.0

--
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]