[libvirt] [PATCH 2/3] Detect newer qemu-kvm versions

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

 



The KVM version string can be one of the following:

  - qemu-kvm-x.y.z in stable releases
  - kvm-XX for kvm versions up to kvm-85
  - qemu-kvm-devel-XX for kvm version kvm-86 and later

There are only a few of places where we need to detect
differences between KVM versions based on 0.9.1:

  1) VNET_HDR introduced in kvm-74

  2) -incoming tcp introduced in kvm-79

  3) -incoming exec introduced in kvm-80

  4) -incoming stdio in all earlier kvm versions

With qemu-kvm-0.10.x, we can now assume that (1) is available
if it's a KVM release, (2) and (3) is always available and
(4) is never available.

So, from now on we should only need to check the qemu version
number and the "is_kvm" flag for detecting feature availability.
We only need the KVM version number for older releases.

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>
---
 src/qemu_conf.c |   39 ++++++++++++++++++++++++++++-----------
 1 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index f6a8390..ea0d2f9 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -416,20 +416,30 @@ virCapsPtr qemudCapsInit(void) {
  * version number. The first bit is easy, just parse
  * 'QEMU PC emulator version x.y.z'.
  *
- * With qemu-kvm, however, that is followed by a kvm-XX
- * string in parenthesis.
+ * With qemu-kvm, however, that is followed by a string
+ * in parenthesis as follows:
+ *  - qemu-kvm-x.y.z in stable releases
+ *  - kvm-XX for kvm versions up to kvm-85
+ *  - qemu-kvm-devel-XX for kvm version kvm-86 and later
+ *
+ * For qemu-kvm versions before 0.10.z, we need to detect
+ * the KVM version number for some features. With 0.10.z
+ * and later, we just need the QEMU version number and
+ * whether it is KVM QEMU or mainline QEMU.
  */
 #define QEMU_VERSION_STR    "QEMU PC emulator version "
+#define QEMU_KVM_VER_PREFIX " (qemu-kvm-"
 #define KVM_VER_PREFIX      " (kvm-"
 
 static int qemudParseVersionStr(const char *str,
                                 unsigned int *version,
+                                unsigned int *is_kvm,
                                 unsigned int *kvm_version)
 {
     unsigned major, minor, micro;
     const char *p = str;
 
-    *version = *kvm_version = 0;
+    *version = *is_kvm = *kvm_version = 0;
 
     if (!STRPREFIX(p, QEMU_VERSION_STR))
         goto fail;
@@ -452,9 +462,13 @@ static int qemudParseVersionStr(const char *str,
     if (major == -1)
         goto fail;
 
-    if (STRPREFIX(p, KVM_VER_PREFIX)) {
+    if (STRPREFIX(p, QEMU_KVM_VER_PREFIX)) {
+        *is_kvm = 1;
+        p += strlen(QEMU_KVM_VER_PREFIX);
+    } else if (STRPREFIX(p, KVM_VER_PREFIX)) {
         int ret;
 
+        *is_kvm = 1;
         p += strlen(KVM_VER_PREFIX);
 
         ret = virParseNumber(&p);
@@ -470,6 +484,8 @@ static int qemudParseVersionStr(const char *str,
                major, minor, micro, *version);
     if (*kvm_version)
         qemudDebug("KVM version %d detected", *kvm_version);
+    else if (*is_kvm)
+        qemudDebug("qemu-kvm version %d.%d.%d detected", major, minor, micro);
 
     return 0;
 
@@ -488,7 +504,7 @@ int qemudExtractVersionInfo(const char *qemu,
     pid_t child;
     int newstdout = -1;
     int ret = -1, status;
-    unsigned int version, kvm_version;
+    unsigned int version, is_kvm, kvm_version;
     unsigned int flags = 0;
 
     if (retflags)
@@ -512,7 +528,7 @@ int qemudExtractVersionInfo(const char *qemu,
     char *eol = strchr(help, '\n');
     if (eol) *eol = '\0';
 
-    if (qemudParseVersionStr(help, &version, &kvm_version) == -1)
+    if (qemudParseVersionStr(help, &version, &is_kvm, &kvm_version) == -1)
         goto cleanup2;
 
     if (strstr(help, "-no-kqemu"))
@@ -536,7 +552,8 @@ int qemudExtractVersionInfo(const char *qemu,
         flags |= QEMUD_CMD_FLAG_DRIVE_BOOT;
     if (version >= 9000)
         flags |= QEMUD_CMD_FLAG_VNC_COLON;
-    if (kvm_version >= 74)
+
+    if (is_kvm && (version >= 10000 || kvm_version >= 74))
         flags |= QEMUD_CMD_FLAG_VNET_HDR;
 
     /*
@@ -549,15 +566,15 @@ int qemudExtractVersionInfo(const char *qemu,
      * was broken, because it blocked the monitor console
      * while waiting for data, so pretend it doesn't exist
      */
-    if (kvm_version >= 79) {
+    if (version >= 10000) {
+        flags |= QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP;
+        flags |= QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC;
+    } else if (kvm_version >= 79) {
         flags |= QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP;
         if (kvm_version >= 80)
             flags |= QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC;
     } else if (kvm_version > 0) {
         flags |= QEMUD_CMD_FLAG_MIGRATE_KVM_STDIO;
-    } else if (version >= 10000) {
-        flags |= QEMUD_CMD_FLAG_MIGRATE_QEMU_TCP;
-        flags |= QEMUD_CMD_FLAG_MIGRATE_QEMU_EXEC;
     }
 
     if (retversion)
-- 
1.6.0.6

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]