mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
network: Add virNetworkObj Get/Set API's for @floor_sum
In preparation for making the object private, create a couple of API's to get/set the obj->floor_sum. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
7435404fd5
commit
062c38ce75
@ -151,6 +151,21 @@ virNetworkObjGetMacMap(virNetworkObjPtr obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long long
|
||||||
|
virNetworkObjGetFloorSum(virNetworkObjPtr obj)
|
||||||
|
{
|
||||||
|
return obj->floor_sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
virNetworkObjSetFloorSum(virNetworkObjPtr obj,
|
||||||
|
unsigned long long floor_sum)
|
||||||
|
{
|
||||||
|
obj->floor_sum = floor_sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
virNetworkObjSetMacMap(virNetworkObjPtr obj,
|
virNetworkObjSetMacMap(virNetworkObjPtr obj,
|
||||||
virMacMapPtr macmap)
|
virMacMapPtr macmap)
|
||||||
|
@ -70,6 +70,13 @@ virNetworkObjSetRadvdPid(virNetworkObjPtr obj,
|
|||||||
virBitmapPtr
|
virBitmapPtr
|
||||||
virNetworkObjGetClassIdMap(virNetworkObjPtr obj);
|
virNetworkObjGetClassIdMap(virNetworkObjPtr obj);
|
||||||
|
|
||||||
|
unsigned long long
|
||||||
|
virNetworkObjGetFloorSum(virNetworkObjPtr obj);
|
||||||
|
|
||||||
|
void
|
||||||
|
virNetworkObjSetFloorSum(virNetworkObjPtr obj,
|
||||||
|
unsigned long long floor_sum);
|
||||||
|
|
||||||
void
|
void
|
||||||
virNetworkObjSetMacMap(virNetworkObjPtr obj,
|
virNetworkObjSetMacMap(virNetworkObjPtr obj,
|
||||||
virMacMapPtr macmap);
|
virMacMapPtr macmap);
|
||||||
|
@ -944,6 +944,7 @@ virNetworkObjFindByName;
|
|||||||
virNetworkObjFindByUUID;
|
virNetworkObjFindByUUID;
|
||||||
virNetworkObjGetClassIdMap;
|
virNetworkObjGetClassIdMap;
|
||||||
virNetworkObjGetDnsmasqPid;
|
virNetworkObjGetDnsmasqPid;
|
||||||
|
virNetworkObjGetFloorSum;
|
||||||
virNetworkObjGetMacMap;
|
virNetworkObjGetMacMap;
|
||||||
virNetworkObjGetPersistentDef;
|
virNetworkObjGetPersistentDef;
|
||||||
virNetworkObjGetRadvdPid;
|
virNetworkObjGetRadvdPid;
|
||||||
@ -963,6 +964,7 @@ virNetworkObjReplacePersistentDef;
|
|||||||
virNetworkObjSaveStatus;
|
virNetworkObjSaveStatus;
|
||||||
virNetworkObjSetDefTransient;
|
virNetworkObjSetDefTransient;
|
||||||
virNetworkObjSetDnsmasqPid;
|
virNetworkObjSetDnsmasqPid;
|
||||||
|
virNetworkObjSetFloorSum;
|
||||||
virNetworkObjSetMacMap;
|
virNetworkObjSetMacMap;
|
||||||
virNetworkObjSetRadvdPid;
|
virNetworkObjSetRadvdPid;
|
||||||
virNetworkObjTaint;
|
virNetworkObjTaint;
|
||||||
|
@ -5271,7 +5271,7 @@ networkCheckBandwidth(virNetworkObjPtr obj,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virNetDevBandwidthPtr netBand = obj->def->bandwidth;
|
virNetDevBandwidthPtr netBand = obj->def->bandwidth;
|
||||||
unsigned long long tmp_floor_sum = obj->floor_sum;
|
unsigned long long tmp_floor_sum = virNetworkObjGetFloorSum(obj);
|
||||||
unsigned long long tmp_new_rate = 0;
|
unsigned long long tmp_new_rate = 0;
|
||||||
char ifmac[VIR_MAC_STRING_BUFLEN];
|
char ifmac[VIR_MAC_STRING_BUFLEN];
|
||||||
|
|
||||||
@ -5365,6 +5365,7 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj,
|
|||||||
{
|
{
|
||||||
virNetworkDriverStatePtr driver = networkGetDriver();
|
virNetworkDriverStatePtr driver = networkGetDriver();
|
||||||
virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
|
virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
|
||||||
|
unsigned long long tmp_floor_sum = virNetworkObjGetFloorSum(obj);
|
||||||
ssize_t class_id = 0;
|
ssize_t class_id = 0;
|
||||||
int plug_ret;
|
int plug_ret;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -5386,17 +5387,19 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj,
|
|||||||
/* QoS was set, generate new class ID */
|
/* QoS was set, generate new class ID */
|
||||||
iface->data.network.actual->class_id = class_id;
|
iface->data.network.actual->class_id = class_id;
|
||||||
/* update sum of 'floor'-s of attached NICs */
|
/* update sum of 'floor'-s of attached NICs */
|
||||||
obj->floor_sum += ifaceBand->in->floor;
|
tmp_floor_sum += ifaceBand->in->floor;
|
||||||
|
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
|
||||||
/* update status file */
|
/* update status file */
|
||||||
if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) {
|
if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) {
|
||||||
ignore_value(virBitmapClearBit(classIdMap, class_id));
|
ignore_value(virBitmapClearBit(classIdMap, class_id));
|
||||||
obj->floor_sum -= ifaceBand->in->floor;
|
tmp_floor_sum -= ifaceBand->in->floor;
|
||||||
|
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
|
||||||
iface->data.network.actual->class_id = 0;
|
iface->data.network.actual->class_id = 0;
|
||||||
ignore_value(virNetDevBandwidthUnplug(obj->def->bridge, class_id));
|
ignore_value(virNetDevBandwidthUnplug(obj->def->bridge, class_id));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
/* update rate for non guaranteed NICs */
|
/* update rate for non guaranteed NICs */
|
||||||
new_rate -= obj->floor_sum;
|
new_rate -= tmp_floor_sum;
|
||||||
if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2,
|
if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2,
|
||||||
obj->def->bandwidth, new_rate) < 0)
|
obj->def->bandwidth, new_rate) < 0)
|
||||||
VIR_WARN("Unable to update rate for 1:2 class on %s bridge",
|
VIR_WARN("Unable to update rate for 1:2 class on %s bridge",
|
||||||
@ -5454,6 +5457,7 @@ networkUnplugBandwidth(virNetworkObjPtr obj,
|
|||||||
virDomainNetDefPtr iface)
|
virDomainNetDefPtr iface)
|
||||||
{
|
{
|
||||||
virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
|
virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
|
||||||
|
unsigned long long tmp_floor_sum = virNetworkObjGetFloorSum(obj);
|
||||||
virNetworkDriverStatePtr driver = networkGetDriver();
|
virNetworkDriverStatePtr driver = networkGetDriver();
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
unsigned long long new_rate;
|
unsigned long long new_rate;
|
||||||
@ -5477,19 +5481,22 @@ networkUnplugBandwidth(virNetworkObjPtr obj,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
/* update sum of 'floor'-s of attached NICs */
|
/* update sum of 'floor'-s of attached NICs */
|
||||||
obj->floor_sum -= ifaceBand->in->floor;
|
tmp_floor_sum -= ifaceBand->in->floor;
|
||||||
|
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
|
||||||
|
|
||||||
/* return class ID */
|
/* return class ID */
|
||||||
ignore_value(virBitmapClearBit(classIdMap,
|
ignore_value(virBitmapClearBit(classIdMap,
|
||||||
iface->data.network.actual->class_id));
|
iface->data.network.actual->class_id));
|
||||||
/* update status file */
|
/* update status file */
|
||||||
if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) {
|
if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) {
|
||||||
obj->floor_sum += ifaceBand->in->floor;
|
tmp_floor_sum += ifaceBand->in->floor;
|
||||||
|
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
|
||||||
ignore_value(virBitmapSetBit(classIdMap,
|
ignore_value(virBitmapSetBit(classIdMap,
|
||||||
iface->data.network.actual->class_id));
|
iface->data.network.actual->class_id));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
/* update rate for non guaranteed NICs */
|
/* update rate for non guaranteed NICs */
|
||||||
new_rate -= obj->floor_sum;
|
new_rate -= tmp_floor_sum;
|
||||||
if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2,
|
if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2,
|
||||||
obj->def->bandwidth, new_rate) < 0)
|
obj->def->bandwidth, new_rate) < 0)
|
||||||
VIR_WARN("Unable to update rate for 1:2 class on %s bridge",
|
VIR_WARN("Unable to update rate for 1:2 class on %s bridge",
|
||||||
@ -5581,6 +5588,7 @@ networkBandwidthUpdate(virDomainNetDefPtr iface,
|
|||||||
{
|
{
|
||||||
virNetworkDriverStatePtr driver = networkGetDriver();
|
virNetworkDriverStatePtr driver = networkGetDriver();
|
||||||
virNetworkObjPtr obj = NULL;
|
virNetworkObjPtr obj = NULL;
|
||||||
|
unsigned long long tmp_floor_sum;
|
||||||
virNetDevBandwidthPtr ifaceBand = virDomainNetGetActualBandwidth(iface);
|
virNetDevBandwidthPtr ifaceBand = virDomainNetGetActualBandwidth(iface);
|
||||||
unsigned long long new_rate = 0;
|
unsigned long long new_rate = 0;
|
||||||
int plug_ret;
|
int plug_ret;
|
||||||
@ -5621,16 +5629,19 @@ networkBandwidthUpdate(virDomainNetDefPtr iface,
|
|||||||
newBandwidth->in->floor) < 0)
|
newBandwidth->in->floor) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
obj->floor_sum -= ifaceBand->in->floor;
|
tmp_floor_sum = virNetworkObjGetFloorSum(obj);
|
||||||
obj->floor_sum += newBandwidth->in->floor;
|
tmp_floor_sum -= ifaceBand->in->floor;
|
||||||
new_rate -= obj->floor_sum;
|
tmp_floor_sum += newBandwidth->in->floor;
|
||||||
|
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
|
||||||
|
new_rate -= tmp_floor_sum;
|
||||||
|
|
||||||
if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2,
|
if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2,
|
||||||
obj->def->bandwidth, new_rate) < 0 ||
|
obj->def->bandwidth, new_rate) < 0 ||
|
||||||
virNetworkObjSaveStatus(driver->stateDir, obj) < 0) {
|
virNetworkObjSaveStatus(driver->stateDir, obj) < 0) {
|
||||||
/* Ouch, rollback */
|
/* Ouch, rollback */
|
||||||
obj->floor_sum -= newBandwidth->in->floor;
|
tmp_floor_sum -= newBandwidth->in->floor;
|
||||||
obj->floor_sum += ifaceBand->in->floor;
|
tmp_floor_sum += ifaceBand->in->floor;
|
||||||
|
virNetworkObjSetFloorSum(obj, tmp_floor_sum);
|
||||||
|
|
||||||
ignore_value(virNetDevBandwidthUpdateRate(obj->def->bridge,
|
ignore_value(virNetDevBandwidthUpdateRate(obj->def->bridge,
|
||||||
iface->data.network.actual->class_id,
|
iface->data.network.actual->class_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user