The function contains two almost identical parts. Let's consolidate them
into a single helper function and call it twice.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 7:
- new patch
src/qemu/qemu_capabilities.c | 67 ++++++++++++++++++------------------
1 file changed, 34 insertions(+), 33 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 6716e62e4a..b695b23fcc 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4355,19 +4355,19 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps
ATTRIBUTE_UNUSED,
static int
-virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
- const char *libDir,
- uid_t runUid,
- gid_t runGid,
- char **qmperr)
+virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps,
+ const char *libDir,
+ uid_t runUid,
+ gid_t runGid,
+ char **qmperr,
+ bool onlyTCG)
{
qemuProcessQMPPtr proc = NULL;
- qemuProcessQMPPtr procTCG = NULL;
int ret = -1;
int rc;
if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
- runUid, runGid, qmperr, false)))
+ runUid, runGid, qmperr, onlyTCG)))
goto cleanup;
if ((rc = qemuProcessQMPRun(proc)) != 0) {
@@ -4376,40 +4376,41 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
goto cleanup;
}
- if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0)
- goto cleanup;
-
- if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
- /* The second QEMU process probes for TCG capabilities
- * in case the first process reported KVM as enabled
- * (otherwise the first one already reported TCG capabilities). */
-
- qemuProcessQMPStop(proc);
-
- procTCG = qemuProcessQMPNew(qemuCaps->binary, libDir,
- runUid, runGid, NULL, true);
-
- if ((rc = qemuProcessQMPRun(procTCG)) != 0) {
- if (rc == 1)
- ret = 0;
- goto cleanup;
- }
-
- if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, procTCG->mon) < 0)
- goto cleanup;
- }
-
- ret = 0;
+ if (onlyTCG)
+ ret = virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon);
+ else
+ ret = virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon);
cleanup:
qemuProcessQMPStop(proc);
- qemuProcessQMPStop(procTCG);
qemuProcessQMPFree(proc);
- qemuProcessQMPFree(procTCG);
return ret;
}
+static int
+virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
+ const char *libDir,
+ uid_t runUid,
+ gid_t runGid,
+ char **qmperr)
+{
+ if (virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, qmperr, false) <
0)
+ return -1;
+
+ /*
+ * If KVM was enabled during the first probe, we need to explicitly probe
+ * for TCG capabilities by asking the same binary again and turning KVM
+ * off.
+ */
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
+ virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, NULL, true) < 0)
+ return -1;
+
+ return 0;
+}
+
+
#define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa361"
static void
--
2.20.1