mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu: return -1 on error paths in qemuDomainSaveImageStartVM
Error paths after sending the event that domain is started written as if ret = -1 which is set at the beginning of the function. It's common idioma to keep 'ret' equal to -1 until the end of function where it is set to 0. But here we use ret to keep result of restore operation too and thus breaks the idioma and its users :) Let's use different variable to hold restore result. Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
This commit is contained in:
committed by
Jiri Denemark
parent
6ec319b84f
commit
4a67b044fb
@@ -6732,6 +6732,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
|
|||||||
qemuDomainAsyncJob asyncJob)
|
qemuDomainAsyncJob asyncJob)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
bool restored = false;
|
||||||
virObjectEventPtr event;
|
virObjectEventPtr event;
|
||||||
int intermediatefd = -1;
|
int intermediatefd = -1;
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
@@ -6758,13 +6759,14 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the migration source and start it up. */
|
/* Set the migration source and start it up. */
|
||||||
ret = qemuProcessStart(conn, driver, vm, asyncJob,
|
if (qemuProcessStart(conn, driver, vm, asyncJob,
|
||||||
"stdio", *fd, path, NULL,
|
"stdio", *fd, path, NULL,
|
||||||
VIR_NETDEV_VPORT_PROFILE_OP_RESTORE,
|
VIR_NETDEV_VPORT_PROFILE_OP_RESTORE,
|
||||||
VIR_QEMU_PROCESS_START_PAUSED);
|
VIR_QEMU_PROCESS_START_PAUSED) == 0)
|
||||||
|
restored = true;
|
||||||
|
|
||||||
if (intermediatefd != -1) {
|
if (intermediatefd != -1) {
|
||||||
if (ret < 0) {
|
if (!restored) {
|
||||||
/* if there was an error setting up qemu, the intermediate
|
/* if there was an error setting up qemu, the intermediate
|
||||||
* process will wait forever to write to stdout, so we
|
* process will wait forever to write to stdout, so we
|
||||||
* must manually kill it.
|
* must manually kill it.
|
||||||
@@ -6775,7 +6777,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
|
|||||||
|
|
||||||
if (virCommandWait(cmd, NULL) < 0) {
|
if (virCommandWait(cmd, NULL) < 0) {
|
||||||
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, 0);
|
qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, 0);
|
||||||
ret = -1;
|
restored = false;
|
||||||
}
|
}
|
||||||
VIR_DEBUG("Decompression binary stderr: %s", NULLSTR(errbuf));
|
VIR_DEBUG("Decompression binary stderr: %s", NULLSTR(errbuf));
|
||||||
}
|
}
|
||||||
@@ -6783,18 +6785,16 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
|
|||||||
|
|
||||||
if (VIR_CLOSE(*fd) < 0) {
|
if (VIR_CLOSE(*fd) < 0) {
|
||||||
virReportSystemError(errno, _("cannot close file: %s"), path);
|
virReportSystemError(errno, _("cannot close file: %s"), path);
|
||||||
ret = -1;
|
restored = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0) {
|
virDomainAuditStart(vm, "restored", restored);
|
||||||
virDomainAuditStart(vm, "restored", false);
|
if (!restored)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
event = virDomainEventLifecycleNewFromObj(vm,
|
event = virDomainEventLifecycleNewFromObj(vm,
|
||||||
VIR_DOMAIN_EVENT_STARTED,
|
VIR_DOMAIN_EVENT_STARTED,
|
||||||
VIR_DOMAIN_EVENT_STARTED_RESTORED);
|
VIR_DOMAIN_EVENT_STARTED_RESTORED);
|
||||||
virDomainAuditStart(vm, "restored", true);
|
|
||||||
qemuDomainEventQueue(driver, event);
|
qemuDomainEventQueue(driver, event);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user