From b5e0532e0446c6255ecedc2d459f4d47172b9225 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Wed, 14 May 2014 13:22:34 +0200 Subject: [PATCH] qemu: Make qemuProcess{Start,Stop}CPUs easier to follow As a side effect, the return value of qemuDomainObjEnterMonitorAsync is not directly used as the return value of qemuProcess{Start,Stop}CPUs. Signed-off-by: Jiri Denemark --- src/qemu/qemu_process.c | 53 ++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 606478e35d..a83780ffb0 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2747,23 +2747,26 @@ qemuProcessStartCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm, } VIR_FREE(priv->lockState); - ret = qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob); - if (ret == 0) { - ret = qemuMonitorStartCPUs(priv->mon, conn); - qemuDomainObjExitMonitor(driver, vm); - } + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + goto release; - if (ret == 0) { - virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason); - } else { - if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0) - VIR_WARN("Unable to release lease on %s", vm->def->name); - VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - } + ret = qemuMonitorStartCPUs(priv->mon, conn); + qemuDomainObjExitMonitor(driver, vm); + + if (ret < 0) + goto release; + + virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason); cleanup: virObjectUnref(cfg); return ret; + + release: + if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0) + VIR_WARN("Unable to release lease on %s", vm->def->name); + VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); + goto cleanup; } @@ -2771,24 +2774,26 @@ int qemuProcessStopCPUs(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainPausedReason reason, enum qemuDomainAsyncJob asyncJob) { - int ret; + int ret = -1; qemuDomainObjPrivatePtr priv = vm->privateData; VIR_FREE(priv->lockState); - ret = qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob); - if (ret == 0) { - ret = qemuMonitorStopCPUs(priv->mon); - qemuDomainObjExitMonitor(driver, vm); - } + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + goto cleanup; - if (ret == 0) { - virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, reason); - if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0) - VIR_WARN("Unable to release lease on %s", vm->def->name); - VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - } + ret = qemuMonitorStopCPUs(priv->mon); + qemuDomainObjExitMonitor(driver, vm); + if (ret < 0) + goto cleanup; + + virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, reason); + if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0) + VIR_WARN("Unable to release lease on %s", vm->def->name); + VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); + + cleanup: return ret; } -- GitLab