Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/network/bridge_driver.c | 172 ++++++++++++++----------------------
1 file changed, 68 insertions(+), 104 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index fcaa6a48ae..0ba7f91c20 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1010,7 +1010,7 @@ networkKillDaemon(pid_t pid,
daemonName, pid, networkName, signame,
virStrerror(errno, ebuf, sizeof(ebuf)));
}
- goto cleanup;
+ return ret;
}
/* NB: since networks have no reference count like
* domains, there is no safe way to unlock the network
@@ -1032,7 +1032,6 @@ networkKillDaemon(pid_t pid,
VIR_WARN("Timed out waiting after SIG%s to %s process %d "
"(network '%s')",
signame, daemonName, pid, networkName);
- cleanup:
return ret;
}
@@ -3205,19 +3204,15 @@ networkConnectListAllNetworks(virConnectPtr conn,
unsigned int flags)
{
virNetworkDriverStatePtr driver = networkGetDriver();
- int ret = -1;
virCheckFlags(VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL, -1);
if (virConnectListAllNetworksEnsureACL(conn) < 0)
- goto cleanup;
-
- ret = virNetworkObjListExport(conn, driver->networks, nets,
- virConnectListAllNetworksCheckACL,
- flags);
+ return -1;
- cleanup:
- return ret;
+ return virNetworkObjListExport(conn, driver->networks, nets,
+ virConnectListAllNetworksCheckACL,
+ flags);
}
@@ -3233,14 +3228,13 @@ networkConnectNetworkEventRegisterAny(virConnectPtr conn,
int ret = -1;
if (virConnectNetworkEventRegisterAnyEnsureACL(conn) < 0)
- goto cleanup;
+ return -1;
if (virNetworkEventStateRegisterID(conn, driver->networkEventState,
net, eventID, callback,
opaque, freecb, &ret) < 0)
ret = -1;
- cleanup:
return ret;
}
@@ -3250,20 +3244,16 @@ networkConnectNetworkEventDeregisterAny(virConnectPtr conn,
int callbackID)
{
virNetworkDriverStatePtr driver = networkGetDriver();
- int ret = -1;
if (virConnectNetworkEventDeregisterAnyEnsureACL(conn) < 0)
- goto cleanup;
+ return -1;
if (virObjectEventStateDeregisterID(conn,
driver->networkEventState,
callbackID, true) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
@@ -3367,24 +3357,20 @@ static int
networkBridgeNameValidate(virNetworkObjListPtr nets,
virNetworkDefPtr def)
{
- int ret = -1;
-
if (def->bridge && !strstr(def->bridge, "%d")) {
if (virNetworkObjBridgeInUse(nets, def->bridge, def->name)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("bridge name '%s' already in use."),
def->bridge);
- goto cleanup;
+ return -1;
}
} else {
/* Allocate a bridge name */
if (networkFindUnusedBridgeName(nets, def) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -4537,7 +4523,6 @@ networkAllocatePort(virNetworkObjPtr obj,
virPortGroupDefPtr portgroup = NULL;
virNetworkForwardIfDefPtr dev = NULL;
size_t i;
- int ret = -1;
virNetDevVPortProfilePtr portprofile = NULL;
netdef = virNetworkObjGetDef(obj);
@@ -4547,7 +4532,7 @@ networkAllocatePort(virNetworkObjPtr obj,
virReportError(VIR_ERR_OPERATION_INVALID,
_("network '%s' is not active"),
netdef->name);
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Interface port group %s", port->group);
@@ -4561,7 +4546,7 @@ networkAllocatePort(virNetworkObjPtr obj,
if (portgroup && portgroup->bandwidth &&
virNetDevBandwidthCopy(&port->bandwidth,
portgroup->bandwidth) < 0)
- goto cleanup;
+ return -1;
}
if (port->vlan.nTags == 0) {
@@ -4572,7 +4557,7 @@ networkAllocatePort(virNetworkObjPtr obj,
vlan = &netdef->vlan;
if (vlan && virNetDevVlanCopy(&port->vlan, vlan) < 0)
- goto cleanup;
+ return -1;
}
if (!port->trustGuestRxFilters) {
@@ -4590,7 +4575,7 @@ networkAllocatePort(virNetworkObjPtr obj,
netdef->virtPortProfile,
portgroup
? portgroup->virtPortProfile : NULL) < 0) {
- goto cleanup;
+ return -1;
}
if (portprofile) {
VIR_FREE(port->virtPortProfile);
@@ -4618,18 +4603,18 @@ networkAllocatePort(virNetworkObjPtr obj,
"'%s' which uses IP forwarding"),
virNetDevVPortTypeToString(port->virtPortProfile->virtPortType),
netdef->name);
- goto cleanup;
+ return -1;
}
if (networkPlugBandwidth(obj, &port->mac, port->bandwidth,
&port->class_id) < 0)
- goto cleanup;
+ return -1;
break;
case VIR_NETWORK_FORWARD_HOSTDEV: {
port->plugtype = VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI;
if (networkCreateInterfacePool(netdef) < 0)
- goto cleanup;
+ return -1;
/* pick first dev with 0 connections */
for (i = 0; i < netdef->forward.nifs; i++) {
@@ -4643,7 +4628,7 @@ networkAllocatePort(virNetworkObjPtr obj,
_("network '%s' requires exclusive access "
"to interfaces, but none are available"),
netdef->name);
- goto cleanup;
+ return -1;
}
port->plug.hostdevpci.addr = dev->device.pci;
port->plug.hostdevpci.driver = netdef->forward.driverName;
@@ -4659,7 +4644,7 @@ networkAllocatePort(virNetworkObjPtr obj,
"via PCI passthrough"),
virNetDevVPortTypeToString(port->virtPortProfile->virtPortType),
netdef->name);
- goto cleanup;
+ return -1;
}
}
break;
@@ -4683,12 +4668,12 @@ networkAllocatePort(virNetworkObjPtr obj,
"'%s' which uses a bridge
device"),
virNetDevVPortTypeToString(port->virtPortProfile->virtPortType),
netdef->name);
- goto cleanup;
+ return -1;
}
}
if (networkPlugBandwidth(obj, &port->mac, port->bandwidth,
&port->class_id) < 0)
- goto cleanup;
+ return -1;
break;
}
@@ -4722,7 +4707,7 @@ networkAllocatePort(virNetworkObjPtr obj,
"'%s' which uses a macvtap device"),
virNetDevVPortTypeToString(port->virtPortProfile->virtPortType),
netdef->name);
- goto cleanup;
+ return -1;
}
}
@@ -4734,12 +4719,12 @@ networkAllocatePort(virNetworkObjPtr obj,
_("network '%s' uses a direct mode, but "
"has no forward dev and no interface pool"),
netdef->name);
- goto cleanup;
+ return -1;
} else {
/* pick an interface from the pool */
if (networkCreateInterfacePool(netdef) < 0)
- goto cleanup;
+ return -1;
/* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both
* require exclusive access to a device, so current
@@ -4774,7 +4759,7 @@ networkAllocatePort(virNetworkObjPtr obj,
_("network '%s' requires exclusive access
"
"to interfaces, but none are available"),
netdef->name);
- goto cleanup;
+ return -1;
}
port->plug.direct.linkdev = g_strdup(dev->device.dev);
}
@@ -4783,15 +4768,15 @@ networkAllocatePort(virNetworkObjPtr obj,
case VIR_NETWORK_FORWARD_LAST:
default:
virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
- goto cleanup;
+ return -1;
}
if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir,
port->ownername, &port->mac) < 0)
- goto cleanup;
+ return -1;
if (virNetDevVPortProfileCheckComplete(port->virtPortProfile, true) < 0)
- goto cleanup;
+ return -1;
/* make sure that everything now specified for the device is
* actually supported on this type of network. NB: network,
@@ -4816,7 +4801,7 @@ networkAllocatePort(virNetworkObjPtr obj,
"is requesting a vlan tag, but that is not "
"supported for this type of network"),
netdef->name);
- goto cleanup;
+ return -1;
}
}
@@ -4827,7 +4812,7 @@ networkAllocatePort(virNetworkObjPtr obj,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("bandwidth settings are not supported "
"for hostdev interfaces"));
- goto cleanup;
+ return -1;
}
netdef->connections++;
@@ -4841,15 +4826,13 @@ networkAllocatePort(virNetworkObjPtr obj,
netdef->connections--;
if (dev)
dev->connections--;
- goto cleanup;
+ return -1;
}
networkLogAllocation(netdef, dev, &port->mac, true);
VIR_DEBUG("Port allocated");
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -4869,7 +4852,6 @@ networkNotifyPort(virNetworkObjPtr obj,
virNetworkDefPtr netdef;
virNetworkForwardIfDefPtr dev = NULL;
size_t i;
- int ret = -1;
netdef = virNetworkObjGetDef(obj);
@@ -4877,14 +4859,14 @@ networkNotifyPort(virNetworkObjPtr obj,
virReportError(VIR_ERR_OPERATION_INVALID,
_("network '%s' is not active"),
netdef->name);
- goto cleanup;
+ return -1;
}
switch (port->plugtype) {
case VIR_NETWORK_PORT_PLUG_TYPE_NONE:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unexpectedly got a network port without a plug"));
- goto cleanup;
+ return -1;
case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK:
case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE:
@@ -4892,13 +4874,13 @@ networkNotifyPort(virNetworkObjPtr obj,
if (!netdef->bridge) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unexpectedly got a network port without a network
bridge"));
- goto cleanup;
+ return -1;
}
break;
case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT:
if (networkCreateInterfacePool(netdef) < 0)
- goto cleanup;
+ return -1;
/* find the matching interface and increment its connections */
for (i = 0; i < netdef->forward.nifs; i++) {
@@ -4917,7 +4899,7 @@ networkNotifyPort(virNetworkObjPtr obj,
"in use by network port '%s'"),
netdef->name, port->plug.direct.linkdev,
port->uuid);
- goto cleanup;
+ return -1;
}
/* PASSTHROUGH mode and PRIVATE Mode + 802.1Qbh both require
@@ -4933,14 +4915,14 @@ networkNotifyPort(virNetworkObjPtr obj,
_("network '%s' claims dev='%s' is
already in "
"use by a different port"),
netdef->name, port->plug.direct.linkdev);
- goto cleanup;
+ return -1;
}
break;
case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI:
if (networkCreateInterfacePool(netdef) < 0)
- goto cleanup;
+ return -1;
/* find the matching interface and increment its connections */
for (i = 0; i < netdef->forward.nifs; i++) {
@@ -4962,7 +4944,7 @@ networkNotifyPort(virNetworkObjPtr obj,
port->plug.hostdevpci.addr.bus,
port->plug.hostdevpci.addr.slot,
port->plug.hostdevpci.addr.function);
- goto cleanup;
+ return -1;
}
/* PASSTHROUGH mode, PRIVATE Mode + 802.1Qbh, and hostdev (PCI
@@ -4978,7 +4960,7 @@ networkNotifyPort(virNetworkObjPtr obj,
netdef->name,
dev->device.pci.domain, dev->device.pci.bus,
dev->device.pci.slot, dev->device.pci.function);
- goto cleanup;
+ return -1;
}
break;
@@ -4986,7 +4968,7 @@ networkNotifyPort(virNetworkObjPtr obj,
case VIR_NETWORK_PORT_PLUG_TYPE_LAST:
default:
virReportEnumRangeError(virNetworkPortPlugType, port->plugtype);
- goto cleanup;
+ return -1;
}
netdef->connections++;
@@ -4999,13 +4981,11 @@ networkNotifyPort(virNetworkObjPtr obj,
if (dev)
dev->connections--;
netdef->connections--;
- goto cleanup;
+ return -1;
}
networkLogAllocation(netdef, dev, &port->mac, true);
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -5028,7 +5008,6 @@ networkReleasePort(virNetworkObjPtr obj,
virNetworkDefPtr netdef;
virNetworkForwardIfDefPtr dev = NULL;
size_t i;
- int ret = -1;
netdef = virNetworkObjGetDef(obj);
@@ -5041,7 +5020,7 @@ networkReleasePort(virNetworkObjPtr obj,
case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE:
if (networkUnplugBandwidth(obj, port->bandwidth,
&port->class_id) < 0)
- goto cleanup;
+ return -1;
break;
case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT:
@@ -5050,7 +5029,7 @@ networkReleasePort(virNetworkObjPtr obj,
_("network '%s' uses a direct mode, but "
"has no forward dev and no interface pool"),
netdef->name);
- goto cleanup;
+ return -1;
}
for (i = 0; i < netdef->forward.nifs; i++) {
@@ -5067,7 +5046,7 @@ networkReleasePort(virNetworkObjPtr obj,
_("network '%s' doesn't have dev='%s'
"
"in use by domain"),
netdef->name, port->plug.direct.linkdev);
- goto cleanup;
+ return -1;
}
break;
@@ -5077,7 +5056,7 @@ networkReleasePort(virNetworkObjPtr obj,
_("network '%s' uses a hostdev mode, but "
"has no forward dev and no interface pool"),
netdef->name);
- goto cleanup;
+ return -1;
}
for (i = 0; i < netdef->forward.nifs; i++) {
@@ -5099,14 +5078,14 @@ networkReleasePort(virNetworkObjPtr obj,
port->plug.hostdevpci.addr.bus,
port->plug.hostdevpci.addr.slot,
port->plug.hostdevpci.addr.function);
- goto cleanup;
+ return -1;
}
break;
case VIR_NETWORK_PORT_PLUG_TYPE_LAST:
default:
virReportEnumRangeError(virNetworkPortPlugType, port->plugtype);
- goto cleanup;
+ return -1;
}
virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, port->ownername,
&port->mac);
@@ -5119,9 +5098,7 @@ networkReleasePort(virNetworkObjPtr obj,
VIR_HOOK_SUBOP_BEGIN);
networkLogAllocation(netdef, dev, &port->mac, false);
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -5152,7 +5129,6 @@ networkCheckBandwidth(virNetworkObjPtr obj,
virMacAddrPtr ifaceMac,
unsigned long long *new_rate)
{
- int ret = -1;
virNetworkDefPtr def = virNetworkObjGetDef(obj);
virNetDevBandwidthPtr netBand = def->bandwidth;
unsigned long long tmp_floor_sum = virNetworkObjGetFloorSum(obj);
@@ -5201,7 +5177,7 @@ networkCheckBandwidth(virNetworkObjPtr obj,
tmp_floor_sum,
netBand->in->peak,
def->name);
- goto cleanup;
+ return -1;
}
} else if (tmp_floor_sum > netBand->in->average) {
/* tmp_floor_sum can be between 'average' and 'peak' iff
'peak' is set.
@@ -5215,15 +5191,13 @@ networkCheckBandwidth(virNetworkObjPtr obj,
tmp_floor_sum,
netBand->in->average,
def->name);
- goto cleanup;
+ return -1;
}
if (new_rate)
*new_rate = tmp_new_rate;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -5266,20 +5240,19 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj,
unsigned long long tmp_floor_sum = virNetworkObjGetFloorSum(obj);
ssize_t next_id = 0;
int plug_ret;
- int ret = -1;
/* generate new class_id */
if ((next_id = networkNextClassID(obj)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not generate next class ID"));
- goto cleanup;
+ return -1;
}
plug_ret = virNetDevBandwidthPlug(def->bridge, def->bandwidth,
mac, ifaceBand, next_id);
if (plug_ret < 0) {
ignore_value(virNetDevBandwidthUnplug(def->bridge, next_id));
- goto cleanup;
+ return -1;
}
/* QoS was set, generate new class ID */
@@ -5294,7 +5267,7 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj,
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
*class_id = 0;
ignore_value(virNetDevBandwidthUnplug(def->bridge, next_id));
- goto cleanup;
+ return -1;
}
/* update rate for non guaranteed NICs */
new_rate -= tmp_floor_sum;
@@ -5303,9 +5276,7 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj,
VIR_WARN("Unable to update rate for 1:2 class on %s bridge",
def->bridge);
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
@@ -5315,7 +5286,6 @@ networkPlugBandwidth(virNetworkObjPtr obj,
virNetDevBandwidthPtr ifaceBand,
unsigned int *class_id)
{
- int ret = -1;
int plug_ret;
unsigned long long new_rate = 0;
char ifmac[VIR_MAC_STRING_BUFLEN];
@@ -5323,24 +5293,19 @@ networkPlugBandwidth(virNetworkObjPtr obj,
if ((plug_ret = networkCheckBandwidth(obj, ifaceBand, NULL,
mac, &new_rate)) < 0) {
/* helper reported error */
- goto cleanup;
+ return -1;
}
- if (plug_ret > 0) {
+ if (plug_ret > 0)
/* no QoS needs to be set; claim success */
- ret = 0;
- goto cleanup;
- }
+ return 0;
virMacAddrFormat(mac, ifmac);
if (networkPlugBandwidthImpl(obj, mac, ifaceBand, class_id, new_rate) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
@@ -5360,7 +5325,7 @@ networkUnplugBandwidth(virNetworkObjPtr obj,
if (!def->bandwidth || !def->bandwidth->in) {
VIR_WARN("Network %s has no bandwidth but unplug requested",
def->name);
- goto cleanup;
+ return 0;
}
/* we must remove class from bridge */
new_rate = def->bandwidth->in->average;
@@ -5370,7 +5335,7 @@ networkUnplugBandwidth(virNetworkObjPtr obj,
ret = virNetDevBandwidthUnplug(def->bridge, *class_id);
if (ret < 0)
- goto cleanup;
+ return ret;
/* update sum of 'floor'-s of attached NICs */
tmp_floor_sum -= ifaceBand->in->floor;
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
@@ -5383,7 +5348,7 @@ networkUnplugBandwidth(virNetworkObjPtr obj,
tmp_floor_sum += ifaceBand->in->floor;
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
ignore_value(virBitmapSetBit(classIdMap, *class_id));
- goto cleanup;
+ return ret;
}
/* update rate for non guaranteed NICs */
new_rate -= tmp_floor_sum;
@@ -5395,7 +5360,6 @@ networkUnplugBandwidth(virNetworkObjPtr obj,
*class_id = 0;
}
- cleanup:
return ret;
}
--
2.21.0