[PATCH 08/16] network: Add virNetworkObj Get/Set API's for @floor_sum

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

 



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@xxxxxxxxxx>
---
 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 991916a..a848203 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 eec38e2..aa544ed 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 20ab35b..150b6f1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -933,6 +933,7 @@ virNetworkObjFindByUUID;
 virNetworkObjFindByUUIDLocked;
 virNetworkObjGetClassIdMap;
 virNetworkObjGetDnsmasqPid;
+virNetworkObjGetFloorSum;
 virNetworkObjGetMacMap;
 virNetworkObjGetPersistentDef;
 virNetworkObjGetRadvdPid;
@@ -953,6 +954,7 @@ virNetworkObjReplacePersistentDef;
 virNetworkObjSaveStatus;
 virNetworkObjSetDefTransient;
 virNetworkObjSetDnsmasqPid;
+virNetworkObjSetFloorSum;
 virNetworkObjSetMacMap;
 virNetworkObjSetRadvdPid;
 virNetworkObjTaint;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 879901a..cd91a1a 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -5272,7 +5272,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];
 
@@ -5366,6 +5366,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;
@@ -5387,17 +5388,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",
@@ -5455,6 +5458,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;
@@ -5478,19 +5482,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",
@@ -5582,6 +5589,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;
@@ -5622,16 +5630,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.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux