]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Explicitly error if guest virtual network is inactive
authorCole Robinson <crobinso@redhat.com>
Tue, 16 Feb 2010 18:11:27 +0000 (13:11 -0500)
committerCole Robinson <crobinso@redhat.com>
Thu, 18 Feb 2010 14:23:05 +0000 (09:23 -0500)
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.

src/qemu/qemu_conf.c

index 646b3ed4e9de8d1f1c792e8486d78643f425052f..79bd1e843c556913937451eb0daf5ea6a5867c00 100644 (file)
@@ -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();