From b95f0c7835c8524b0ab84fbe5ca9f7b8e79b82bf Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Fri, 8 Apr 2011 16:55:33 +0200 Subject: [PATCH] kvm tools: Emit a more informative error message when /dev/kvm does not open 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 Signed-off-by: Pekka Enberg --- tools/kvm/kvm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 93d48b3454c8..188cd98b0d06 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); -- 2.39.5