Skip to content

Commit

Permalink
lib: Define HAVE_LIBVIRT_BACKEND where you have too old libvirt to ru…
Browse files Browse the repository at this point in the history
…n the backend.

In the case where libvirt was installed, but is too old to run the
backend, the libvirt backend would be compiled out but still
referenced by the library.

Fix this by splitting the definition of HAVE_LIBVIRT (libvirt is
installed at all) and HAVE_LIBVIRT_BACKEND (libvirt is new enough to
run the libvirt backend).

Reported by: Efstratios Skleparis.
  • Loading branch information
rwmjones committed Oct 16, 2015
1 parent 279adde commit bc2b417
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
20 changes: 18 additions & 2 deletions src/guestfs-internal.h
Expand Up @@ -26,6 +26,22 @@

#include <pcre.h>

/* Minimum required version of libvirt for the libvirt backend.
*
* This is also checked at runtime because you can dynamically link
* with a different version from what you were compiled with.
*/
#define MIN_LIBVIRT_MAJOR 0
#define MIN_LIBVIRT_MINOR 10
#define MIN_LIBVIRT_MICRO 2 /* XXX patches in > 2 already */
#define MIN_LIBVIRT_VERSION (MIN_LIBVIRT_MAJOR * 1000000 + \
MIN_LIBVIRT_MINOR * 1000 + \
MIN_LIBVIRT_MICRO)

#if defined(HAVE_LIBVIRT) && LIBVIR_VERSION_NUMBER >= MIN_LIBVIRT_VERSION
#define HAVE_LIBVIRT_BACKEND
#endif

#ifdef HAVE_LIBVIRT
#include <libvirt/libvirt.h>
#endif
Expand Down Expand Up @@ -476,7 +492,7 @@ struct guestfs_h
int ml_debug_calls; /* Extra debug info on each FUSE call. */
#endif

#ifdef HAVE_LIBVIRT
#ifdef HAVE_LIBVIRT_BACKEND
/* Used by src/libvirt-auth.c. */
#define NR_CREDENTIAL_TYPES 9
unsigned int nr_supported_credentials;
Expand Down Expand Up @@ -885,7 +901,7 @@ extern bool guestfs_int_discard_possible (guestfs_h *g, struct drive *drv, unsig

/* launch-*.c constructors */
void guestfs_int_init_direct_backend (void) __attribute__((constructor));
#ifdef HAVE_LIBVIRT
#ifdef HAVE_LIBVIRT_BACKEND
void guestfs_int_init_libvirt_backend (void) __attribute__((constructor));
#endif
void guestfs_int_init_uml_backend (void) __attribute__((constructor));
Expand Down
20 changes: 2 additions & 18 deletions src/launch-libvirt.c
Expand Up @@ -61,23 +61,7 @@
#endif
/* End of fixes for Mac OS X */

/* Check minimum required version of libvirt. The libvirt backend
* is new and not the default, so we can get away with forcing
* people who want to try it to have a reasonably new version of
* libvirt, so we don't have to work around any bugs in libvirt.
*
* This is also checked at runtime because you can dynamically link
* with a different version from what you were compiled with.
*/
#define MIN_LIBVIRT_MAJOR 0
#define MIN_LIBVIRT_MINOR 10
#define MIN_LIBVIRT_MICRO 2 /* XXX patches in > 2 already */
#define MIN_LIBVIRT_VERSION (MIN_LIBVIRT_MAJOR * 1000000 + \
MIN_LIBVIRT_MINOR * 1000 + \
MIN_LIBVIRT_MICRO)

#if defined(HAVE_LIBVIRT) && \
LIBVIR_VERSION_NUMBER >= MIN_LIBVIRT_VERSION
#ifdef HAVE_LIBVIRT_BACKEND

#ifndef HAVE_XMLBUFFERDETACH
/* Added in libxml2 2.8.0. This is mostly a copy of the function from
Expand Down Expand Up @@ -2308,4 +2292,4 @@ guestfs_int_init_libvirt_backend (void)
guestfs_int_register_backend ("libvirt", &backend_libvirt_ops);
}

#endif
#endif /* HAVE_LIBVIRT_BACKEND */
2 changes: 1 addition & 1 deletion src/launch.c
Expand Up @@ -520,7 +520,7 @@ guestfs_int_set_backend (guestfs_h *g, const char *method)
void *
guestfs_int_force_load_backends[] = {
guestfs_int_init_direct_backend,
#ifdef HAVE_LIBVIRT
#ifdef HAVE_LIBVIRT_BACKEND
guestfs_int_init_libvirt_backend,
#endif
guestfs_int_init_uml_backend,
Expand Down

0 comments on commit bc2b417

Please sign in to comment.