summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README27
-rw-r--r--configure.ac106
-rw-r--r--src/launch.c65
3 files changed, 154 insertions, 44 deletions
diff --git a/README b/README
index 29ab65d2..69c43fe6 100644
--- a/README
+++ b/README
@@ -286,6 +286,33 @@ Don't enable GCC warnings (ie. *don't* use
'./configure --enable-gcc-warnings').
+Note on using non-x86 architectures
+----------------------------------------------------------------------
+
+In theory libguestfs should work on non-x86 architectures. Usually if
+it doesn't it's because qemu isn't available or cannot boot the
+kernel.
+
+Nevertheless we've had some success on arm. For arm you will need to
+specify the exact machine type and CPU variant that is required to
+boot the Linux kernel (there's no way to know this except by looking
+at how the Linux kernel was configured). For example:
+
+ ./configure \
+ --with-qemu="qemu-system-arm" \
+ --with-qemu-options="-M versatilepb -cpu arm926"
+ ./configure \
+ --with-qemu="qemu-system-arm" \
+ --with-qemu-options="-M vexpress-a9 -cpu cortex-a9"
+
+Note that since virtio is required by libguestfs, and virtio is a
+PCI-based architecture, whatever architecture qemu emulates must
+support PCI also.
+
+After building libguestfs, run 'make quickcheck' and pay close
+attention to the qemu command line.
+
+
Copyright and license information
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 16433df1..346884d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -536,6 +536,22 @@ AC_PATH_PROGS([QEMU],[$with_qemu],[no],
test "x$QEMU" = "xno" && AC_MSG_ERROR([qemu must be installed])
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])
+ 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 vmchannel_test=no.
if test "x$vmchannel_test" != "xno"; then
@@ -552,53 +568,55 @@ working.
])
fi
- dnl qemu 0.15 was released with broken support for '-machine',
- dnl requiring you to add the machine type: '-machine pc,[...]'.
- dnl The problem is that 'pc' is only applicable for PC-like
- dnl hardware, so we cannot do this as a general solution. Since
- dnl qemu 0.15, this problem has been fixed so now the default
- dnl machine type is chosen (qemu commit 2645c6dcaf6ea2a51a).
- dnl
- dnl We need to work out if this qemu is the broken version, so we
- dnl can add 'pc' just for this broken version.
- dnl
- dnl Note that old qemu didn't support the '-machine' option at all.
- dnl
- dnl We use the -kernel option for testing this, because this option
- dnl is processed very late, after qemu has set up the machine.
- AC_MSG_CHECKING([for broken '-machine accel=tcg' option in $QEMU])
- LC_ALL=C $QEMU -nographic -machine accel=tcg -kernel /NO_SUCH_FILE \
+ AS_IF([test "x$QEMU_OPTIONS" = "x"],[
+ dnl qemu 0.15 was released with broken support for '-machine',
+ dnl requiring you to add the machine type: '-machine pc,[...]'.
+ dnl The problem is that 'pc' is only applicable for PC-like
+ dnl hardware, so we cannot do this as a general solution. Since
+ dnl qemu 0.15, this problem has been fixed so now the default
+ dnl machine type is chosen (qemu commit 2645c6dcaf6ea2a51a).
+ dnl
+ dnl We need to work out if this qemu is the broken version, so we
+ dnl can add 'pc' just for this broken version.
+ dnl
+ dnl Note that old qemu didn't support the '-machine' option at all.
+ dnl
+ dnl We use the -kernel option for testing this, because this option
+ dnl is processed very late, after qemu has set up the machine.
+ AC_MSG_CHECKING([for broken '-machine accel=tcg' option in $QEMU])
+ LC_ALL=C $QEMU -nographic -machine accel=tcg -kernel /NO_SUCH_FILE \
> config1.tmp 2>&1
- LC_ALL=C $QEMU -nographic -machine pc,accel=tcg -kernel /NO_SUCH_FILE \
+ LC_ALL=C $QEMU -nographic -machine pc,accel=tcg -kernel /NO_SUCH_FILE \
> config2.tmp 2>&1
- if cmp -s config1.tmp config2.tmp; then
- AC_MSG_RESULT([no])
- else
- AC_MSG_RESULT([yes])
- AC_DEFINE([QEMU_MACHINE_TYPE_IS_BROKEN],[1],[qemu -machine accel=tcg option is broken (in qemu 0.15 only)])
- fi
- rm config1.tmp config2.tmp
-
- dnl See if the '-machine [pc,]accel=tcg' option is required in
- dnl order to run the virtio-serial test below. This happens when
- dnl we run qemu-kvm inside a VM without forcing TCG:
- dnl
- dnl Could not access KVM kernel module: No such file or directory
- dnl failed to initialize KVM: No such file or directory
- dnl No accelerator found!
- AC_MSG_CHECKING([if -machine @<:@pc,@:>@accel=tcg option is required to test virtio-serial feature])
- if $QEMU -nographic -device \? >/dev/null 2>&1; then
- :
- elif $QEMU -machine accel=tcg -nographic -device \? >/dev/null 2>&1; then
- QEMU_EXTRA_OPTIONS_FOR_TEST="-machine accel=tcg"
- elif $QEMU -machine pc,accel=tcg -nographic -device \? >/dev/null 2>&1; then
- QEMU_EXTRA_OPTIONS_FOR_TEST="-machine pc,accel=tcg"
- # else nothing ... it'll fail below.
- fi
- AC_MSG_RESULT([$QEMU_EXTRA_OPTIONS_FOR_TEST])
+ if cmp -s config1.tmp config2.tmp; then
+ AC_MSG_RESULT([no])
+ else
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([QEMU_MACHINE_TYPE_IS_BROKEN],[1],[qemu -machine accel=tcg option is broken (in qemu 0.15 only)])
+ fi
+ rm config1.tmp config2.tmp
+
+ dnl See if the '-machine [pc,]accel=tcg' option is required in
+ dnl order to run the virtio-serial test below. This happens when
+ dnl we run qemu-kvm inside a VM without forcing TCG:
+ dnl
+ dnl Could not access KVM kernel module: No such file or directory
+ dnl failed to initialize KVM: No such file or directory
+ dnl No accelerator found!
+ AC_MSG_CHECKING([if -machine @<:@pc,@:>@accel=tcg option is required to test virtio-serial feature])
+ if $QEMU -nographic -device \? >/dev/null 2>&1; then
+ :
+ elif $QEMU -machine accel=tcg -nographic -device \? >/dev/null 2>&1; then
+ QEMU_OPTIONS_FOR_TEST="-machine accel=tcg"
+ elif $QEMU -machine pc,accel=tcg -nographic -device \? >/dev/null 2>&1; then
+ QEMU_OPTIONS_FOR_TEST="-machine pc,accel=tcg"
+ # else nothing ... it'll fail below.
+ fi
+ AC_MSG_RESULT([$QEMU_OPTIONS_FOR_TEST])
+ ])
AC_MSG_CHECKING([for virtio-serial support in $QEMU])
- if $QEMU $QEMU_EXTRA_OPTIONS_FOR_TEST -nographic -device \? 2>&1 | grep -sq virtio-serial; then
+ if $QEMU $QEMU_OPTIONS $QEMU_OPTIONS_FOR_TEST -nographic -device \? 2>&1 | grep -sq virtio-serial; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
@@ -1371,7 +1389,7 @@ echo "This is how we have configured the optional components for you today:"
echo
echo "Daemon .............................. $enable_daemon"
echo "Appliance ........................... $enable_appliance"
-echo "QEMU ................................ $QEMU"
+echo "QEMU ................................ $QEMU $QEMU_OPTIONS"
AS_ECHO_N(["OCaml bindings ...................... "])
if test "x$HAVE_OCAML_TRUE" = "x"; then echo "yes"; else echo "no"; fi
AS_ECHO_N(["Perl bindings ....................... "])
diff --git a/src/launch.c b/src/launch.c
index 5c6676fc..a7c75ee9 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -142,6 +142,64 @@ add_cmdline (guestfs_h *g, const char *str)
return 0;
}
+/* Like 'add_cmdline' but allowing a shell-quoted string of zero or
+ * more options. XXX The unquoting is not very clever.
+ */
+static int
+add_cmdline_shell_unquoted (guestfs_h *g, const char *options)
+{
+ char quote;
+ const char *startp, *endp, *nextp;
+
+ if (g->state != CONFIG) {
+ error (g,
+ _("command line cannot be altered after qemu subprocess launched"));
+ return -1;
+ }
+
+ while (*options) {
+ quote = *options;
+ if (quote == '\'' || quote == '"')
+ startp = options+1;
+ else {
+ startp = options;
+ quote = ' ';
+ }
+
+ endp = strchr (options, quote);
+ if (endp == NULL) {
+ if (quote != ' ') {
+ error (g, _("unclosed quote character (%c) in command line near: %s"),
+ quote, options);
+ return -1;
+ }
+ endp = options + strlen (options);
+ }
+
+ if (quote == ' ')
+ nextp = endp+1;
+ else {
+ if (!endp[1])
+ nextp = endp+1;
+ else if (endp[1] == ' ')
+ nextp = endp+2;
+ else {
+ error (g, _("cannot parse quoted string near: %s"), options);
+ return -1;
+ }
+ }
+ while (*nextp && *nextp == ' ')
+ nextp++;
+
+ incr_cmdline_size (g);
+ g->cmdline[g->cmdline_size-1] = safe_strndup (g, startp, endp-startp);
+
+ options = nextp;
+ }
+
+ return 0;
+}
+
struct drive **
guestfs___checkpoint_drives (guestfs_h *g)
{
@@ -598,6 +656,13 @@ launch_appliance (guestfs_h *g)
if (qemu_supports (g, "-nodefconfig"))
add_cmdline (g, "-nodefconfig");
+ if (STRNEQ (QEMU_OPTIONS, "")) {
+ /* Add the extra options for the qemu command line specified
+ * at configure time.
+ */
+ add_cmdline_shell_unquoted (g, QEMU_OPTIONS);
+ }
+
/* The #if on the next line should really be "architectures for
* which KVM is commonly available.
*/