launch: direct: Don't use -cpu host on TCG.

qemu -cpu \? documents this as:

host  KVM processor with all supported host features (only available in KVM mode)

And indeed if you try it with TCG you'll get this error:

Unable to find CPU definition: host

This fixes commit 038ed0a08e.
This commit is contained in:
Richard W.M. Jones
2013-08-14 15:08:04 +01:00
parent 08f605c073
commit c53b459fdd

View File

@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include <unistd.h>
@@ -258,6 +259,7 @@ launch_direct (guestfs_h *g, const char *arg)
char buf[256];
int virtio_scsi = qemu_supports_virtio_scsi (g);
struct qemu_param *qp;
bool has_kvm;
/* Set up the full command line. Do this in the subprocess so we
* don't need to worry about cleaning up.
@@ -290,6 +292,14 @@ launch_direct (guestfs_h *g, const char *arg)
add_cmdline (g, "-nographic");
/* Try to guess if KVM is available. We are just checking that
* /dev/kvm is openable. That's not reliable, since /dev/kvm
* might be openable by qemu but not by us (think: SELinux) in
* which case the user would not get hardware virtualization,
* although at least shouldn't fail.
*/
has_kvm = is_openable (g, "/dev/kvm", O_RDWR|O_CLOEXEC);
/* The qemu -machine option (added 2010-12) is a bit more sane
* since it falls back through various different acceleration
* modes, so try that first (thanks Markus Armbruster).
@@ -301,23 +311,26 @@ launch_direct (guestfs_h *g, const char *arg)
/* qemu sometimes needs this option to enable hardware
* virtualization, but some versions of 'qemu-kvm' will use KVM
* regardless (even where this option appears in the help text).
* It is rumoured that there are versions of qemu where supplying
* this option when hardware virtualization is not available will
* cause qemu to fail, so we we have to check at least that
* /dev/kvm is openable. That's not reliable, since /dev/kvm
* might be openable by qemu but not by us (think: SELinux) in
* which case the user would not get hardware virtualization,
* although at least shouldn't fail. A giant clusterfuck with the
* qemu command line, again.
* It is rumoured that there are versions of qemu where
* supplying this option when hardware virtualization is not
* available will cause qemu to fail. A giant clusterfuck with
* the qemu command line, again.
*/
if (qemu_supports (g, "-enable-kvm") &&
is_openable (g, "/dev/kvm", O_RDWR|O_CLOEXEC))
if (qemu_supports (g, "-enable-kvm") && has_kvm)
add_cmdline (g, "-enable-kvm");
}
/* Specify the host CPU for speed, and kvmclock for stability. */
add_cmdline (g, "-cpu");
add_cmdline (g, "host,+kvmclock");
/* -cpu host only works if KVM is available. */
if (has_kvm) {
/* Specify the host CPU for speed, and kvmclock for stability. */
add_cmdline (g, "-cpu");
add_cmdline (g, "host,+kvmclock");
} else {
/* Specify default CPU for speed, and kvmclock for stability. */
snprintf (buf, sizeof buf, "qemu%d,+kvmclock", SIZEOF_LONG*8);
add_cmdline (g, "-cpu");
add_cmdline (g, buf);
}
if (g->smp > 1) {
snprintf (buf, sizeof buf, "%d", g->smp);