From e562e82f76614beff132ab48d3f0dabf64b20c5b Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Mon, 10 Mar 2014 16:00:49 +0100 Subject: [PATCH] Load CPU map from builddir when run uninstalled When libvirtd is run from a build directory without being installed, it should not depend on files from a libvirt package installed in the system. Not only because there may not be any libvirt installed at all. We already do a good job for plugins but cpu_map.xml was still loaded from the system. The Makefile.am change is necessary to make this all work from VPATH builds since libvirtd has no idea where to find libvirt sources. It only knows the path from which it was started, i.e, a builddir. https://bugzilla.redhat.com/show_bug.cgi?id=1074327 Signed-off-by: Jiri Denemark --- daemon/libvirtd.c | 7 ++++++- src/Makefile.am | 4 ++++ src/cpu/cpu_map.c | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 36adaf09c7..a471b3b01f 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -103,6 +103,7 @@ #include "configmake.h" #include "virdbus.h" +#include "cpu/cpu_map.h" #if WITH_SASL virNetSASLContextPtr saslCtxt = NULL; @@ -1157,13 +1158,16 @@ int main(int argc, char **argv) { 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'; char *driverdir; - if (virAsprintfQuiet(&driverdir, "%s/../../src/.libs", argv[0]) < 0) { + if (virAsprintfQuiet(&driverdir, "%s/../../src/.libs", argv[0]) < 0 || + virAsprintfQuiet(&cpumap, "%s/../../src/cpu/cpu_map.xml", + argv[0]) < 0) { fprintf(stderr, _("%s: initialization failed\n"), argv[0]); exit(EXIT_FAILURE); } @@ -1176,6 +1180,7 @@ int main(int argc, char **argv) { #ifdef WITH_DRIVER_MODULES virDriverModuleInitialize(driverdir); #endif + cpuMapOverride(cpumap); *tmp = '/'; /* Must not free 'driverdir' - it is still used */ } diff --git a/src/Makefile.am b/src/Makefile.am index 25b33a7f03..d4d7b2b2a7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -976,6 +976,10 @@ libvirt_la_BUILT_LIBADD += libvirt_cpu.la libvirt_cpu_la_CFLAGS = \ -I$(top_srcdir)/src/conf $(AM_CFLAGS) libvirt_cpu_la_SOURCES = $(CPU_SOURCES) +libvirt_cpu_la_DEPENDENCIES = $(abs_builddir)/cpu/cpu_map.xml + +$(abs_builddir)/cpu/cpu_map.xml: + $(AM_V_GEN)ln -s $(abs_srcdir)/cpu/cpu_map.xml $@ if WITH_VMX noinst_LTLIBRARIES += libvirt_vmx.la diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index 7c2bdec01e..f6c63d49c2 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -28,6 +28,7 @@ #include "cpu_map.h" #include "configmake.h" #include "virstring.h" +#include "virlog.h" #define VIR_FROM_THIS VIR_FROM_CPU @@ -86,6 +87,8 @@ int cpuMapLoad(const char *arch, int element; const char *mapfile = (cpumap ? cpumap : CPUMAPFILE); + VIR_DEBUG("Loading CPU map from %s", mapfile); + if (arch == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("undefined hardware architecture"));