[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 09/20] 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>
---
 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 1fedb1c..ce571bc 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 dc8a1cd..12d0a86 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 147d78d..35dfe5e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -946,6 +946,7 @@ virNetworkObjFindByUUID;
 virNetworkObjFindByUUIDLocked;
 virNetworkObjGetClassIdMap;
 virNetworkObjGetDnsmasqPid;
+virNetworkObjGetFloorSum;
 virNetworkObjGetMacMap;
 virNetworkObjGetPersistentDef;
 virNetworkObjGetRadvdPid;
@@ -965,6 +966,7 @@ virNetworkObjReplacePersistentDef;
 virNetworkObjSaveStatus;
 virNetworkObjSetDefTransient;
 virNetworkObjSetDnsmasqPid;
+virNetworkObjSetFloorSum;
 virNetworkObjSetMacMap;
 virNetworkObjSetRadvdPid;
 virNetworkObjTaint;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 4a1c258..602492e 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,
-- 
2.9.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]