]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Emit a more informative error message when /dev/kvm does not open
authorIngo Molnar <mingo@elte.hu>
Fri, 8 Apr 2011 14:55:33 +0000 (16:55 +0200)
committerPekka Enberg <penberg@kernel.org>
Fri, 8 Apr 2011 15:18:00 +0000 (18:18 +0300)
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>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/kvm.c

index 93d48b3454c88489fc6532e09fcead8ac2e7910e..188cd98b0d060bb53fa3eb460e2a1d620c6c0d1e 100644 (file)
@@ -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);