The check for a network being active during interface attach was being
done individually in several places (by both the lxc driver and the
qemu driver), but those places were too specific, leading to it *not*
being checked when allocating a connection/device from a macvtap or
hostdev network.
This patch puts a single check in networkAllocateActualDevice(), which
is always called before the any network interface is attached to any
type of domain. It also removes all the other now-redundant checks
from the lxc and qemu drivers.
NB: the following patches are prerequisites for this patch, in the
case that it is backported to any branch:
440beeb network: fix virNetworkObjAssignDef and persistence
8aaa5b6 network: create statedir during driver initialization
b9e9549 network: change location of network state xml files
411c548 network: set macvtap/hostdev networks active if their state
file exists
This fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=880483
virNetworkPtr network;
char *brname = NULL;
bool fail = false;
- int active;
virErrorPtr errobj;
- if (!(network = virNetworkLookupByName(conn,
- net->data.network.name)))
+ if (!(network = virNetworkLookupByName(conn, net->data.network.name)))
goto cleanup;
-
- active = virNetworkIsActive(network);
- if (active != 1) {
- fail = true;
- if (active == 0)
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Network '%s' is not active."),
- net->data.network.name);
- }
-
- if (!fail) {
- brname = virNetworkGetBridgeName(network);
- if (brname == NULL)
- fail = true;
- }
+ if (!(brname = virNetworkGetBridgeName(network)))
+ fail = true;
/* Make sure any above failure is preserved */
errobj = virSaveLastError();
virNetworkPtr network;
char *brname = NULL;
bool fail = false;
- int active;
virErrorPtr errobj;
if (!(network = virNetworkLookupByName(conn,
def->nets[i]->data.network.name)))
goto cleanup;
-
- active = virNetworkIsActive(network);
- if (active != 1) {
- fail = true;
- if (active == 0)
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Network '%s' is not active."),
- def->nets[i]->data.network.name);
- }
-
- if (!fail) {
- brname = virNetworkGetBridgeName(network);
- if (brname == NULL)
- fail = true;
- }
+ if (!(brname = virNetworkGetBridgeName(network)))
+ fail = true;
/* Make sure any above failure is preserved */
errobj = virSaveLastError();
if (!virNetworkObjIsActive(network)) {
virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("network is not active"));
+ _("network '%s' is not active"),
+ network->def->name);
goto cleanup;
}
}
netdef = network->def;
+ if (!virNetworkObjIsActive(network)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("network '%s' is not active"),
+ netdef->name);
+ goto error;
+ }
+
if (VIR_ALLOC(iface->data.network.actual) < 0)
goto error;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
- int active;
bool fail = false;
virErrorPtr errobj;
virNetworkPtr network = virNetworkLookupByName(conn,
if (!network)
return ret;
- active = virNetworkIsActive(network);
- if (active != 1) {
- fail = true;
-
- if (active == 0)
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Network '%s' is not active."),
- net->data.network.name);
- }
-
- if (!fail) {
- brname = virNetworkGetBridgeName(network);
- if (brname == NULL)
- fail = true;
- }
+ if (!(brname = virNetworkGetBridgeName(network)))
+ fail = true;
/* Make sure any above failure is preserved */
errobj = virSaveLastError();
if (VIR_STRDUP(brname, tmpbr) < 0)
goto cleanup;
} else if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
- int active;
virErrorPtr errobj;
virNetworkPtr network;
net->data.network.name);
goto cleanup;
}
-
- active = virNetworkIsActive(network);
- if (active == 1) {
- brname = virNetworkGetBridgeName(network);
- } else if (active == 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Network '%s' is not active."),
- net->data.network.name);
- }
+ brname = virNetworkGetBridgeName(network);
/* Make sure any above failure is preserved */
errobj = virSaveLastError();