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(a)redhat.com>
---
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 a21aa26..5918bce 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -121,6 +121,21 @@ virNetworkObjGetNewDef(virNetworkObjPtr obj)
}
+bool
+virNetworkObjIsActive(virNetworkObjPtr obj)
+{
+ return obj->active;
+}
+
+
+void
+virNetworkObjSetActive(virNetworkObjPtr obj,
+ bool active)
+{
+ obj->active = active;
+}
+
+
int
virNetworkObjGetAutostart(virNetworkObjPtr obj)
{
@@ -1005,7 +1020,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 55a5331..60f0e0e 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;
@@ -56,6 +56,13 @@ virNetworkObjGetDef(virNetworkObjPtr obj);
virNetworkDefPtr
virNetworkObjGetNewDef(virNetworkObjPtr obj);
+bool
+virNetworkObjIsActive(virNetworkObjPtr obj);
+
+void
+virNetworkObjSetActive(virNetworkObjPtr obj,
+ bool active);
+
int
virNetworkObjGetAutostart(virNetworkObjPtr obj);
@@ -121,12 +128,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 b148eeb..85f4cbd 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -940,6 +940,7 @@ virNetworkObjGetMacMap;
virNetworkObjGetNewDef;
virNetworkObjGetPersistentDef;
virNetworkObjGetRadvdPid;
+virNetworkObjIsActive;
virNetworkObjListExport;
virNetworkObjListForEach;
virNetworkObjListGetNames;
@@ -955,6 +956,7 @@ virNetworkObjNew;
virNetworkObjRemoveInactive;
virNetworkObjReplacePersistentDef;
virNetworkObjSaveStatus;
+virNetworkObjSetActive;
virNetworkObjSetAutostart;
virNetworkObjSetDefTransient;
virNetworkObjSetDnsmasqPid;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 029f1b5..8ac5c7b 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 = virNetworkObjMacMgrFileName(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 e14fc63..ff03d30 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -986,7 +986,7 @@ testParseNetworks(testDriverPtr privconn,
goto error;
}
- obj->active = 1;
+ virNetworkObjSetActive(obj, true);
virNetworkObjEndAPI(&obj);
}
@@ -3401,7 +3401,7 @@ testNetworkCreateXML(virConnectPtr conn, const char *xml)
goto cleanup;
def = NULL;
objdef = virNetworkObjGetDef(obj);
- obj->active = 1;
+ virNetworkObjSetActive(obj, true);
event = virNetworkEventLifecycleNew(objdef->name, objdef->uuid,
VIR_NETWORK_EVENT_STARTED,
@@ -3543,7 +3543,7 @@ testNetworkCreate(virNetworkPtr net)
goto cleanup;
}
- obj->active = 1;
+ virNetworkObjSetActive(obj, true);
event = virNetworkEventLifecycleNew(def->name, def->uuid,
VIR_NETWORK_EVENT_STARTED,
0);
@@ -3569,7 +3569,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.3