mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-04 10:55:19 +00:00
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: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
0e12707680
commit
c7b59b66ab
@ -4355,19 +4355,19 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
|
virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps,
|
||||||
const char *libDir,
|
const char *libDir,
|
||||||
uid_t runUid,
|
uid_t runUid,
|
||||||
gid_t runGid,
|
gid_t runGid,
|
||||||
char **qmperr)
|
char **qmperr,
|
||||||
|
bool onlyTCG)
|
||||||
{
|
{
|
||||||
qemuProcessQMPPtr proc = NULL;
|
qemuProcessQMPPtr proc = NULL;
|
||||||
qemuProcessQMPPtr procTCG = NULL;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
|
if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
|
||||||
runUid, runGid, qmperr, false)))
|
runUid, runGid, qmperr, onlyTCG)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((rc = qemuProcessQMPRun(proc)) != 0) {
|
if ((rc = qemuProcessQMPRun(proc)) != 0) {
|
||||||
@ -4376,40 +4376,41 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0)
|
if (onlyTCG)
|
||||||
goto cleanup;
|
ret = virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon);
|
||||||
|
else
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
|
ret = virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon);
|
||||||
/* 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;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
qemuProcessQMPStop(proc);
|
qemuProcessQMPStop(proc);
|
||||||
qemuProcessQMPStop(procTCG);
|
|
||||||
qemuProcessQMPFree(proc);
|
qemuProcessQMPFree(proc);
|
||||||
qemuProcessQMPFree(procTCG);
|
|
||||||
return ret;
|
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"
|
#define MESSAGE_ID_CAPS_PROBE_FAILURE "8ae2f3fb-2dbe-498e-8fbd-012d40afa361"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user