From: Cole Robinson Date: Tue, 16 Feb 2010 18:11:27 +0000 (-0500) Subject: qemu: Explicitly error if guest virtual network is inactive X-Git-Tag: v0.7.7~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f745ebe9fa37eabc6d85533268c0dd0acd54ae3;p=thirdparty%2Flibvirt.git qemu: Explicitly error if guest virtual network is inactive Currently we just error with ex. 'virbr0: No such device'. Since we are using public API calls here, we need to ensure that any raised error is properly saved and restored, since API entry points always reset messages. --- diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 646b3ed4e9..79bd1e843c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1472,17 +1472,39 @@ qemudNetworkIfaceConnect(virConnectPtr conn, int template_ifname = 0; if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) { + int active, fail = 0; + virErrorPtr errobj; virNetworkPtr network = virNetworkLookupByName(conn, - net->data.network.name); + net->data.network.name); if (!network) return -1; - brname = virNetworkGetBridgeName(network); + active = virNetworkIsActive(network); + if (active != 1) { + fail = 1; + if (active == 0) + qemuReportError(VIR_ERR_INTERNAL_ERROR, + _("Network '%s' is not active."), + net->data.network.name); + } + + if (!fail) { + brname = virNetworkGetBridgeName(network); + if (brname == NULL) + fail = 1; + } + + /* Make sure any above failure is preserved */ + errobj = virSaveLastError(); virNetworkFree(network); + virSetError(errobj); + virFreeError(errobj); - if (brname == NULL) + errobj = virSaveLastError(); + if (fail) return -1; + } else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (!(brname = strdup(net->data.bridge.brname))) { virReportOOMError();