]> xenbits.xensource.com Git - libvirt.git/commitdiff
configure.in, src/qemu_driver.h, src/qemu_driver.c: KVM
authorRichard W.M. Jones <rjones@redhat.com>
Wed, 17 Sep 2008 14:07:49 +0000 (14:07 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Wed, 17 Sep 2008 14:07:49 +0000 (14:07 +0000)
          can determine max VCPUs at runtime (Guido Günther).

ChangeLog
configure.in
src/qemu_driver.c
src/qemu_driver.h

index a940856bd004a06a6ce9b5a8e86b0bc7b9648bd3..faf25bdf3ee6c4066ae072c951d8046894316a1b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Sep 17 15:03:00 BST 2008 Richard W.M. Jones <rjones@redhat.com>
+
+       * configure.in, src/qemu_driver.h, src/qemu_driver.c: KVM
+         can determine max VCPUs at runtime (Guido Günther).
+
 Tue Sep 16 12:43:00 EST 2008 Cole Robinson <crobinso@redhat.com>
 
        * src/storack_backend_disk.c: Implement disk volume delete
index 52f70c7400a5aae9edaf5771efb4a8404377be15..fcc2cdec7edd1fd2f4d2fe7cca95d0acc241ecb5 100644 (file)
@@ -316,6 +316,11 @@ if test "$with_qemu" = "yes" -o "$with_lxc" = "yes" ; then
                    AC_MSG_ERROR([You must install kernel-headers in order to compile libvirt]))
 fi
 
+dnl
+dnl check for kvm headers
+dnl 
+AC_CHECK_HEADERS([linux/kvm.h])
+
 dnl Need to test if pkg-config exists
 PKG_PROG_PKG_CONFIG
 
index 8cc32bcd69c5ebc740ba25825feea314ef347f33..99044218d34fddbb5bc5d3843b49666e263e7045 100644 (file)
@@ -42,6 +42,7 @@
 #include <pwd.h>
 #include <stdio.h>
 #include <sys/wait.h>
+#include <sys/ioctl.h>
 
 #if HAVE_NUMACTL
 #include <numa.h>
@@ -1804,6 +1805,27 @@ static const char *qemudGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
     return "QEMU";
 }
 
+
+static int kvmGetMaxVCPUs(void) {
+    int maxvcpus = 1;
+
+    int r, fd;
+    
+    fd = open(KVM_DEVICE, O_RDONLY);
+    if (fd < 0) {
+        qemudLog(QEMUD_WARN, _("Unable to open " KVM_DEVICE ": %s\n"), strerror(errno));
+        return maxvcpus;
+    }
+
+    r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS);
+    if (r > 0)
+        maxvcpus = r;
+
+    close(fd);
+    return maxvcpus;
+}
+
+
 static int qemudGetMaxVCPUs(virConnectPtr conn, const char *type) {
     if (!type)
         return 16;
@@ -1814,7 +1836,7 @@ static int qemudGetMaxVCPUs(virConnectPtr conn, const char *type) {
     /* XXX future KVM will support SMP. Need to probe
        kernel to figure out KVM module version i guess */
     if (STRCASEEQ(type, "kvm"))
-        return 1;
+        return kvmGetMaxVCPUs();
 
     if (STRCASEEQ(type, "kqemu"))
         return 1;
index dbcca705a7c8a0763a8a5195df82e2d21cd32839..e0662e0ad80c3add097fabc37dcc040e2a366e9e 100644 (file)
 
 #include "internal.h"
 
+#if HAVE_LINUX_KVM_H
+#include <linux/kvm.h>
+#endif
+
+/* device for kvm ioctls */
+#define KVM_DEVICE "/dev/kvm"
+
+/* add definitions missing in older linux/kvm.h */
+#ifndef KVMIO
+#  define KVMIO 0xAE
+#endif
+#ifndef KVM_CHECK_EXTENSION
+#  define KVM_CHECK_EXTENSION       _IO(KVMIO,   0x03)
+#endif
+#ifndef KVM_CAP_NR_VCPUS
+#  define KVM_CAP_NR_VCPUS 9       /* returns max vcpus per vm */
+#endif
+
 int qemudRegister(void);
 
 #endif /* QEMUD_DRIVER_H */