提交 34cc3b2f 编写于 作者: L Laine Stump

network: centralize check for active network during interface attach

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:

  440beeb7 network: fix virNetworkObjAssignDef and persistence
  8aaa5b68 network: create statedir during driver initialization
  b9e95491 network: change location of network state xml files
  411c5486 network: set macvtap/hostdev networks active if their state
          file exists

This fixes:

  https://bugzilla.redhat.com/show_bug.cgi?id=880483
上级 411c5486
...@@ -4155,27 +4155,12 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, ...@@ -4155,27 +4155,12 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn,
virNetworkPtr network; virNetworkPtr network;
char *brname = NULL; char *brname = NULL;
bool fail = false; bool fail = false;
int active;
virErrorPtr errobj; virErrorPtr errobj;
if (!(network = virNetworkLookupByName(conn, if (!(network = virNetworkLookupByName(conn, net->data.network.name)))
net->data.network.name)))
goto cleanup; goto cleanup;
if (!(brname = virNetworkGetBridgeName(network)))
active = virNetworkIsActive(network); fail = true;
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;
}
/* Make sure any above failure is preserved */ /* Make sure any above failure is preserved */
errobj = virSaveLastError(); errobj = virSaveLastError();
......
...@@ -387,27 +387,13 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, ...@@ -387,27 +387,13 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
virNetworkPtr network; virNetworkPtr network;
char *brname = NULL; char *brname = NULL;
bool fail = false; bool fail = false;
int active;
virErrorPtr errobj; virErrorPtr errobj;
if (!(network = virNetworkLookupByName(conn, if (!(network = virNetworkLookupByName(conn,
def->nets[i]->data.network.name))) def->nets[i]->data.network.name)))
goto cleanup; goto cleanup;
if (!(brname = virNetworkGetBridgeName(network)))
active = virNetworkIsActive(network); fail = true;
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;
}
/* Make sure any above failure is preserved */ /* Make sure any above failure is preserved */
errobj = virSaveLastError(); errobj = virSaveLastError();
......
...@@ -3166,7 +3166,8 @@ static int networkDestroy(virNetworkPtr net) ...@@ -3166,7 +3166,8 @@ static int networkDestroy(virNetworkPtr net)
if (!virNetworkObjIsActive(network)) { if (!virNetworkObjIsActive(network)) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("network is not active")); _("network '%s' is not active"),
network->def->name);
goto cleanup; goto cleanup;
} }
...@@ -3510,6 +3511,13 @@ networkAllocateActualDevice(virDomainDefPtr dom, ...@@ -3510,6 +3511,13 @@ networkAllocateActualDevice(virDomainDefPtr dom,
} }
netdef = network->def; 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) if (VIR_ALLOC(iface->data.network.actual) < 0)
goto error; goto error;
......
...@@ -297,7 +297,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def, ...@@ -297,7 +297,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) { if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
int active;
bool fail = false; bool fail = false;
virErrorPtr errobj; virErrorPtr errobj;
virNetworkPtr network = virNetworkLookupByName(conn, virNetworkPtr network = virNetworkLookupByName(conn,
...@@ -305,21 +304,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def, ...@@ -305,21 +304,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
if (!network) if (!network)
return ret; return ret;
active = virNetworkIsActive(network); if (!(brname = virNetworkGetBridgeName(network)))
if (active != 1) { fail = true;
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;
}
/* Make sure any above failure is preserved */ /* Make sure any above failure is preserved */
errobj = virSaveLastError(); errobj = virSaveLastError();
......
...@@ -1710,7 +1710,6 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net) ...@@ -1710,7 +1710,6 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net)
if (VIR_STRDUP(brname, tmpbr) < 0) if (VIR_STRDUP(brname, tmpbr) < 0)
goto cleanup; goto cleanup;
} else if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) { } else if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
int active;
virErrorPtr errobj; virErrorPtr errobj;
virNetworkPtr network; virNetworkPtr network;
...@@ -1720,15 +1719,7 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net) ...@@ -1720,15 +1719,7 @@ qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net)
net->data.network.name); net->data.network.name);
goto cleanup; goto cleanup;
} }
brname = virNetworkGetBridgeName(network);
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);
}
/* Make sure any above failure is preserved */ /* Make sure any above failure is preserved */
errobj = virSaveLastError(); errobj = virSaveLastError();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册