[PATCH] kvm tools: Emit a more informative error message when /dev/kvm does not open

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

 



When for some reason virtualization is not available on a box, the user
gets this cryptic error message:

  open: No such device

The user has no idea what happened - what is being opened and why is
there no such device?

This happens on one of my boxes, where there's VMX support indicated
in the CPU feature flags but where modules do not load because the
BIOS has virtualization disabled. The KVM kernel subsystem emits a
warning into the syslog:

  kvm: disabled by bios

But unfortunatey tools cannot really recover that error reason in any sane,
programmatic way when accessing /dev/kvm.

So do the best we can, we suggest to the user to look into the syslog for
the reason of the error:

  Fatal: '/dev/kvm' KVM driver not available.
  # (If the KVM module is loaded then 'dmesg' may offer further clues about the failure.)

Also improve the fallback error message from 'open: No such device' to:

  Fatal, could not open /dev/kvm: No such device

... should there be any future error returns that are neither -ENOENT,
nor -ENODEV.

Signed-off-by: Ingo Molnar <mingo@xxxxxxx>
---
 tools/kvm/kvm.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 93d48b3..188cd98 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -174,8 +174,12 @@ struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size)
 	if (self->sys_fd < 0) {
 		if (errno == ENOENT)
 			die("'%s' not found. Please make sure your kernel has CONFIG_KVM enabled and that the KVM modules are loaded.", kvm_dev);
+		if (errno == ENODEV)
+			die("'%s' KVM driver not available.\n  # (If the KVM module is loaded then 'dmesg' may offer further clues about the failure.)", kvm_dev);
 
-		die_perror("open");
+		fprintf(stderr, "  Fatal, could not open %s: ", kvm_dev);
+		perror(NULL);
+		exit(1);
 	}
 
 	ret = ioctl(self->sys_fd, KVM_GET_API_VERSION, 0);
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux