[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 |   44 +++++++++++++++++++++++++++++++-------------
 1 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index ce835aa..9ff1402 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -414,6 +414,7 @@ virCapsPtr qemudCapsInit(void) {
 
 static unsigned int qemudComputeCmdFlags(const char *help,
                                          unsigned int version,
+                                         unsigned int is_kvm,
                                          unsigned int kvm_version)
 {
     unsigned int flags = 0;
@@ -439,7 +440,8 @@ static unsigned int qemudComputeCmdFlags(const char *help,
         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;
 
     /*
@@ -452,15 +454,15 @@ static unsigned int qemudComputeCmdFlags(const char *help,
      * 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;
     }
 
     return flags;
@@ -470,21 +472,31 @@ static unsigned int qemudComputeCmdFlags(const char *help,
  * 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 qemudParseHelpStr(const char *help,
                              unsigned int *flags,
                              unsigned int *version,
+                             unsigned int *is_kvm,
                              unsigned int *kvm_version)
 {
     unsigned major, minor, micro;
     const char *p = help;
 
-    *flags = *version = *kvm_version = 0;
+    *flags = *version = *is_kvm = *kvm_version = 0;
 
     if (!STRPREFIX(p, QEMU_VERSION_STR))
         goto fail;
@@ -507,9 +519,13 @@ static int qemudParseHelpStr(const char *help,
     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);
@@ -521,12 +537,14 @@ static int qemudParseHelpStr(const char *help,
 
     *version = (major * 1000 * 1000) + (minor * 1000) + micro;
 
-    *flags = qemudComputeCmdFlags(help, *version, *kvm_version);
+    *flags = qemudComputeCmdFlags(help, *version, *is_kvm, *kvm_version);
 
     qemudDebug("Version %u.%u.%u, cooked version %u, flags %u",
                major, minor, micro, *version, *flags);
     if (*kvm_version)
-        qemudDebug("KVM version %u detected", *kvm_version);
+        qemudDebug("KVM version %d detected", *kvm_version);
+    else if (*is_kvm)
+        qemudDebug("qemu-kvm version %u.%u.%u detected", major, minor, micro);
 
     return 0;
 
@@ -552,7 +570,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)
@@ -573,7 +591,7 @@ int qemudExtractVersionInfo(const char *qemu,
         goto cleanup2;
     }
 
-    if (qemudParseHelpStr(help, &version, &kvm_version, &flags) == -1)
+    if (qemudParseHelpStr(help, &version, &kvm_version, &is_kvm, &flags) == -1)
         goto cleanup2;
 
     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]