network: Introduce virNetworkObj{Is|Set}Active

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@redhat.com>
This commit is contained in:
John Ferlan 2017-05-10 07:22:15 -04:00
parent f57d8a7b32
commit 9e8227d76b
5 changed files with 35 additions and 17 deletions

View File

@ -129,6 +129,21 @@ virNetworkObjGetNewDef(virNetworkObjPtr obj)
} }
bool
virNetworkObjIsActive(virNetworkObjPtr obj)
{
return obj->active;
}
void
virNetworkObjSetActive(virNetworkObjPtr obj,
bool active)
{
obj->active = active;
}
bool bool
virNetworkObjIsAutostart(virNetworkObjPtr obj) virNetworkObjIsAutostart(virNetworkObjPtr obj)
{ {
@ -924,7 +939,7 @@ virNetworkLoadState(virNetworkObjListPtr nets,
net->floor_sum = floor_sum_val; net->floor_sum = floor_sum_val;
net->taint = taint; 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: cleanup:
VIR_FREE(configFile); VIR_FREE(configFile);

View File

@ -31,7 +31,7 @@ struct _virNetworkObj {
pid_t dnsmasqPid; pid_t dnsmasqPid;
pid_t radvdPid; pid_t radvdPid;
unsigned int active : 1; bool active;
bool autostart; bool autostart;
unsigned int persistent : 1; unsigned int persistent : 1;
@ -60,6 +60,13 @@ virNetworkObjSetDef(virNetworkObjPtr obj,
virNetworkDefPtr virNetworkDefPtr
virNetworkObjGetNewDef(virNetworkObjPtr obj); virNetworkObjGetNewDef(virNetworkObjPtr obj);
bool
virNetworkObjIsActive(virNetworkObjPtr obj);
void
virNetworkObjSetActive(virNetworkObjPtr obj,
bool active);
bool bool
virNetworkObjIsAutostart(virNetworkObjPtr obj); virNetworkObjIsAutostart(virNetworkObjPtr obj);
@ -119,12 +126,6 @@ virNetworkObjEndAPI(virNetworkObjPtr *net);
typedef struct _virNetworkObjList virNetworkObjList; typedef struct _virNetworkObjList virNetworkObjList;
typedef virNetworkObjList *virNetworkObjListPtr; typedef virNetworkObjList *virNetworkObjListPtr;
static inline int
virNetworkObjIsActive(const virNetworkObj *net)
{
return net->active;
}
virNetworkObjListPtr virNetworkObjListPtr
virNetworkObjListNew(void); virNetworkObjListNew(void);

View File

@ -950,6 +950,7 @@ virNetworkObjGetMacMap;
virNetworkObjGetNewDef; virNetworkObjGetNewDef;
virNetworkObjGetPersistentDef; virNetworkObjGetPersistentDef;
virNetworkObjGetRadvdPid; virNetworkObjGetRadvdPid;
virNetworkObjIsActive;
virNetworkObjIsAutostart; virNetworkObjIsAutostart;
virNetworkObjListExport; virNetworkObjListExport;
virNetworkObjListForEach; virNetworkObjListForEach;
@ -965,6 +966,7 @@ virNetworkObjNew;
virNetworkObjRemoveInactive; virNetworkObjRemoveInactive;
virNetworkObjReplacePersistentDef; virNetworkObjReplacePersistentDef;
virNetworkObjSaveStatus; virNetworkObjSaveStatus;
virNetworkObjSetActive;
virNetworkObjSetAutostart; virNetworkObjSetAutostart;
virNetworkObjSetDef; virNetworkObjSetDef;
virNetworkObjSetDefTransient; virNetworkObjSetDefTransient;

View File

@ -452,7 +452,7 @@ networkUpdateState(virNetworkObjPtr obj,
case VIR_NETWORK_FORWARD_OPEN: case VIR_NETWORK_FORWARD_OPEN:
/* If bridge doesn't exist, then mark it inactive */ /* If bridge doesn't exist, then mark it inactive */
if (!(def->bridge && virNetDevExists(def->bridge) == 1)) if (!(def->bridge && virNetDevExists(def->bridge) == 1))
obj->active = 0; virNetworkObjSetActive(obj, false);
if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir, if (!(macMapFile = virMacMapFileName(driver->dnsmasqStateDir,
def->bridge))) def->bridge)))
@ -468,7 +468,7 @@ networkUpdateState(virNetworkObjPtr obj,
case VIR_NETWORK_FORWARD_BRIDGE: case VIR_NETWORK_FORWARD_BRIDGE:
if (def->bridge) { if (def->bridge) {
if (virNetDevExists(def->bridge) != 1) if (virNetDevExists(def->bridge) != 1)
obj->active = 0; virNetworkObjSetActive(obj, false);
break; break;
} }
/* intentionally drop through to common case for all /* intentionally drop through to common case for all
@ -487,7 +487,7 @@ networkUpdateState(virNetworkObjPtr obj,
} }
/* Try and read dnsmasq/radvd pids of active networks */ /* 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 radvdPid;
pid_t dnsmasqPid; pid_t dnsmasqPid;
char *radvdpidbase; char *radvdpidbase;
@ -2790,7 +2790,7 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0) if (virNetworkObjSaveStatus(driver->stateDir, obj) < 0)
goto cleanup; goto cleanup;
obj->active = 1; virNetworkObjSetActive(obj, true);
VIR_INFO("Network '%s' started up", def->name); VIR_INFO("Network '%s' started up", def->name);
ret = 0; ret = 0;
@ -2860,7 +2860,7 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver,
networkRunHook(obj, NULL, NULL, VIR_HOOK_NETWORK_OP_STOPPED, networkRunHook(obj, NULL, NULL, VIR_HOOK_NETWORK_OP_STOPPED,
VIR_HOOK_SUBOP_END); VIR_HOOK_SUBOP_END);
obj->active = 0; virNetworkObjSetActive(obj, false);
virNetworkObjUnsetDefTransient(obj); virNetworkObjUnsetDefTransient(obj);
return ret; return ret;
} }

View File

@ -988,7 +988,7 @@ testParseNetworks(testDriverPtr privconn,
goto error; goto error;
} }
obj->active = 1; virNetworkObjSetActive(obj, true);
virNetworkObjEndAPI(&obj); virNetworkObjEndAPI(&obj);
} }
@ -3404,7 +3404,7 @@ testNetworkCreateXML(virConnectPtr conn, const char *xml)
goto cleanup; goto cleanup;
newDef = NULL; newDef = NULL;
def = virNetworkObjGetDef(obj); def = virNetworkObjGetDef(obj);
obj->active = 1; virNetworkObjSetActive(obj, true);
event = virNetworkEventLifecycleNew(def->name, def->uuid, event = virNetworkEventLifecycleNew(def->name, def->uuid,
VIR_NETWORK_EVENT_STARTED, VIR_NETWORK_EVENT_STARTED,
@ -3546,7 +3546,7 @@ testNetworkCreate(virNetworkPtr net)
goto cleanup; goto cleanup;
} }
obj->active = 1; virNetworkObjSetActive(obj, true);
event = virNetworkEventLifecycleNew(def->name, def->uuid, event = virNetworkEventLifecycleNew(def->name, def->uuid,
VIR_NETWORK_EVENT_STARTED, VIR_NETWORK_EVENT_STARTED,
0); 0);
@ -3572,7 +3572,7 @@ testNetworkDestroy(virNetworkPtr net)
goto cleanup; goto cleanup;
def = virNetworkObjGetDef(obj); def = virNetworkObjGetDef(obj);
obj->active = 0; virNetworkObjSetActive(obj, false);
event = virNetworkEventLifecycleNew(def->name, def->uuid, event = virNetworkEventLifecycleNew(def->name, def->uuid,
VIR_NETWORK_EVENT_STOPPED, VIR_NETWORK_EVENT_STOPPED,
0); 0);