summaryrefslogtreecommitdiffstats
path: root/src/guestfs.c
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-02-09 16:30:18 +0000
committerRichard Jones <rjones@redhat.com>2010-02-09 16:30:18 +0000
commit245ac5673700f54479e9408e8659cb68f80c344a (patch)
tree55cc3db9d8deef5dbcd8d35c600f73ca0770481c /src/guestfs.c
parente4fbe3e2cd130fa0b1b21a105729cd6ef32aac38 (diff)
downloadlibguestfs-245ac5673700f54479e9408e8659cb68f80c344a.tar.gz
libguestfs-245ac5673700f54479e9408e8659cb68f80c344a.tar.xz
libguestfs-245ac5673700f54479e9408e8659cb68f80c344a.zip
Add -enable-kvm option to qemu command line.
If the version of qemu being used supports -enable-kvm option, then check if /dev/kvm is openable and add this option. I have found this option makes no difference, although it is *supposed* to enable KVM (hardware virtualization) support.
Diffstat (limited to 'src/guestfs.c')
-rw-r--r--src/guestfs.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/guestfs.c b/src/guestfs.c
index 1d6d40bf..9908e7f8 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -858,6 +858,7 @@ static void print_timestamped_message (guestfs_h *g, const char *fs, ...);
static int build_supermin_appliance (guestfs_h *g, const char *path, char **kernel, char **initrd);
static int test_qemu (guestfs_h *g);
static int qemu_supports (guestfs_h *g, const char *option);
+static int is_openable (guestfs_h *g, const char *path, int flags);
static void print_cmdline (guestfs_h *g);
static const char *kernel_name = "vmlinuz." REPO "." host_cpu;
@@ -1091,6 +1092,22 @@ guestfs__launch (guestfs_h *g)
*/
g->cmdline[0] = g->qemu;
+ /* 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.
+ */
+ if (qemu_supports (g, "-enable-kvm") &&
+ is_openable (g, "/dev/kvm", O_RDWR))
+ add_cmdline (g, "-enable-kvm");
+
/* Newer versions of qemu (from around 2009/12) changed the
* behaviour of monitors so that an implicit '-monitor stdio' is
* assumed if we are in -nographic mode and there is no other
@@ -1647,6 +1664,20 @@ qemu_supports (guestfs_h *g, const char *option)
return g->qemu_help && strstr (g->qemu_help, option) != NULL;
}
+/* Check if a file can be opened. */
+static int
+is_openable (guestfs_h *g, const char *path, int flags)
+{
+ int fd = open (path, flags);
+ if (fd == -1) {
+ if (g->verbose)
+ perror (path);
+ return 0;
+ }
+ close (fd);
+ return 1;
+}
+
/* Check the peer effective UID for a TCP socket. Ideally we'd like
* SO_PEERCRED for a loopback TCP socket. This isn't possible on
* Linux (but it is on Solaris!) so we read /proc/net/tcp instead.