9c6c51
From b8ca3f396e09f0ba190656363c0d1fc6a0dd9cd6 Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <b8ca3f396e09f0ba190656363c0d1fc6a0dd9cd6@dist-git>
9c6c51
From: Andrea Bolognani <abologna@redhat.com>
9c6c51
Date: Mon, 17 Sep 2018 18:00:52 +0200
9c6c51
Subject: [PATCH] qemu: Clarify QEMU_CAPS_KVM
9c6c51
9c6c51
This capability is documented as having one meaning (whether
9c6c51
KVM is enabled by default) but is actually assigned two other
9c6c51
meanings over its life: whether the query-kvm QMP command is
9c6c51
available at first, and later on whether KVM is usable / was
9c6c51
used during probing.
9c6c51
9c6c51
Since the query-kvm QMP command was available in 1.5.0, we
9c6c51
can avoid probing for it; additionally, we can simplify the
9c6c51
logic by setting the flag when it applies instead of initially
9c6c51
setting it and then clearing it when it doesn't.
9c6c51
9c6c51
The flag's description is also updated to reflect reality.
9c6c51
9c6c51
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
9c6c51
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
9c6c51
(cherry picked from commit c3be8bb4235b447dc29568f96b8c31cc741fc358)
9c6c51
9c6c51
https://bugzilla.redhat.com/show_bug.cgi?id=1629862
9c6c51
9c6c51
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
9c6c51
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
9c6c51
---
9c6c51
 src/qemu/qemu_capabilities.c | 19 ++-----------------
9c6c51
 src/qemu/qemu_capabilities.h |  2 +-
9c6c51
 2 files changed, 3 insertions(+), 18 deletions(-)
9c6c51
9c6c51
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
9c6c51
index 9b3f35553b..c7ece21dd2 100644
9c6c51
--- a/src/qemu/qemu_capabilities.c
9c6c51
+++ b/src/qemu/qemu_capabilities.c
9c6c51
@@ -1003,7 +1003,6 @@ struct virQEMUCapsStringFlags virQEMUCapsCommands[] = {
9c6c51
     { "block-stream", QEMU_CAPS_BLOCKJOB_ASYNC },
9c6c51
     { "dump-guest-memory", QEMU_CAPS_DUMP_GUEST_MEMORY },
9c6c51
     { "query-spice", QEMU_CAPS_SPICE },
9c6c51
-    { "query-kvm", QEMU_CAPS_KVM },
9c6c51
     { "block-commit", QEMU_CAPS_BLOCK_COMMIT },
9c6c51
     { "query-vnc", QEMU_CAPS_VNC },
9c6c51
     { "drive-mirror", QEMU_CAPS_DRIVE_MIRROR },
9c6c51
@@ -2584,25 +2583,11 @@ virQEMUCapsProbeQMPKVMState(virQEMUCapsPtr qemuCaps,
9c6c51
     bool enabled = false;
9c6c51
     bool present = false;
9c6c51
 
9c6c51
-    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
9c6c51
-        return 0;
9c6c51
-
9c6c51
     if (qemuMonitorGetKVMState(mon, &enabled, &present) < 0)
9c6c51
         return -1;
9c6c51
 
9c6c51
-    /* The QEMU_CAPS_KVM flag was initially set according to the QEMU
9c6c51
-     * reporting the recognition of 'query-kvm' QMP command. That merely
9c6c51
-     * indicates existence of the command though, not whether KVM support
9c6c51
-     * is actually available, nor whether it is enabled by default.
9c6c51
-     *
9c6c51
-     * If it is not present we need to clear the flag, and if it is
9c6c51
-     * not enabled by default we need to change the flag.
9c6c51
-     */
9c6c51
-    if (!present) {
9c6c51
-        virQEMUCapsClear(qemuCaps, QEMU_CAPS_KVM);
9c6c51
-    } else if (!enabled) {
9c6c51
-        virQEMUCapsClear(qemuCaps, QEMU_CAPS_KVM);
9c6c51
-    }
9c6c51
+    if (present && enabled)
9c6c51
+        virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM);
9c6c51
 
9c6c51
     return 0;
9c6c51
 }
9c6c51
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
9c6c51
index 98668115d6..6acd9fe825 100644
9c6c51
--- a/src/qemu/qemu_capabilities.h
9c6c51
+++ b/src/qemu/qemu_capabilities.h
9c6c51
@@ -65,7 +65,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */
9c6c51
     X_QEMU_CAPS_MIGRATE_QEMU_TCP, /* have qemu tcp migration */
9c6c51
     X_QEMU_CAPS_MIGRATE_QEMU_EXEC, /* have qemu exec migration */
9c6c51
     X_QEMU_CAPS_DRIVE_CACHE_V2, /* cache= flag wanting new v2 values */
9c6c51
-    QEMU_CAPS_KVM, /* Whether KVM is enabled by default */
9c6c51
+    QEMU_CAPS_KVM, /* Whether KVM is usable / was used during probing */
9c6c51
     X_QEMU_CAPS_DRIVE_FORMAT, /* Is -drive format= avail */
9c6c51
 
9c6c51
     /* 15 */
9c6c51
-- 
9c6c51
2.19.1
9c6c51