From 062c38ce75ba3d4112ddcdbdb8427997c7002b70 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Tue, 9 May 2017 17:57:41 -0400 Subject: [PATCH] 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 --- src/conf/virnetworkobj.c | 15 +++++++++++++++ src/conf/virnetworkobj.h | 7 +++++++ src/libvirt_private.syms | 2 ++ src/network/bridge_driver.c | 35 +++++++++++++++++++++++------------ 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 7b5e6a2983..1767c93758 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -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 virNetworkObjSetMacMap(virNetworkObjPtr obj, virMacMapPtr macmap) diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h index 79a9d09944..5dec0c3604 100644 --- a/src/conf/virnetworkobj.h +++ b/src/conf/virnetworkobj.h @@ -70,6 +70,13 @@ virNetworkObjSetRadvdPid(virNetworkObjPtr obj, virBitmapPtr virNetworkObjGetClassIdMap(virNetworkObjPtr obj); +unsigned long long +virNetworkObjGetFloorSum(virNetworkObjPtr obj); + +void +virNetworkObjSetFloorSum(virNetworkObjPtr obj, + unsigned long long floor_sum); + void virNetworkObjSetMacMap(virNetworkObjPtr obj, virMacMapPtr macmap); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b9964111f4..b756e282f1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -944,6 +944,7 @@ virNetworkObjFindByName; virNetworkObjFindByUUID; virNetworkObjGetClassIdMap; virNetworkObjGetDnsmasqPid; +virNetworkObjGetFloorSum; virNetworkObjGetMacMap; virNetworkObjGetPersistentDef; virNetworkObjGetRadvdPid; @@ -963,6 +964,7 @@ virNetworkObjReplacePersistentDef; virNetworkObjSaveStatus; virNetworkObjSetDefTransient; virNetworkObjSetDnsmasqPid; +virNetworkObjSetFloorSum; virNetworkObjSetMacMap; virNetworkObjSetRadvdPid; virNetworkObjTaint; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 4a1c258194..602492e2da 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5271,7 +5271,7 @@ networkCheckBandwidth(virNetworkObjPtr obj, { int ret = -1; 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; char ifmac[VIR_MAC_STRING_BUFLEN]; @@ -5365,6 +5365,7 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj, { virNetworkDriverStatePtr driver = networkGetDriver(); virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj); + unsigned long long tmp_floor_sum = virNetworkObjGetFloorSum(obj); ssize_t class_id = 0; int plug_ret; int ret = -1; @@ -5386,17 +5387,19 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj, /* QoS was set, generate new class ID */ iface->data.network.actual->class_id = class_id; /* 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 */ if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) { 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; ignore_value(virNetDevBandwidthUnplug(obj->def->bridge, class_id)); goto cleanup; } /* update rate for non guaranteed NICs */ - new_rate -= obj->floor_sum; + new_rate -= tmp_floor_sum; if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2, obj->def->bandwidth, new_rate) < 0) VIR_WARN("Unable to update rate for 1:2 class on %s bridge", @@ -5454,6 +5457,7 @@ networkUnplugBandwidth(virNetworkObjPtr obj, virDomainNetDefPtr iface) { virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj); + unsigned long long tmp_floor_sum = virNetworkObjGetFloorSum(obj); virNetworkDriverStatePtr driver = networkGetDriver(); int ret = 0; unsigned long long new_rate; @@ -5477,19 +5481,22 @@ networkUnplugBandwidth(virNetworkObjPtr obj, if (ret < 0) goto cleanup; /* 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 */ ignore_value(virBitmapClearBit(classIdMap, iface->data.network.actual->class_id)); /* update status file */ 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, iface->data.network.actual->class_id)); goto cleanup; } /* update rate for non guaranteed NICs */ - new_rate -= obj->floor_sum; + new_rate -= tmp_floor_sum; if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2, obj->def->bandwidth, new_rate) < 0) VIR_WARN("Unable to update rate for 1:2 class on %s bridge", @@ -5581,6 +5588,7 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, { virNetworkDriverStatePtr driver = networkGetDriver(); virNetworkObjPtr obj = NULL; + unsigned long long tmp_floor_sum; virNetDevBandwidthPtr ifaceBand = virDomainNetGetActualBandwidth(iface); unsigned long long new_rate = 0; int plug_ret; @@ -5621,16 +5629,19 @@ networkBandwidthUpdate(virDomainNetDefPtr iface, newBandwidth->in->floor) < 0) goto cleanup; - obj->floor_sum -= ifaceBand->in->floor; - obj->floor_sum += newBandwidth->in->floor; - new_rate -= obj->floor_sum; + tmp_floor_sum = virNetworkObjGetFloorSum(obj); + tmp_floor_sum -= ifaceBand->in->floor; + tmp_floor_sum += newBandwidth->in->floor; + virNetworkObjSetFloorSum(obj, tmp_floor_sum); + new_rate -= tmp_floor_sum; if (virNetDevBandwidthUpdateRate(obj->def->bridge, 2, obj->def->bandwidth, new_rate) < 0 || virNetworkObjSaveStatus(driver->stateDir, obj) < 0) { /* Ouch, rollback */ - obj->floor_sum -= newBandwidth->in->floor; - obj->floor_sum += ifaceBand->in->floor; + tmp_floor_sum -= newBandwidth->in->floor; + tmp_floor_sum += ifaceBand->in->floor; + virNetworkObjSetFloorSum(obj, tmp_floor_sum); ignore_value(virNetDevBandwidthUpdateRate(obj->def->bridge, iface->data.network.actual->class_id,