[PATCH v2 12/20] network: Introduce virNetworkObj{Is|Set}Active

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

 



In order to privatize the virNetworkObj create accessors in virnetworkobj
in order to handle the get/set of the active value.

Also rather than an unsigned int, convert it to a boolean to match other
drivers representation and the reality of what it is.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virnetworkobj.c    | 17 ++++++++++++++++-
 src/conf/virnetworkobj.h    | 15 ++++++++-------
 src/libvirt_private.syms    |  2 ++
 src/network/bridge_driver.c | 10 +++++-----
 src/test/test_driver.c      |  8 ++++----
 5 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 36d4bff..a195494 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -129,6 +129,21 @@ virNetworkObjGetNewDef(virNetworkObjPtr obj)
 }
 
 
+bool
+virNetworkObjIsActive(virNetworkObjPtr obj)
+{
+    return obj->active;
+}
+
+
+void
+virNetworkObjSetActive(virNetworkObjPtr obj,
+                       bool active)
+{
+    obj->active = active;
+}
+
+
 int
 virNetworkObjGetAutostart(virNetworkObjPtr obj)
 {
@@ -942,7 +957,7 @@ virNetworkLoadState(virNetworkObjListPtr nets,
         net->floor_sum = floor_sum_val;
 
     net->taint = taint;
-    net->active = 1; /* any network with a state file is by definition active */
+    net->active = true; /* any network with a state file is by definition active */
 
  cleanup:
     VIR_FREE(configFile);
diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h
index a526d30..8b778c8 100644
--- a/src/conf/virnetworkobj.h
+++ b/src/conf/virnetworkobj.h
@@ -31,7 +31,7 @@ struct _virNetworkObj {
 
     pid_t dnsmasqPid;
     pid_t radvdPid;
-    unsigned int active : 1;
+    bool active;
     int autostart;
     unsigned int persistent : 1;
 
@@ -60,6 +60,13 @@ virNetworkObjSetDef(virNetworkObjPtr obj,
 virNetworkDefPtr
 virNetworkObjGetNewDef(virNetworkObjPtr obj);
 
+bool
+virNetworkObjIsActive(virNetworkObjPtr obj);
+
+void
+virNetworkObjSetActive(virNetworkObjPtr obj,
+                       bool active);
+
 int
 virNetworkObjGetAutostart(virNetworkObjPtr obj);
 
@@ -119,12 +126,6 @@ virNetworkObjEndAPI(virNetworkObjPtr *net);
 typedef struct _virNetworkObjList virNetworkObjList;
 typedef virNetworkObjList *virNetworkObjListPtr;
 
-static inline int
-virNetworkObjIsActive(const virNetworkObj *net)
-{
-    return net->active;
-}
-
 virNetworkObjListPtr
 virNetworkObjListNew(void);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8a3284f..8796258 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -953,6 +953,7 @@ virNetworkObjGetMacMap;
 virNetworkObjGetNewDef;
 virNetworkObjGetPersistentDef;
 virNetworkObjGetRadvdPid;
+virNetworkObjIsActive;
 virNetworkObjListExport;
 virNetworkObjListForEach;
 virNetworkObjListGetNames;
@@ -967,6 +968,7 @@ virNetworkObjNew;
 virNetworkObjRemoveInactive;
 virNetworkObjReplacePersistentDef;
 virNetworkObjSaveStatus;
+virNetworkObjSetActive;
 virNetworkObjSetAutostart;
 virNetworkObjSetDef;
 virNetworkObjSetDefTransient;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index eb814d3..f423c82 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -451,7 +451,7 @@ networkUpdateState(virNetworkObjPtr obj,
     case VIR_NETWORK_FORWARD_OPEN:
         /* If bridge doesn't exist, then mark it inactive */
         if (!(def->bridge && virNetDevExists(def->bridge) == 1))
-            obj->active = 0;
+            virNetworkObjSetActive(obj, false);
 
         if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir,
                                              def->bridge)))
@@ -467,7 +467,7 @@ networkUpdateState(virNetworkObjPtr obj,
     case VIR_NETWORK_FORWARD_BRIDGE:
         if (def->bridge) {
             if (virNetDevExists(def->bridge) != 1)
-                obj->active = 0;
+                virNetworkObjSetActive(obj, false);
             break;
         }
         /* intentionally drop through to common case for all
@@ -486,7 +486,7 @@ networkUpdateState(virNetworkObjPtr obj,
     }
 
     /* Try and read dnsmasq/radvd pids of active networks */
-    if (obj->active && def->ips && (def->nips > 0)) {
+    if (virNetworkObjIsActive(obj) && def->ips && (def->nips > 0)) {
         pid_t radvdPid;
         pid_t dnsmasqPid;
         char *radvdpidbase;
@@ -2789,7 +2789,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
     if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0)
         goto cleanup;
 
-    obj->active = 1;
+    virNetworkObjSetActive(obj, true);
     VIR_INFO("Network '%s' started up", def->name);
     ret = 0;
 
@@ -2859,7 +2859,7 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver,
     networkRunHook(obj, NULL, NULL, VIR_HOOK_NETWORK_OP_STOPPED,
                    VIR_HOOK_SUBOP_END);
 
-    obj->active = 0;
+    virNetworkObjSetActive(obj, false);
     virNetworkObjUnsetDefTransient(obj);
     return ret;
 }
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 8e841b2..698488e 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -988,7 +988,7 @@ testParseNetworks(testDriverPtr privconn,
             goto error;
         }
 
-        obj->active = 1;
+        virNetworkObjSetActive(obj, true);
         virNetworkObjEndAPI(&obj);
     }
 
@@ -3404,7 +3404,7 @@ testNetworkCreateXML(virConnectPtr conn, const char *xml)
         goto cleanup;
     newDef = NULL;
     def = virNetworkObjGetDef(obj);
-    obj->active = 1;
+    virNetworkObjSetActive(obj, true);
 
     event = virNetworkEventLifecycleNew(def->name, def->uuid,
                                         VIR_NETWORK_EVENT_STARTED,
@@ -3546,7 +3546,7 @@ testNetworkCreate(virNetworkPtr net)
         goto cleanup;
     }
 
-    obj->active = 1;
+    virNetworkObjSetActive(obj, true);
     event = virNetworkEventLifecycleNew(def->name, def->uuid,
                                         VIR_NETWORK_EVENT_STARTED,
                                         0);
@@ -3572,7 +3572,7 @@ testNetworkDestroy(virNetworkPtr net)
         goto cleanup;
     def = virNetworkObjGetDef(obj);
 
-    obj->active = 0;
+    virNetworkObjSetActive(obj, false);
     event = virNetworkEventLifecycleNew(def->name, def->uuid,
                                         VIR_NETWORK_EVENT_STOPPED,
                                         0);
-- 
2.9.4

--
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