public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm tools: Emit a more informative error message when /dev/kvm does not open
@ 2011-04-08 14:55 Ingo Molnar
  0 siblings, 0 replies; only message in thread
From: Ingo Molnar @ 2011-04-08 14:55 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: kvm


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@elte.hu>
---
 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);

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-08 14:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-08 14:55 [PATCH] kvm tools: Emit a more informative error message when /dev/kvm does not open Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox