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

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: NJiri Denemark <jdenemar@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 e691b150
...@@ -4397,7 +4397,6 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, ...@@ -4397,7 +4397,6 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps,
if (ret < 0) if (ret < 0)
virQEMUCapsLogProbeFailure(qemuCaps->binary); virQEMUCapsLogProbeFailure(qemuCaps->binary);
qemuProcessQMPStop(proc);
qemuProcessQMPFree(proc); qemuProcessQMPFree(proc);
return ret; return ret;
} }
......
...@@ -8324,6 +8324,49 @@ static qemuMonitorCallbacks callbacks = { ...@@ -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 void
qemuProcessQMPFree(qemuProcessQMPPtr proc) qemuProcessQMPFree(qemuProcessQMPPtr proc)
{ {
...@@ -8535,7 +8578,6 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) ...@@ -8535,7 +8578,6 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc)
* proc = qemuProcessQMPNew(binary, libDir, runUid, runGid, forceTCG); * proc = qemuProcessQMPNew(binary, libDir, runUid, runGid, forceTCG);
* qemuProcessQMPStart(proc); * qemuProcessQMPStart(proc);
* ** Send QMP Queries to QEMU using monitor (proc->mon) ** * ** Send QMP Queries to QEMU using monitor (proc->mon) **
* qemuProcessQMPStop(proc);
* qemuProcessQMPFree(proc); * qemuProcessQMPFree(proc);
* *
* Process error output (proc->stderr) remains available in qemuProcessQMP * Process error output (proc->stderr) remains available in qemuProcessQMP
...@@ -8552,57 +8594,13 @@ qemuProcessQMPStart(qemuProcessQMPPtr proc) ...@@ -8552,57 +8594,13 @@ qemuProcessQMPStart(qemuProcessQMPPtr proc)
goto cleanup; goto cleanup;
if (qemuProcessQMPLaunch(proc) < 0) if (qemuProcessQMPLaunch(proc) < 0)
goto stop; goto cleanup;
if (qemuProcessQMPConnectMonitor(proc) < 0) if (qemuProcessQMPConnectMonitor(proc) < 0)
goto stop; goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
return ret; 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);
} }
...@@ -242,6 +242,4 @@ void qemuProcessQMPFree(qemuProcessQMPPtr proc); ...@@ -242,6 +242,4 @@ void qemuProcessQMPFree(qemuProcessQMPPtr proc);
int qemuProcessQMPStart(qemuProcessQMPPtr proc); int qemuProcessQMPStart(qemuProcessQMPPtr proc);
void qemuProcessQMPStop(qemuProcessQMPPtr proc);
#endif /* LIBVIRT_QEMU_PROCESS_H */ #endif /* LIBVIRT_QEMU_PROCESS_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册