From: "Richard W.M. Jones" <rjones(a)redhat.com>
This means there will be no default hypervisor, and effectively the
user will always have to specify one (eg. by setting LIBGUESTFS_HV or
calling guestfs_set_hv).
This is useful on platforms where qemu doesn't work, or where qemu is
not needed (eg. if you want to use UML, or you just want to compile
libguestfs without using/testing it).
---
configure.ac | 125 ++++++++++++++++++++++-------------------
src/handle.c | 28 ++++++++-
src/launch-direct.c | 4 ++
src/launch-libvirt.c | 4 ++
tests/regressions/rhbz501893.c | 2 +
5 files changed, 105 insertions(+), 58 deletions(-)
diff --git a/configure.ac b/configure.ac
index de0455e..6e93221 100644
--- a/configure.ac
+++ b/configure.ac
@@ -737,80 +737,90 @@ default_qemu="qemu-kvm kvm $qemu_system qemu"
AC_ARG_WITH([qemu],
[AS_HELP_STRING([--with-qemu="bin1 bin2 ..."],
[set default QEMU binary @<:@default="[qemu-kvm] qemu-system-<host>
qemu"@:>@])],
- [],
- [with_qemu="$default_qemu"])
-AC_PATH_PROGS([QEMU],[$with_qemu],[no],
- [$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/libexec])
-test "x$QEMU" = "xno" && AC_MSG_ERROR([qemu must be
installed])
-AC_DEFINE_UNQUOTED([QEMU],["$QEMU"],[Location of qemu binary.])
+ dnl --with-qemu or --without-qemu:
+ [],
+ dnl neither option was given:
+ [with_qemu="$default_qemu"]
+)
-dnl Does the user wish to specify -M, -cpu or other qemu options?
-AC_MSG_CHECKING([if the user specified extra options for qemu command line])
-AC_ARG_WITH([qemu-options],
- [AS_HELP_STRING([--with-qemu-options="-M ... -cpu ... etc"],
- [pass extra options for qemu command line @<:@default=no@:>@])],
- [QEMU_OPTIONS="$withval"],
- [QEMU_OPTIONS=no])
-AS_IF([test "x$QEMU_OPTIONS" = "xno"],[
- AC_MSG_RESULT([no])
- QEMU_OPTIONS=
+AS_IF([test "x$with_qemu" = "xno"],[
+ AC_MSG_WARN([qemu was disabled, libguestfs may not work at all])
+ QEMU=no
],[
- AC_MSG_RESULT([$QEMU_OPTIONS])
-])
-AC_DEFINE_UNQUOTED([QEMU_OPTIONS],["$QEMU_OPTIONS"],
- [Extra options for qemu command line.])
+ AC_PATH_PROGS([QEMU],[$with_qemu],[no],
+ [$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin$PATH_SEPARATOR/usr/libexec])
+ test "x$QEMU" = "xno" && AC_MSG_ERROR([qemu must be
installed])
-dnl Check that the chosen qemu has virtio-serial support.
-dnl For historical reasons this can be disabled by setting vmchannel_test=no.
-if test "x$vmchannel_test" != "xno"; then
- AC_MSG_CHECKING([that $QEMU -help works])
- if $QEMU -help >&AS_MESSAGE_LOG_FD 2>&1; then
- AC_MSG_RESULT([yes])
- else
+ AC_DEFINE_UNQUOTED([QEMU],["$QEMU"],[Location of qemu binary.])
+
+ dnl Does the user wish to specify -M, -cpu or other qemu options?
+ AC_MSG_CHECKING([if the user specified extra options for qemu command line])
+ AC_ARG_WITH([qemu-options],
+ [AS_HELP_STRING([--with-qemu-options="-M ... -cpu ... etc"],
+ [pass extra options for qemu command line @<:@default=no@:>@])],
+ [QEMU_OPTIONS="$withval"],
+ [QEMU_OPTIONS=no])
+ AS_IF([test "x$QEMU_OPTIONS" = "xno"],[
AC_MSG_RESULT([no])
- AC_MSG_FAILURE(
+ QEMU_OPTIONS=
+ ],[
+ AC_MSG_RESULT([$QEMU_OPTIONS])
+ ])
+ AC_DEFINE_UNQUOTED([QEMU_OPTIONS],["$QEMU_OPTIONS"],
+ [Extra options for qemu command line.])
+
+ dnl Check that the chosen qemu has virtio-serial support.
+ dnl For historical reasons this can be disabled by setting
+ dnl vmchannel_test=no.
+ if test "x$vmchannel_test" != "xno"; then
+ AC_MSG_CHECKING([that $QEMU -help works])
+ if $QEMU -help >&AS_MESSAGE_LOG_FD 2>&1; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ AC_MSG_FAILURE(
[$QEMU -help: command failed.
This could be a very old version of qemu, or qemu might not be
working.
])
- fi
+ fi
- AC_MSG_CHECKING([that $QEMU -version works])
- if $QEMU -version >&AS_MESSAGE_LOG_FD 2>&1; then
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no])
- AC_MSG_FAILURE(
+ AC_MSG_CHECKING([that $QEMU -version works])
+ if $QEMU -version >&AS_MESSAGE_LOG_FD 2>&1; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ AC_MSG_FAILURE(
[$QEMU -version: command failed.
This could be a very old version of qemu, or qemu might not be
working.
])
- fi
+ fi
- AC_MSG_CHECKING([for $QEMU version >= 1])
- if $QEMU -version | grep -sq 'version @<:@1-@:>@'; then
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no])
- AC_MSG_FAILURE([$QEMU version must be >= 1.0.])
- fi
+ AC_MSG_CHECKING([for $QEMU version >= 1])
+ if $QEMU -version | grep -sq 'version @<:@1-@:>@'; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ AC_MSG_FAILURE([$QEMU version must be >= 1.0.])
+ fi
- AC_MSG_CHECKING([that $QEMU -display none -machine accel=kvm:tcg -device ? works])
- if $QEMU -display none -machine accel=kvm:tcg -device \? >&AS_MESSAGE_LOG_FD
2>&1; then
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no])
- AC_MSG_FAILURE([$QEMU -display none -machine accel=kvm:tcg -device ? doesn't
work.])
- fi
+ AC_MSG_CHECKING([that $QEMU -display none -machine accel=kvm:tcg -device ?
works])
+ if $QEMU -display none -machine accel=kvm:tcg -device \?
>&AS_MESSAGE_LOG_FD 2>&1; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ AC_MSG_FAILURE([$QEMU -display none -machine accel=kvm:tcg -device ?
doesn't work.])
+ fi
- AC_MSG_CHECKING([for virtio-serial support in $QEMU])
- if $QEMU $QEMU_OPTIONS -display none -machine accel=kvm:tcg -device \? 2>&1 |
grep -sq virtio-serial; then
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no])
- AC_MSG_FAILURE(
+ AC_MSG_CHECKING([for virtio-serial support in $QEMU])
+ if $QEMU $QEMU_OPTIONS -display none -machine accel=kvm:tcg -device \?
2>&1 | grep -sq virtio-serial; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ AC_MSG_FAILURE(
[I did not find virtio-serial support in
$QEMU.
@@ -831,8 +841,9 @@ If I am using the wrong qemu or you want to compile qemu from source
and install it in another location, then you should configure with
the --with-qemu option.
])
+ fi
fi
-fi
+])
dnl Enable packet dumps when in verbose mode. This generates lots
dnl of debug info, only useful for people debugging the RPC mechanism.
diff --git a/src/handle.c b/src/handle.c
index fa96d95..af7d956 100644
--- a/src/handle.c
+++ b/src/handle.c
@@ -107,7 +107,15 @@ guestfs_create_flags (unsigned flags, ...)
g->path = strdup (GUESTFS_DEFAULT_PATH);
if (!g->path) goto error;
+#ifdef QEMU
g->hv = strdup (QEMU);
+#else
+ /* configure --without-qemu, so set QEMU to something which will
+ * definitely fail. The user is expected to override the hypervisor
+ * by setting an environment variable or calling set_hv.
+ */
+ g->hv = strdup ("false");
+#endif
if (!g->hv) goto error;
/* Get program name. */
@@ -467,8 +475,26 @@ guestfs__get_path (guestfs_h *g)
int
guestfs__set_qemu (guestfs_h *g, const char *qemu)
{
+ char *new_hv;
+
+ /* Only this deprecated set_qemu API supports using NULL as a
+ * parameter, to mean set it back to the default QEMU. The new
+ * set_hv API does not allow callers to do this.
+ */
+ if (qemu == NULL) {
+#ifdef QEMU
+ new_hv = safe_strdup (g, QEMU);
+#else
+ error (g, _("configured --without-qemu so calling guestfs_set_qemu with qemu ==
NULL is an error"));
+ return -1;
+#endif
+ }
+ else
+ new_hv = safe_strdup (g, qemu);
+
free (g->hv);
- g->hv = qemu == NULL ? safe_strdup (g, QEMU) : safe_strdup (g, qemu);
+ g->hv = new_hv;
+
return 0;
}
diff --git a/src/launch-direct.c b/src/launch-direct.c
index f45f582..2d4073a 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -101,6 +101,7 @@ static int qemu_supports_device (guestfs_h *g, struct
backend_direct_data *, con
static int qemu_supports_virtio_scsi (guestfs_h *g, struct backend_direct_data *);
static char *qemu_escape_param (guestfs_h *g, const char *param);
+#ifdef QEMU_OPTIONS
/* Like 'add_cmdline' but allowing a shell-quoted string of zero or
* more options. XXX The unquoting is not very clever.
*/
@@ -156,6 +157,7 @@ add_cmdline_shell_unquoted (guestfs_h *g, struct stringsbuf *sb,
options = nextp;
}
}
+#endif /* defined QEMU_OPTIONS */
/* On Debian, /dev/kvm is mode 0660 and group kvm, so users need to
* add themselves to the kvm group otherwise things are going to be
@@ -587,8 +589,10 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
/* Add the extra options for the qemu command line specified
* at configure time.
*/
+#ifdef QEMU_OPTIONS
if (STRNEQ (QEMU_OPTIONS, ""))
add_cmdline_shell_unquoted (g, &cmdline, QEMU_OPTIONS);
+#endif
/* Add any qemu parameters. */
for (hp = g->hv_params; hp; hp = hp->next) {
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index b5650ea..e3ebd51 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -622,7 +622,11 @@ parse_capabilities (guestfs_h *g, const char *capabilities_xml,
static int
is_custom_hv (guestfs_h *g)
{
+#ifdef QEMU
return g->hv && STRNEQ (g->hv, QEMU);
+#else
+ return 1;
+#endif
}
#if HAVE_LIBSELINUX
diff --git a/tests/regressions/rhbz501893.c b/tests/regressions/rhbz501893.c
index fdd49c8..f4091bf 100644
--- a/tests/regressions/rhbz501893.c
+++ b/tests/regressions/rhbz501893.c
@@ -50,7 +50,9 @@ main (int argc, char *argv[])
assert (guestfs_set_path (g, NULL) == 0);
assert (guestfs_set_append (g, NULL) == 0);
+#ifdef QEMU
assert (guestfs_set_qemu (g, NULL) == 0);
+#endif
guestfs_close (g);
exit (EXIT_SUCCESS);
--
1.8.3.1