[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH] Add test for qemu broken -machine option (RHBZ#748266).

I've pushed this one already, so this is just 'FYI'.  I tested
it first on 5 different machines with:

 - latest upstream qemu
 - qemu-kvm from Fedora that contains the patch to fix the broken
    -machine option
 - qemu-kvm from Fedora, but with that patch removed
 - old qemu that predates the -machine option entirely
 - Debian 6 + qemu 0.14


Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
>From 3814680423984b3c46c2f99e944c2a71862bde9f Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones redhat com>
Date: Mon, 24 Oct 2011 13:24:16 +0100
Subject: [PATCH] Add test for qemu broken -machine option (RHBZ#748266).

Also add this option, if necessary, when testing for virtio-serial

When the workaround is enabled, we specify machine type 'pc'.
 configure.ac |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/launch.c |   12 ++++++++++++
 2 files changed, 58 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index c384c6e..d1b1c10 100644
--- a/configure.ac
+++ b/configure.ac
@@ -446,8 +446,53 @@ working.
+    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 \
+             > 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_CHECKING([for virtio-serial support in $QEMU])
-    if $QEMU -nographic -device \? 2>&1 | grep -sq virtio-serial; then
+    if $QEMU $QEMU_EXTRA_OPTIONS_FOR_TEST -nographic -device \? 2>&1 | grep -sq virtio-serial; then
diff --git a/src/launch.c b/src/launch.c
index 1988f70..7b3372c 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -586,7 +586,19 @@ launch_appliance (guestfs_h *g)
     if (qemu_supports (g, "-machine")) {
       add_cmdline (g, "-machine");
+      /* Workaround for qemu 0.15: We have to add the '[type=]pc'
+       * since there is no default.  This is not a permanent solution
+       * because this only works on PC-like hardware.  Other platforms
+       * like ppc would need a different machine type.
+       *
+       * This bug is fixed in qemu commit 2645c6dcaf6ea2a51a, and was
+       * not a problem in qemu < 0.15.
+       */
+      add_cmdline (g, "pc,accel=kvm:tcg");
       add_cmdline (g, "accel=kvm:tcg");
     } else {
       /* qemu sometimes needs this option to enable hardware
        * virtualization, but some versions of 'qemu-kvm' will use KVM

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]