static virDomainNetAllocateActualDeviceImpl netAllocate;
static virDomainNetNotifyActualDeviceImpl netNotify;
static virDomainNetReleaseActualDeviceImpl netRelease;
-static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed;
static virDomainNetBandwidthUpdateImpl netBandwidthUpdate;
virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
virDomainNetNotifyActualDeviceImpl notify,
virDomainNetReleaseActualDeviceImpl release,
- virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
virDomainNetBandwidthUpdateImpl bandwidthUpdate)
{
netAllocate = allocate;
netNotify = notify;
netRelease = release;
- netBandwidthChangeAllowed = bandwidthChangeAllowed;
netBandwidthUpdate = bandwidthUpdate;
}
return ret;
}
-bool
-virDomainNetBandwidthChangeAllowed(virDomainNetDefPtr iface,
- virNetDevBandwidthPtr newBandwidth)
-{
- if (!netBandwidthChangeAllowed) {
- virReportError(VIR_ERR_NO_SUPPORT, "%s",
- _("Virtual networking driver is not available"));
- return -1;
- }
-
- return netBandwidthChangeAllowed(iface, newBandwidth);
-}
int
virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
virDomainDefPtr dom,
virDomainNetDefPtr iface);
-typedef bool
-(*virDomainNetBandwidthChangeAllowedImpl)(virDomainNetDefPtr iface,
- virNetDevBandwidthPtr newBandwidth);
-
typedef int
(*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth);
virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
virDomainNetNotifyActualDeviceImpl notify,
virDomainNetReleaseActualDeviceImpl release,
- virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
virDomainNetBandwidthUpdateImpl bandwidthUpdate);
int
virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-bool
-virDomainNetBandwidthChangeAllowed(virDomainNetDefPtr iface,
- virNetDevBandwidthPtr newBandwidth)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-
int
virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth)
virDomainMemorySourceTypeToString;
virDomainNetAllocateActualDevice;
virDomainNetAppendIPAddress;
-virDomainNetBandwidthChangeAllowed;
virDomainNetBandwidthUpdate;
virDomainNetDefActualFromNetworkPort;
virDomainNetDefActualToNetworkPort;
}
-static bool
-networkBandwidthGenericChecks(virDomainNetDefPtr iface,
- virNetDevBandwidthPtr newBandwidth)
-{
- virNetDevBandwidthPtr ifaceBand;
- unsigned long long old_floor, new_floor;
-
- if (virDomainNetGetActualType(iface) != VIR_DOMAIN_NET_TYPE_NETWORK &&
- (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 false;
- }
-
- ifaceBand = virDomainNetGetActualBandwidth(iface);
- old_floor = new_floor = 0;
-
- if (ifaceBand && ifaceBand->in)
- old_floor = ifaceBand->in->floor;
- if (newBandwidth && newBandwidth->in)
- new_floor = newBandwidth->in->floor;
-
- return new_floor != old_floor;
-}
-
-
-static bool
-networkBandwidthChangeAllowed(virDomainNetDefPtr iface,
- virNetDevBandwidthPtr newBandwidth)
-{
- virNetworkDriverStatePtr driver = networkGetDriver();
- virNetworkObjPtr obj = NULL;
- virNetDevBandwidthPtr ifaceBand = virDomainNetGetActualBandwidth(iface);
- bool ret = false;
-
- if (!networkBandwidthGenericChecks(iface, newBandwidth))
- return true;
-
- 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 false;
- }
-
- if (networkCheckBandwidth(obj, newBandwidth, ifaceBand, &iface->mac, NULL) < 0)
- goto cleanup;
-
- ret = true;
-
- cleanup:
- virNetworkObjEndAPI(&obj);
- return ret;
-}
-
-
static int
networkBandwidthUpdate(virDomainNetDefPtr iface,
virNetDevBandwidthPtr newBandwidth)
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;
return -1;
}
- if (!networkBandwidthGenericChecks(iface, newBandwidth))
+ if (virDomainNetGetActualType(iface) != VIR_DOMAIN_NET_TYPE_NETWORK &&
+ (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 bridge.
+ * 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 (newBandwidth && newBandwidth->in)
+ new_floor = newBandwidth->in->floor;
+
+ if (new_floor == old_floor)
return 0;
obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
networkAllocateActualDevice,
networkNotifyActualDevice,
networkReleaseActualDevice,
- networkBandwidthChangeAllowed,
networkBandwidthUpdate);
return 0;
}
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
- !virDomainNetBandwidthChangeAllowed(net, newBandwidth))
+ virDomainNetBandwidthUpdate(net, newBandwidth) < 0)
goto endjob;
if (virNetDevBandwidthSet(net->ifname, newBandwidth, false,
- !virDomainNetTypeSharesHostView(net)) < 0 ||
- (net->type == VIR_DOMAIN_NET_TYPE_NETWORK &&
- virDomainNetBandwidthUpdate(net, newBandwidth) < 0)) {
+ !virDomainNetTypeSharesHostView(net)) < 0) {
ignore_value(virNetDevBandwidthSet(net->ifname,
net->bandwidth,
false,
!virDomainNetTypeSharesHostView(net)));
+ ignore_value(virDomainNetBandwidthUpdate(net,
+ net->bandwidth));
goto endjob;
}