Separate network port bandwidth update code from the domain driver
network callback implementation.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/network/bridge_driver.c | 115 ++++++++++++++++++++----------------
1 file changed, 65 insertions(+), 50 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index abc6b248aa..b23037335f 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -5393,77 +5393,56 @@ networkNetworkObjTaint(virNetworkObjPtr obj,
static int
-networkBandwidthUpdate(virDomainNetDefPtr iface,
- virNetDevBandwidthPtr newBandwidth)
+networkUpdatePortBandwidth(virNetworkObjPtr obj,
+ virMacAddrPtr mac,
+ unsigned int *class_id,
+ virNetDevBandwidthPtr oldBandwidth,
+ virNetDevBandwidthPtr newBandwidth)
{
virNetworkDriverStatePtr driver = networkGetDriver();
- virNetworkObjPtr obj = NULL;
virNetworkDefPtr def;
unsigned long long tmp_floor_sum;
- virNetDevBandwidthPtr ifaceBand = virDomainNetGetActualBandwidth(iface);
unsigned long long new_rate = 0;
unsigned long long old_floor, new_floor;
int plug_ret;
- int ret = -1;
-
- if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Expected a interface for a virtual network"));
- return -1;
- }
-
- if (virDomainNetGetActualType(iface) != VIR_DOMAIN_NET_TYPE_BRIDGE ||
- iface->data.network.actual->data.bridge.brname == NULL) {
- /* This is not an interface that's plugged into a network.
- * We don't care. Thus from our POV bandwidth change is allowed. */
- return 0;
- }
old_floor = new_floor = 0;
- if (ifaceBand && ifaceBand->in)
- old_floor = ifaceBand->in->floor;
+ if (oldBandwidth && oldBandwidth->in)
+ old_floor = oldBandwidth->in->floor;
if (newBandwidth && newBandwidth->in)
new_floor = newBandwidth->in->floor;
if (new_floor == old_floor)
return 0;
- obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
- if (!obj) {
- virReportError(VIR_ERR_NO_NETWORK,
- _("no network with matching name '%s'"),
- iface->data.network.name);
- return ret;
- }
def = virNetworkObjGetDef(obj);
- if ((plug_ret = networkCheckBandwidth(obj, newBandwidth, ifaceBand,
- &iface->mac, &new_rate)) < 0) {
+ if ((plug_ret = networkCheckBandwidth(obj, newBandwidth, oldBandwidth,
+ mac, &new_rate)) < 0) {
/* helper reported error */
- goto cleanup;
+ return -1;
}
if (plug_ret > 0) {
/* no QoS needs to be set; claim success */
- ret = 0;
- goto cleanup;
+ return 0;
}
/* Okay, there are three possible scenarios: */
- if (ifaceBand && ifaceBand->in && ifaceBand->in->floor
&&
+ if (oldBandwidth && oldBandwidth->in &&
oldBandwidth->in->floor &&
newBandwidth->in && newBandwidth->in->floor) {
/* Either we just need to update @floor .. */
if (virNetDevBandwidthUpdateRate(def->bridge,
- iface->data.network.actual->class_id,
+ *class_id,
def->bandwidth,
newBandwidth->in->floor) < 0)
- goto cleanup;
+ return -1;
tmp_floor_sum = virNetworkObjGetFloorSum(obj);
- tmp_floor_sum -= ifaceBand->in->floor;
+ tmp_floor_sum -= oldBandwidth->in->floor;
tmp_floor_sum += newBandwidth->in->floor;
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
new_rate -= tmp_floor_sum;
@@ -5473,34 +5452,70 @@ networkBandwidthUpdate(virDomainNetDefPtr iface,
virNetworkObjSaveStatus(driver->stateDir, obj) < 0) {
/* Ouch, rollback */
tmp_floor_sum -= newBandwidth->in->floor;
- tmp_floor_sum += ifaceBand->in->floor;
+ tmp_floor_sum += oldBandwidth->in->floor;
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
ignore_value(virNetDevBandwidthUpdateRate(def->bridge,
-
iface->data.network.actual->class_id,
+ *class_id,
def->bandwidth,
- ifaceBand->in->floor));
- goto cleanup;
+ oldBandwidth->in->floor));
+ return -1;
}
} else if (newBandwidth->in && newBandwidth->in->floor) {
/* .. or we need to plug in new .. */
- if (networkPlugBandwidthImpl(obj, &iface->mac, newBandwidth,
- iface->data.network.actual ?
- &iface->data.network.actual->class_id :
NULL,
+ if (networkPlugBandwidthImpl(obj, mac, newBandwidth,
+ class_id,
new_rate) < 0)
- goto cleanup;
+ return -1;
} else {
/* .. or unplug old. */
- if (networkUnplugBandwidth(obj, iface->bandwidth,
- iface->data.network.actual ?
- &iface->data.network.actual->class_id :
NULL) < 0)
- goto cleanup;
+ if (networkUnplugBandwidth(obj, oldBandwidth, class_id) < 0)
+ return -1;
}
- ret = 0;
- cleanup:
+ return 0;
+}
+
+
+static int
+networkBandwidthUpdate(virDomainNetDefPtr iface,
+ virNetDevBandwidthPtr newBandwidth)
+{
+ virNetworkDriverStatePtr driver = networkGetDriver();
+ virNetworkObjPtr obj = NULL;
+ virNetDevBandwidthPtr oldBandwidth = virDomainNetGetActualBandwidth(iface);
+ int ret = -1;
+
+ if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Expected a interface for a virtual network"));
+ return -1;
+ }
+
+ if (virDomainNetGetActualType(iface) != VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ iface->data.network.actual->data.bridge.brname == NULL) {
+ /* This is not an interface that's plugged into a network.
+ * We don't care. Thus from our POV bandwidth change is allowed. */
+ return 0;
+ }
+
+ obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
+ if (!obj) {
+ virReportError(VIR_ERR_NO_NETWORK,
+ _("no network with matching name '%s'"),
+ iface->data.network.name);
+ return ret;
+ }
+
+ ret = networkUpdatePortBandwidth(obj,
+ &iface->mac,
+ iface->data.network.actual ?
+ &iface->data.network.actual->class_id :
NULL,
+ newBandwidth,
+ oldBandwidth);
+
virNetworkObjEndAPI(&obj);
return ret;
}
--
2.20.1