qemu_process: Hide qemuProcessQMPStop

Users qemuProcessQMP struct were always forced to call both
qemuProcessQMPStop and qemuProcessQMPFree when they are done with the
process. We can just call qemuProcessQMPStop from qemuProcessQMPFree and
let users call qemuProcessQMPFree only.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2019-02-13 17:18:51 +01:00
parent e691b150e4
commit f87eb56067
3 changed files with 45 additions and 50 deletions

View File

@ -4397,7 +4397,6 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps,
if (ret < 0)
virQEMUCapsLogProbeFailure(qemuCaps->binary);
qemuProcessQMPStop(proc);
qemuProcessQMPFree(proc);
return ret;
}

View File

@ -8324,6 +8324,49 @@ static qemuMonitorCallbacks callbacks = {
};
static void
qemuProcessQMPStop(qemuProcessQMPPtr proc)
{
if (proc->mon) {
virObjectUnlock(proc->mon);
qemuMonitorClose(proc->mon);
proc->mon = NULL;
}
if (proc->cmd) {
virCommandAbort(proc->cmd);
virCommandFree(proc->cmd);
proc->cmd = NULL;
}
if (proc->monpath)
unlink(proc->monpath);
virDomainObjEndAPI(&proc->vm);
if (proc->pid != 0) {
char ebuf[1024];
VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid);
if (virProcessKill(proc->pid, SIGKILL) < 0 && errno != ESRCH)
VIR_ERROR(_("Failed to kill process %lld: %s"),
(long long)proc->pid,
virStrerror(errno, ebuf, sizeof(ebuf)));
proc->pid = 0;
}
if (proc->pidfile)
unlink(proc->pidfile);
}
/**
* qemuProcessQMPFree:
* @proc: Stores process and connection state
*
* Kill QEMU process and free process data structure.
*/
void
qemuProcessQMPFree(qemuProcessQMPPtr proc)
{
@ -8535,7 +8578,6 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc)
* proc = qemuProcessQMPNew(binary, libDir, runUid, runGid, forceTCG);
* qemuProcessQMPStart(proc);
* ** Send QMP Queries to QEMU using monitor (proc->mon) **
* qemuProcessQMPStop(proc);
* qemuProcessQMPFree(proc);
*
* Process error output (proc->stderr) remains available in qemuProcessQMP
@ -8552,57 +8594,13 @@ qemuProcessQMPStart(qemuProcessQMPPtr proc)
goto cleanup;
if (qemuProcessQMPLaunch(proc) < 0)
goto stop;
goto cleanup;
if (qemuProcessQMPConnectMonitor(proc) < 0)
goto stop;
goto cleanup;
ret = 0;
cleanup:
return ret;
stop:
qemuProcessQMPStop(proc);
goto cleanup;
}
void
qemuProcessQMPStop(qemuProcessQMPPtr proc)
{
if (!proc)
return;
if (proc->mon) {
virObjectUnlock(proc->mon);
qemuMonitorClose(proc->mon);
proc->mon = NULL;
}
if (proc->cmd) {
virCommandAbort(proc->cmd);
virCommandFree(proc->cmd);
proc->cmd = NULL;
}
if (proc->monpath)
unlink(proc->monpath);
virDomainObjEndAPI(&proc->vm);
if (proc->pid != 0) {
char ebuf[1024];
VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid);
if (virProcessKill(proc->pid, SIGKILL) < 0 && errno != ESRCH)
VIR_ERROR(_("Failed to kill process %lld: %s"),
(long long)proc->pid,
virStrerror(errno, ebuf, sizeof(ebuf)));
proc->pid = 0;
}
if (proc->pidfile)
unlink(proc->pidfile);
}

View File

@ -242,6 +242,4 @@ void qemuProcessQMPFree(qemuProcessQMPPtr proc);
int qemuProcessQMPStart(qemuProcessQMPPtr proc);
void qemuProcessQMPStop(qemuProcessQMPPtr proc);
#endif /* LIBVIRT_QEMU_PROCESS_H */