mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
qemu_process: Refer to proc not cmd in process code
s/cmd/proc/ in process code imported from qemu_capabilities. Signed-off-by: Chris Venteicher <cventeic@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
1aa4257569
commit
3dcdd18b6b
@ -4361,39 +4361,39 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
|
|||||||
gid_t runGid,
|
gid_t runGid,
|
||||||
char **qmperr)
|
char **qmperr)
|
||||||
{
|
{
|
||||||
qemuProcessQMPPtr cmd = NULL;
|
qemuProcessQMPPtr proc = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!(cmd = qemuProcessQMPNew(qemuCaps->binary, libDir,
|
if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
|
||||||
runUid, runGid, qmperr)))
|
runUid, runGid, qmperr)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((rc = qemuProcessQMPRun(cmd, false)) != 0) {
|
if ((rc = qemuProcessQMPRun(proc, false)) != 0) {
|
||||||
if (rc == 1)
|
if (rc == 1)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virQEMUCapsInitQMPMonitor(qemuCaps, cmd->mon) < 0)
|
if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
|
||||||
qemuProcessQMPAbort(cmd);
|
qemuProcessQMPAbort(proc);
|
||||||
if ((rc = qemuProcessQMPRun(cmd, true)) != 0) {
|
if ((rc = qemuProcessQMPRun(proc, true)) != 0) {
|
||||||
if (rc == 1)
|
if (rc == 1)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, cmd->mon) < 0)
|
if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
qemuProcessQMPFree(cmd);
|
qemuProcessQMPFree(proc);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8325,17 +8325,17 @@ static qemuMonitorCallbacks callbacks = {
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
qemuProcessQMPFree(qemuProcessQMPPtr cmd)
|
qemuProcessQMPFree(qemuProcessQMPPtr proc)
|
||||||
{
|
{
|
||||||
if (!cmd)
|
if (!proc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qemuProcessQMPAbort(cmd);
|
qemuProcessQMPAbort(proc);
|
||||||
VIR_FREE(cmd->binary);
|
VIR_FREE(proc->binary);
|
||||||
VIR_FREE(cmd->monpath);
|
VIR_FREE(proc->monpath);
|
||||||
VIR_FREE(cmd->monarg);
|
VIR_FREE(proc->monarg);
|
||||||
VIR_FREE(cmd->pidfile);
|
VIR_FREE(proc->pidfile);
|
||||||
VIR_FREE(cmd);
|
VIR_FREE(proc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -8346,25 +8346,25 @@ qemuProcessQMPNew(const char *binary,
|
|||||||
gid_t runGid,
|
gid_t runGid,
|
||||||
char **qmperr)
|
char **qmperr)
|
||||||
{
|
{
|
||||||
qemuProcessQMPPtr cmd = NULL;
|
qemuProcessQMPPtr proc = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(cmd) < 0)
|
if (VIR_ALLOC(proc) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_STRDUP(cmd->binary, binary) < 0)
|
if (VIR_STRDUP(proc->binary, binary) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
cmd->runUid = runUid;
|
proc->runUid = runUid;
|
||||||
cmd->runGid = runGid;
|
proc->runGid = runGid;
|
||||||
cmd->qmperr = qmperr;
|
proc->qmperr = qmperr;
|
||||||
|
|
||||||
/* the ".sock" sufix is important to avoid a possible clash with a qemu
|
/* the ".sock" sufix is important to avoid a possible clash with a qemu
|
||||||
* domain called "capabilities"
|
* domain called "capabilities"
|
||||||
*/
|
*/
|
||||||
if (virAsprintf(&cmd->monpath, "%s/%s", libDir,
|
if (virAsprintf(&proc->monpath, "%s/%s", libDir,
|
||||||
"capabilities.monitor.sock") < 0)
|
"capabilities.monitor.sock") < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (virAsprintf(&cmd->monarg, "unix:%s,server,nowait", cmd->monpath) < 0)
|
if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* ".pidfile" suffix is used rather than ".pid" to avoid a possible clash
|
/* ".pidfile" suffix is used rather than ".pid" to avoid a possible clash
|
||||||
@ -8373,19 +8373,19 @@ qemuProcessQMPNew(const char *binary,
|
|||||||
* -daemonize we need QEMU to be allowed to create them, rather
|
* -daemonize we need QEMU to be allowed to create them, rather
|
||||||
* than libvirtd. So we're using libDir which QEMU can write to
|
* than libvirtd. So we're using libDir which QEMU can write to
|
||||||
*/
|
*/
|
||||||
if (virAsprintf(&cmd->pidfile, "%s/%s", libDir, "capabilities.pidfile") < 0)
|
if (virAsprintf(&proc->pidfile, "%s/%s", libDir, "capabilities.pidfile") < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
virPidFileForceCleanupPath(cmd->pidfile);
|
virPidFileForceCleanupPath(proc->pidfile);
|
||||||
|
|
||||||
cmd->config.type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
proc->config.type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
||||||
cmd->config.data.nix.path = cmd->monpath;
|
proc->config.data.nix.path = proc->monpath;
|
||||||
cmd->config.data.nix.listen = false;
|
proc->config.data.nix.listen = false;
|
||||||
|
|
||||||
return cmd;
|
return proc;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
qemuProcessQMPFree(cmd);
|
qemuProcessQMPFree(proc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8395,7 +8395,7 @@ qemuProcessQMPNew(const char *binary,
|
|||||||
* 1 when probing QEMU failed
|
* 1 when probing QEMU failed
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
qemuProcessQMPRun(qemuProcessQMPPtr cmd,
|
qemuProcessQMPRun(qemuProcessQMPPtr proc,
|
||||||
bool forceTCG)
|
bool forceTCG)
|
||||||
{
|
{
|
||||||
virDomainXMLOptionPtr xmlopt = NULL;
|
virDomainXMLOptionPtr xmlopt = NULL;
|
||||||
@ -8409,7 +8409,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr cmd,
|
|||||||
machine = "none,accel=kvm:tcg";
|
machine = "none,accel=kvm:tcg";
|
||||||
|
|
||||||
VIR_DEBUG("Try to probe capabilities of '%s' via QMP, machine %s",
|
VIR_DEBUG("Try to probe capabilities of '%s' via QMP, machine %s",
|
||||||
cmd->binary, machine);
|
proc->binary, machine);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We explicitly need to use -daemonize here, rather than
|
* We explicitly need to use -daemonize here, rather than
|
||||||
@ -8418,63 +8418,63 @@ qemuProcessQMPRun(qemuProcessQMPPtr cmd,
|
|||||||
* daemonize guarantees control won't return to libvirt
|
* daemonize guarantees control won't return to libvirt
|
||||||
* until the socket is present.
|
* until the socket is present.
|
||||||
*/
|
*/
|
||||||
cmd->cmd = virCommandNewArgList(cmd->binary,
|
proc->cmd = virCommandNewArgList(proc->binary,
|
||||||
"-S",
|
"-S",
|
||||||
"-no-user-config",
|
"-no-user-config",
|
||||||
"-nodefaults",
|
"-nodefaults",
|
||||||
"-nographic",
|
"-nographic",
|
||||||
"-machine", machine,
|
"-machine", machine,
|
||||||
"-qmp", cmd->monarg,
|
"-qmp", proc->monarg,
|
||||||
"-pidfile", cmd->pidfile,
|
"-pidfile", proc->pidfile,
|
||||||
"-daemonize",
|
"-daemonize",
|
||||||
NULL);
|
NULL);
|
||||||
virCommandAddEnvPassCommon(cmd->cmd);
|
virCommandAddEnvPassCommon(proc->cmd);
|
||||||
virCommandClearCaps(cmd->cmd);
|
virCommandClearCaps(proc->cmd);
|
||||||
|
|
||||||
#if WITH_CAPNG
|
#if WITH_CAPNG
|
||||||
/* QEMU might run into permission issues, e.g. /dev/sev (0600), override
|
/* QEMU might run into permission issues, e.g. /dev/sev (0600), override
|
||||||
* them just for the purpose of probing */
|
* them just for the purpose of probing */
|
||||||
if (geteuid() == 0)
|
if (geteuid() == 0)
|
||||||
virCommandAllowCap(cmd->cmd, CAP_DAC_OVERRIDE);
|
virCommandAllowCap(proc->cmd, CAP_DAC_OVERRIDE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virCommandSetGID(cmd->cmd, cmd->runGid);
|
virCommandSetGID(proc->cmd, proc->runGid);
|
||||||
virCommandSetUID(cmd->cmd, cmd->runUid);
|
virCommandSetUID(proc->cmd, proc->runUid);
|
||||||
|
|
||||||
virCommandSetErrorBuffer(cmd->cmd, cmd->qmperr);
|
virCommandSetErrorBuffer(proc->cmd, proc->qmperr);
|
||||||
|
|
||||||
/* Log, but otherwise ignore, non-zero status. */
|
/* Log, but otherwise ignore, non-zero status. */
|
||||||
if (virCommandRun(cmd->cmd, &status) < 0)
|
if (virCommandRun(proc->cmd, &status) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
VIR_DEBUG("QEMU %s exited with status %d: %s",
|
VIR_DEBUG("QEMU %s exited with status %d: %s",
|
||||||
cmd->binary, status, *cmd->qmperr);
|
proc->binary, status, *proc->qmperr);
|
||||||
goto ignore;
|
goto ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virPidFileReadPath(cmd->pidfile, &cmd->pid) < 0) {
|
if (virPidFileReadPath(proc->pidfile, &proc->pid) < 0) {
|
||||||
VIR_DEBUG("Failed to read pidfile %s", cmd->pidfile);
|
VIR_DEBUG("Failed to read pidfile %s", proc->pidfile);
|
||||||
goto ignore;
|
goto ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
|
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
|
||||||
!(cmd->vm = virDomainObjNew(xmlopt)))
|
!(proc->vm = virDomainObjNew(xmlopt)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cmd->vm->pid = cmd->pid;
|
proc->vm->pid = proc->pid;
|
||||||
|
|
||||||
if (!(cmd->mon = qemuMonitorOpen(cmd->vm, &cmd->config, true, true,
|
if (!(proc->mon = qemuMonitorOpen(proc->vm, &proc->config, true, true,
|
||||||
0, &callbacks, NULL)))
|
0, &callbacks, NULL)))
|
||||||
goto ignore;
|
goto ignore;
|
||||||
|
|
||||||
virObjectLock(cmd->mon);
|
virObjectLock(proc->mon);
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (!cmd->mon)
|
if (!proc->mon)
|
||||||
qemuProcessQMPAbort(cmd);
|
qemuProcessQMPAbort(proc);
|
||||||
virObjectUnref(xmlopt);
|
virObjectUnref(xmlopt);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -8486,34 +8486,34 @@ qemuProcessQMPRun(qemuProcessQMPPtr cmd,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
qemuProcessQMPAbort(qemuProcessQMPPtr cmd)
|
qemuProcessQMPAbort(qemuProcessQMPPtr proc)
|
||||||
{
|
{
|
||||||
if (cmd->mon)
|
if (proc->mon)
|
||||||
virObjectUnlock(cmd->mon);
|
virObjectUnlock(proc->mon);
|
||||||
qemuMonitorClose(cmd->mon);
|
qemuMonitorClose(proc->mon);
|
||||||
cmd->mon = NULL;
|
proc->mon = NULL;
|
||||||
|
|
||||||
virCommandAbort(cmd->cmd);
|
virCommandAbort(proc->cmd);
|
||||||
virCommandFree(cmd->cmd);
|
virCommandFree(proc->cmd);
|
||||||
cmd->cmd = NULL;
|
proc->cmd = NULL;
|
||||||
|
|
||||||
if (cmd->monpath)
|
if (proc->monpath)
|
||||||
unlink(cmd->monpath);
|
unlink(proc->monpath);
|
||||||
|
|
||||||
virDomainObjEndAPI(&cmd->vm);
|
virDomainObjEndAPI(&proc->vm);
|
||||||
|
|
||||||
if (cmd->pid != 0) {
|
if (proc->pid != 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
|
|
||||||
VIR_DEBUG("Killing QMP caps process %lld", (long long)cmd->pid);
|
VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid);
|
||||||
if (virProcessKill(cmd->pid, SIGKILL) < 0 && errno != ESRCH)
|
if (virProcessKill(proc->pid, SIGKILL) < 0 && errno != ESRCH)
|
||||||
VIR_ERROR(_("Failed to kill process %lld: %s"),
|
VIR_ERROR(_("Failed to kill process %lld: %s"),
|
||||||
(long long)cmd->pid,
|
(long long)proc->pid,
|
||||||
virStrerror(errno, ebuf, sizeof(ebuf)));
|
virStrerror(errno, ebuf, sizeof(ebuf)));
|
||||||
|
|
||||||
VIR_FREE(*cmd->qmperr);
|
VIR_FREE(*proc->qmperr);
|
||||||
}
|
}
|
||||||
if (cmd->pidfile)
|
if (proc->pidfile)
|
||||||
unlink(cmd->pidfile);
|
unlink(proc->pidfile);
|
||||||
cmd->pid = 0;
|
proc->pid = 0;
|
||||||
}
|
}
|
||||||
|
@ -237,11 +237,11 @@ qemuProcessQMPPtr qemuProcessQMPNew(const char *binary,
|
|||||||
gid_t runGid,
|
gid_t runGid,
|
||||||
char **qmperr);
|
char **qmperr);
|
||||||
|
|
||||||
void qemuProcessQMPFree(qemuProcessQMPPtr cmd);
|
void qemuProcessQMPFree(qemuProcessQMPPtr proc);
|
||||||
|
|
||||||
int qemuProcessQMPRun(qemuProcessQMPPtr cmd,
|
int qemuProcessQMPRun(qemuProcessQMPPtr proc,
|
||||||
bool forceTCG);
|
bool forceTCG);
|
||||||
|
|
||||||
void qemuProcessQMPAbort(qemuProcessQMPPtr cmd);
|
void qemuProcessQMPAbort(qemuProcessQMPPtr proc);
|
||||||
|
|
||||||
#endif /* LIBVIRT_QEMU_PROCESS_H */
|
#endif /* LIBVIRT_QEMU_PROCESS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user