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