Move {Enter,Exit}Monitor calls inside qemuProcessSetLinkStates to
simplify qemuProcessStart.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_process.c | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d5f6750..de5c9f8 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2233,19 +2233,25 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm)
/* set link states to down on interfaces at qemu start */
static int
-qemuProcessSetLinkStates(virDomainObjPtr vm)
+qemuProcessSetLinkStates(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ qemuDomainAsyncJob asyncJob)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDefPtr def = vm->def;
size_t i;
- int ret = 0;
+ int ret = -1;
+ int rv;
+
+ if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+ return -1;
for (i = 0; i < def->nnets; i++) {
if (def->nets[i]->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN) {
if (!def->nets[i]->info.alias) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing alias for network device"));
- return -1;
+ goto cleanup;
}
VIR_DEBUG("Setting link state: %s",
def->nets[i]->info.alias);
@@ -2253,20 +2259,26 @@ qemuProcessSetLinkStates(virDomainObjPtr vm)
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("Setting of link state is not supported by this
qemu"));
- return -1;
+ goto cleanup;
}
- ret = qemuMonitorSetLink(priv->mon,
- def->nets[i]->info.alias,
- VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN);
- if (ret != 0) {
+ rv = qemuMonitorSetLink(priv->mon,
+ def->nets[i]->info.alias,
+ VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN);
+ if (rv < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
- _("Couldn't set link state on interface:
%s"), def->nets[i]->info.alias);
- break;
+ _("Couldn't set link state on interface:
%s"),
+ def->nets[i]->info.alias);
+ goto cleanup;
}
}
}
+ ret = 0;
+
+ cleanup:
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ ret = -1;
return ret;
}
@@ -4926,11 +4938,7 @@ int qemuProcessStart(virConnectPtr conn,
/* qemu doesn't support setting this on the command line, so
* enter the monitor */
VIR_DEBUG("Setting network link states");
- if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
- goto error;
- if (qemuProcessSetLinkStates(vm) < 0)
- goto exit_monitor;
- if (qemuDomainObjExitMonitor(driver, vm))
+ if (qemuProcessSetLinkStates(driver, vm, asyncJob) < 0)
goto error;
VIR_DEBUG("Fetching list of active devices");
--
2.6.3