[PATCH 07/16] network: Alter virNetworkObj @class_id to be @classIdMap

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

 



Change the variable name to be a bit more descriptive and less confusing
when used with the data.network.actual->class_id.

In preparation for privatizing virNetworkObj, create accessor function to
fetch the @classIdMap.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virnetworkobj.c    | 46 ++++++++++++++++++++++++++-------------------
 src/conf/virnetworkobj.h    |  5 ++++-
 src/libvirt_private.syms    |  1 +
 src/network/bridge_driver.c | 13 ++++++++-----
 4 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index e44684a..991916a 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -79,13 +79,13 @@ virNetworkObjNew(void)
     if (!(net = virObjectLockableNew(virNetworkObjClass)))
         return NULL;
 
-    if (!(net->class_id = virBitmapNew(CLASS_ID_BITMAP_SIZE)))
+    if (!(net->classIdMap = virBitmapNew(CLASS_ID_BITMAP_SIZE)))
         goto error;
 
     /* The first three class IDs are already taken */
-    ignore_value(virBitmapSetBit(net->class_id, 0));
-    ignore_value(virBitmapSetBit(net->class_id, 1));
-    ignore_value(virBitmapSetBit(net->class_id, 2));
+    ignore_value(virBitmapSetBit(net->classIdMap, 0));
+    ignore_value(virBitmapSetBit(net->classIdMap, 1));
+    ignore_value(virBitmapSetBit(net->classIdMap, 2));
 
     return net;
 
@@ -137,6 +137,13 @@ virNetworkObjSetRadvdPid(virNetworkObjPtr obj,
 }
 
 
+virBitmapPtr
+virNetworkObjGetClassIdMap(virNetworkObjPtr obj)
+{
+    return obj->classIdMap;
+}
+
+
 virMacMapPtr
 virNetworkObjGetMacMap(virNetworkObjPtr obj)
 {
@@ -388,7 +395,7 @@ virNetworkObjDispose(void *obj)
 
     virNetworkDefFree(net->def);
     virNetworkDefFree(net->newDef);
-    virBitmapFree(net->class_id);
+    virBitmapFree(net->classIdMap);
     virObjectUnref(net->macmap);
 }
 
@@ -728,17 +735,17 @@ virNetworkObjFormat(virNetworkObjPtr net,
                     unsigned int flags)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
-    char *class_id = virBitmapFormat(net->class_id);
+    char *classIdStr = virBitmapFormat(net->classIdMap);
     size_t i;
 
-    if (!class_id)
+    if (!classIdStr)
         goto error;
 
     virBufferAddLit(&buf, "<networkstatus>\n");
     virBufferAdjustIndent(&buf, 2);
-    virBufferAsprintf(&buf, "<class_id bitmap='%s'/>\n", class_id);
+    virBufferAsprintf(&buf, "<class_id bitmap='%s'/>\n", classIdStr);
     virBufferAsprintf(&buf, "<floor sum='%llu'/>\n", net->floor_sum);
-    VIR_FREE(class_id);
+    VIR_FREE(classIdStr);
 
     for (i = 0; i < VIR_NETWORK_TAINT_LAST; i++) {
         if (net->taint & (1 << i))
@@ -795,7 +802,7 @@ virNetworkLoadState(virNetworkObjListPtr nets,
     xmlDocPtr xml = NULL;
     xmlNodePtr node = NULL, *nodes = NULL;
     xmlXPathContextPtr ctxt = NULL;
-    virBitmapPtr class_id_map = NULL;
+    virBitmapPtr classIdMap = NULL;
     unsigned long long floor_sum_val = 0;
     unsigned int taint = 0;
     int n;
@@ -832,18 +839,19 @@ virNetworkLoadState(virNetworkObjListPtr nets,
     if (xmlStrEqual(node->name, BAD_CAST "networkstatus")) {
         /* Newer network status file. Contains useful
          * info which are not to be found in bare config XML */
-        char *class_id = NULL;
+        char *classIdStr = NULL;
         char *floor_sum = NULL;
 
         ctxt->node = node;
-        if ((class_id = virXPathString("string(./class_id[1]/@bitmap)", ctxt))) {
-            if (virBitmapParse(class_id, &class_id_map,
+        if ((classIdStr = virXPathString("string(./class_id[1]/@bitmap)",
+                                         ctxt))) {
+            if (virBitmapParse(classIdStr, &classIdMap,
                                CLASS_ID_BITMAP_SIZE) < 0) {
-                VIR_FREE(class_id);
+                VIR_FREE(classIdStr);
                 goto error;
             }
         }
-        VIR_FREE(class_id);
+        VIR_FREE(classIdStr);
 
         floor_sum = virXPathString("string(./floor[1]/@sum)", ctxt);
         if (floor_sum &&
@@ -885,9 +893,9 @@ virNetworkLoadState(virNetworkObjListPtr nets,
     /* do not put any "goto error" below this comment */
 
     /* assign status data stored in the network object */
-    if (class_id_map) {
-        virBitmapFree(net->class_id);
-        net->class_id = class_id_map;
+    if (classIdMap) {
+        virBitmapFree(net->classIdMap);
+        net->classIdMap = classIdMap;
     }
 
     if (floor_sum_val > 0)
@@ -904,7 +912,7 @@ virNetworkLoadState(virNetworkObjListPtr nets,
 
  error:
     VIR_FREE(nodes);
-    virBitmapFree(class_id_map);
+    virBitmapFree(classIdMap);
     virNetworkDefFree(def);
     goto cleanup;
 }
diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h
index 9323692..eec38e2 100644
--- a/src/conf/virnetworkobj.h
+++ b/src/conf/virnetworkobj.h
@@ -38,7 +38,7 @@ struct _virNetworkObj {
     virNetworkDefPtr def; /* The current definition */
     virNetworkDefPtr newDef; /* New definition to activate at shutdown */
 
-    virBitmapPtr class_id; /* bitmap of class IDs for QoS */
+    virBitmapPtr classIdMap; /* bitmap of class IDs for QoS */
     unsigned long long floor_sum; /* sum of all 'floor'-s of attached NICs */
 
     unsigned int taint;
@@ -67,6 +67,9 @@ void
 virNetworkObjSetRadvdPid(virNetworkObjPtr obj,
                          pid_t radvdPid);
 
+virBitmapPtr
+virNetworkObjGetClassIdMap(virNetworkObjPtr obj);
+
 void
 virNetworkObjSetMacMap(virNetworkObjPtr obj,
                        virMacMapPtr macmap);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 56b969c..20ab35b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -931,6 +931,7 @@ virNetworkObjFindByName;
 virNetworkObjFindByNameLocked;
 virNetworkObjFindByUUID;
 virNetworkObjFindByUUIDLocked;
+virNetworkObjGetClassIdMap;
 virNetworkObjGetDnsmasqPid;
 virNetworkObjGetMacMap;
 virNetworkObjGetPersistentDef;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 31a3d40..879901a 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -5347,10 +5347,11 @@ static ssize_t
 networkNextClassID(virNetworkObjPtr obj)
 {
     ssize_t ret = 0;
+    virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
 
-    ret = virBitmapNextClearBit(obj->class_id, -1);
+    ret = virBitmapNextClearBit(classIdMap, -1);
 
-    if (ret < 0 || virBitmapSetBit(obj->class_id, ret) < 0)
+    if (ret < 0 || virBitmapSetBit(classIdMap, ret) < 0)
         return -1;
 
     return ret;
@@ -5364,6 +5365,7 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj,
                          unsigned long long new_rate)
 {
     virNetworkDriverStatePtr driver = networkGetDriver();
+    virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
     ssize_t class_id = 0;
     int plug_ret;
     int ret = -1;
@@ -5388,7 +5390,7 @@ networkPlugBandwidthImpl(virNetworkObjPtr obj,
     obj->floor_sum += ifaceBand->in->floor;
     /* update status file */
     if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) {
-        ignore_value(virBitmapClearBit(obj->class_id, class_id));
+        ignore_value(virBitmapClearBit(classIdMap, class_id));
         obj->floor_sum -= ifaceBand->in->floor;
         iface->data.network.actual->class_id = 0;
         ignore_value(virNetDevBandwidthUnplug(obj->def->bridge, class_id));
@@ -5452,6 +5454,7 @@ static int
 networkUnplugBandwidth(virNetworkObjPtr obj,
                        virDomainNetDefPtr iface)
 {
+    virBitmapPtr classIdMap = virNetworkObjGetClassIdMap(obj);
     virNetworkDriverStatePtr driver = networkGetDriver();
     int ret = 0;
     unsigned long long new_rate;
@@ -5477,12 +5480,12 @@ networkUnplugBandwidth(virNetworkObjPtr obj,
         /* update sum of 'floor'-s of attached NICs */
         obj->floor_sum -= ifaceBand->in->floor;
         /* return class ID */
-        ignore_value(virBitmapClearBit(obj->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;
-            ignore_value(virBitmapSetBit(obj->class_id,
+            ignore_value(virBitmapSetBit(classIdMap,
                                          iface->data.network.actual->class_id));
             goto cleanup;
         }
-- 
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