[libvirt] [PATCH] qemu: check for kvm availability before starting kvm guests

This *kind of* addresses: https://bugzilla.redhat.com/show_bug.cgi?id=772395 (it doesn't eliminate the failure to start, but causes libvirt to give a better idea about the cause of the failure). If a guest uses a kvm emulator (e.g. /usr/bin/qemu-kvm) and the guest is started when kvm isn't available (either because virtualization is unavailable / has been disabled in the BIOS, or the kvm modules haven't been loaded for some reason), a semi-cryptic error message is logged: libvirtError: internal error Child process (LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin /usr/bin/qemu-kvm -device ? -device pci-assign,? -device virtio-blk-pci,? -device virtio-net-pci,?) status unexpected: exit status 1 This patch notices at process start that a guest needs kvm, and checks for the presence of /dev/kvm (a reasonable indicator that kvm is available) before trying to execute the qemu binary. If kvm isn't available, a more useful (too verbose??) error is logged. --- src/qemu/qemu_process.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 105b895..e0fd073 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3031,6 +3031,17 @@ int qemuProcessStart(virConnectPtr conn, if ((logfile = qemuDomainCreateLog(driver, vm, false)) < 0) goto cleanup; + if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) { + VIR_DEBUG("Checking for KVM availability"); + if (access("/dev/kvm", F_OK) != 0) { + qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Domain requires KVM, but it is not available. " + "Check that virtualization is enabled in the host BIOS, " + "and host configuration is setup to load the kvm modules.")); + goto cleanup; + } + } + VIR_DEBUG("Determining emulator version"); qemuCapsFree(priv->qemuCaps); priv->qemuCaps = NULL; -- 1.7.7.4

On 01/09/2012 01:05 PM, Laine Stump wrote:
This *kind of* addresses:
https://bugzilla.redhat.com/show_bug.cgi?id=772395
(it doesn't eliminate the failure to start, but causes libvirt to give a better idea about the cause of the failure).
If a guest uses a kvm emulator (e.g. /usr/bin/qemu-kvm) and the guest is started when kvm isn't available (either because virtualization is unavailable / has been disabled in the BIOS, or the kvm modules haven't been loaded for some reason), a semi-cryptic error message is logged:
libvirtError: internal error Child process (LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin /usr/bin/qemu-kvm -device ? -device pci-assign,? -device virtio-blk-pci,? -device virtio-net-pci,?) status unexpected: exit status 1
This patch notices at process start that a guest needs kvm, and checks for the presence of /dev/kvm (a reasonable indicator that kvm is available) before trying to execute the qemu binary. If kvm isn't available, a more useful (too verbose??) error is logged.
Nah, I think it is useful to have a message that long, as I have seen quite a few people on the IRC channel (myself included, at one point) that have forgotten to turn on the BIOS to allow kvm. ACK.
+ if (vm->def->virtType == VIR_DOMAIN_VIRT_KVM) { + VIR_DEBUG("Checking for KVM availability"); + if (access("/dev/kvm", F_OK) != 0) { + qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Domain requires KVM, but it is not available. " + "Check that virtualization is enabled in the host BIOS, " + "and host configuration is setup to load the kvm modules.")); + goto cleanup; + } + }
-- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 01/09/2012 03:23 PM, Eric Blake wrote:
This *kind of* addresses:
https://bugzilla.redhat.com/show_bug.cgi?id=772395
(it doesn't eliminate the failure to start, but causes libvirt to give a better idea about the cause of the failure).
If a guest uses a kvm emulator (e.g. /usr/bin/qemu-kvm) and the guest is started when kvm isn't available (either because virtualization is unavailable / has been disabled in the BIOS, or the kvm modules haven't been loaded for some reason), a semi-cryptic error message is logged:
libvirtError: internal error Child process (LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin /usr/bin/qemu-kvm -device ? -device pci-assign,? -device virtio-blk-pci,? -device virtio-net-pci,?) status unexpected: exit status 1
This patch notices at process start that a guest needs kvm, and checks for the presence of /dev/kvm (a reasonable indicator that kvm is available) before trying to execute the qemu binary. If kvm isn't available, a more useful (too verbose??) error is logged. Nah, I think it is useful to have a message that long, as I have seen quite a few people on the IRC channel (myself included, at one point)
On 01/09/2012 01:05 PM, Laine Stump wrote: that have forgotten to turn on the BIOS to allow kvm.
Note that this patch will only be helpful in cases where kvm was available when the domain was defined, but is not available at runtime. The former would be an issue to be solved in virt-install/virt-manager, since they normally just pick from what libvirt tells them is available.
ACK.
Pushed. Thanks!
participants (2)
-
Eric Blake
-
Laine Stump