Use virFileFindResource to locate CPU map XML

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

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2014-04-24 16:59:37 +01:00
parent bc2f42a094
commit dd477238bc
7 changed files with 10 additions and 72 deletions

View File

@ -1158,25 +1158,6 @@ int main(int argc, char **argv) {
virFileActivateDirOverride(argv[0]); 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) { while (1) {
int optidx = 0; int optidx = 0;
int c; int c;

View File

@ -24,6 +24,7 @@
#include <config.h> #include <config.h>
#include "viralloc.h" #include "viralloc.h"
#include "virfile.h"
#include "cpu.h" #include "cpu.h"
#include "cpu_map.h" #include "cpu_map.h"
#include "configmake.h" #include "configmake.h"
@ -34,10 +35,6 @@
VIR_LOG_INIT("cpu.cpu_map"); VIR_LOG_INIT("cpu.cpu_map");
#define CPUMAPFILE PKGDATADIR "/cpu_map.xml"
static char *cpumap;
VIR_ENUM_IMPL(cpuMapElement, CPU_MAP_ELEMENT_LAST, VIR_ENUM_IMPL(cpuMapElement, CPU_MAP_ELEMENT_LAST,
"vendor", "vendor",
"feature", "feature",
@ -87,20 +84,25 @@ int cpuMapLoad(const char *arch,
char *xpath = NULL; char *xpath = NULL;
int ret = -1; int ret = -1;
int element; 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); VIR_DEBUG("Loading CPU map from %s", mapfile);
if (arch == NULL) { if (arch == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("undefined hardware architecture")); "%s", _("undefined hardware architecture"));
return -1; goto cleanup;
} }
if (cb == NULL) { if (cb == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no callback provided")); "%s", _("no callback provided"));
return -1; goto cleanup;
} }
if ((xml = xmlParseFile(mapfile)) == NULL) { if ((xml = xmlParseFile(mapfile)) == NULL) {
@ -141,6 +143,7 @@ int cpuMapLoad(const char *arch,
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml); xmlFreeDoc(xml);
VIR_FREE(xpath); VIR_FREE(xpath);
VIR_FREE(mapfile);
return ret; return ret;
@ -148,17 +151,3 @@ int cpuMapLoad(const char *arch,
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
int
cpuMapOverride(const char *path)
{
char *map;
if (VIR_STRDUP(map, path) < 0)
return -1;
VIR_FREE(cpumap);
cpumap = map;
return 0;
}

View File

@ -48,7 +48,4 @@ cpuMapLoad(const char *arch,
cpuMapLoadCallback cb, cpuMapLoadCallback cb,
void *data); void *data);
extern int
cpuMapOverride(const char *path);
#endif /* __VIR_CPU_MAP_H__ */ #endif /* __VIR_CPU_MAP_H__ */

View File

@ -744,7 +744,6 @@ cpuEncode;
cpuGetModels; cpuGetModels;
cpuGuestData; cpuGuestData;
cpuHasFeature; cpuHasFeature;
cpuMapOverride;
cpuNodeData; cpuNodeData;
cpuUpdate; cpuUpdate;

View File

@ -40,8 +40,6 @@
#include "cpu/cpu_map.h" #include "cpu/cpu_map.h"
#include "virstring.h" #include "virstring.h"
static const char *abs_top_srcdir;
#define VIR_FROM_THIS VIR_FROM_CPU #define VIR_FROM_THIS VIR_FROM_CPU
enum cpuTestBoolWithError { enum cpuTestBoolWithError {
@ -504,17 +502,6 @@ static int
mymain(void) mymain(void)
{ {
int ret = 0; 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, \ #define DO_TEST(arch, api, name, host, cpu, \
models, nmodels, preferred, flags, result) \ 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", ppc_models, NULL, 0);
DO_TEST_GUESTDATA("ppc64", "host", "guest-nofallback", ppc_models, "POWER7_v2.1", -1); DO_TEST_GUESTDATA("ppc64", "host", "guest-nofallback", ppc_models, "POWER7_v2.1", -1);
VIR_FREE(map);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@ -483,7 +483,6 @@ static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char *map = NULL;
bool skipLegacyCPUs = false; bool skipLegacyCPUs = false;
abs_top_srcdir = getenv("abs_top_srcdir"); abs_top_srcdir = getenv("abs_top_srcdir");
@ -530,11 +529,6 @@ mymain(void)
driver.config->spiceTLS = 1; driver.config->spiceTLS = 1;
if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0) if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0)
return EXIT_FAILURE; 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, ...) \ # define DO_TEST_FULL(name, migrateFrom, migrateFd, flags, ...) \
do { \ do { \
@ -1364,7 +1358,6 @@ mymain(void)
virObjectUnref(driver.config); virObjectUnref(driver.config);
virObjectUnref(driver.caps); virObjectUnref(driver.caps);
virObjectUnref(driver.xmlopt); virObjectUnref(driver.xmlopt);
VIR_FREE(map);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@ -205,7 +205,6 @@ static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char *map = NULL;
bool json = false; bool json = false;
abs_top_srcdir = getenv("abs_top_srcdir"); abs_top_srcdir = getenv("abs_top_srcdir");
@ -217,11 +216,6 @@ mymain(void)
return EXIT_FAILURE; return EXIT_FAILURE;
if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver))) if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
return EXIT_FAILURE; 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, ...) \ # define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \
do { \ do { \
@ -266,7 +260,6 @@ mymain(void)
virObjectUnref(driver.config); virObjectUnref(driver.config);
virObjectUnref(driver.caps); virObjectUnref(driver.caps);
virObjectUnref(driver.xmlopt); virObjectUnref(driver.xmlopt);
VIR_FREE(map);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }