提交 c7b59b66 编写于 作者: J Jiri Denemark

qemu_capabilities: Refactor virQEMUCapsInitQMP

The function contains two almost identical parts. Let's consolidate them
into a single helper function and call it twice.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 0e127076
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册