mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-03 10:25:16 +00:00
qemu: Use ShutdownVMDaemon for all startup cleanup paths
The current cleanup: in StartVMDaemon path is a poor duplication. qemuShutdownVMDaemon can handle teardown for inactive VMs, so let's use it. v2: Remove old abort: label, only use cleanup:
This commit is contained in:
parent
54971d9170
commit
ac23d911df
@ -3516,29 +3516,29 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
|
|
||||||
DEBUG0("Waiting for monitor to show up");
|
DEBUG0("Waiting for monitor to show up");
|
||||||
if (qemudWaitForMonitor(driver, vm, pos) < 0)
|
if (qemudWaitForMonitor(driver, vm, pos) < 0)
|
||||||
goto abort;
|
goto cleanup;
|
||||||
|
|
||||||
DEBUG0("Detecting VCPU PIDs");
|
DEBUG0("Detecting VCPU PIDs");
|
||||||
if (qemuDetectVcpuPIDs(driver, vm) < 0)
|
if (qemuDetectVcpuPIDs(driver, vm) < 0)
|
||||||
goto abort;
|
goto cleanup;
|
||||||
|
|
||||||
DEBUG0("Setting any required VM passwords");
|
DEBUG0("Setting any required VM passwords");
|
||||||
if (qemuInitPasswords(conn, driver, vm, qemuCmdFlags) < 0)
|
if (qemuInitPasswords(conn, driver, vm, qemuCmdFlags) < 0)
|
||||||
goto abort;
|
goto cleanup;
|
||||||
|
|
||||||
/* If we have -device, then addresses are assigned explicitly.
|
/* If we have -device, then addresses are assigned explicitly.
|
||||||
* If not, then we have to detect dynamic ones here */
|
* If not, then we have to detect dynamic ones here */
|
||||||
if (!(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
|
if (!(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
|
||||||
DEBUG0("Determining domain device PCI addresses");
|
DEBUG0("Determining domain device PCI addresses");
|
||||||
if (qemuInitPCIAddresses(driver, vm) < 0)
|
if (qemuInitPCIAddresses(driver, vm) < 0)
|
||||||
goto abort;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG0("Setting initial memory amount");
|
DEBUG0("Setting initial memory amount");
|
||||||
qemuDomainObjEnterMonitorWithDriver(driver, vm);
|
qemuDomainObjEnterMonitorWithDriver(driver, vm);
|
||||||
if (qemuMonitorSetBalloon(priv->mon, vm->def->memory) < 0) {
|
if (qemuMonitorSetBalloon(priv->mon, vm->def->memory) < 0) {
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
goto abort;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (migrateFrom == NULL) {
|
if (migrateFrom == NULL) {
|
||||||
@ -3549,7 +3549,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("resume operation failed"));
|
"%s", _("resume operation failed"));
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
goto abort;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
qemuDomainObjExitMonitorWithDriver(driver, vm);
|
||||||
@ -3557,7 +3557,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
|
|
||||||
DEBUG0("Writing domain status to disk");
|
DEBUG0("Writing domain status to disk");
|
||||||
if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
|
if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
|
||||||
goto abort;
|
goto cleanup;
|
||||||
|
|
||||||
if (logfile != -1)
|
if (logfile != -1)
|
||||||
close(logfile);
|
close(logfile);
|
||||||
@ -3565,26 +3565,9 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
/* We jump here if we failed to start the VM for any reason
|
/* We jump here if we failed to start the VM for any reason, or
|
||||||
* XXX investigate if we can kill this block and safely call
|
* if we failed to initialize the now running VM. kill it off and
|
||||||
* qemudShutdownVMDaemon even though no PID is running */
|
* pretend we never started it */
|
||||||
qemuDomainReAttachHostDevices(driver, vm->def);
|
|
||||||
|
|
||||||
if (driver->securityDriver &&
|
|
||||||
driver->securityDriver->domainRestoreSecurityAllLabel)
|
|
||||||
driver->securityDriver->domainRestoreSecurityAllLabel(vm, 0);
|
|
||||||
if (driver->securityDriver &&
|
|
||||||
driver->securityDriver->domainReleaseSecurityLabel)
|
|
||||||
driver->securityDriver->domainReleaseSecurityLabel(vm);
|
|
||||||
qemuRemoveCgroup(driver, vm, 1);
|
|
||||||
if (logfile != -1)
|
|
||||||
close(logfile);
|
|
||||||
vm->def->id = -1;
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
abort:
|
|
||||||
/* We jump here if we failed to initialize the now running VM
|
|
||||||
* killing it off and pretend we never started it */
|
|
||||||
qemudShutdownVMDaemon(driver, vm, 0);
|
qemudShutdownVMDaemon(driver, vm, 0);
|
||||||
|
|
||||||
if (logfile != -1)
|
if (logfile != -1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user