In preparation for making the object private, create/use a couple of API's
to get/set the obj->dnsmasqPid and obj->radvdPid.
NB: Since the pid's can sometimes changed based on intervening functions,
be sure to always fetch the latest value.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virnetworkobj.c | 30 ++++++++++++++
src/conf/virnetworkobj.h | 14 +++++++
src/libvirt_private.syms | 4 ++
src/network/bridge_driver.c | 96 ++++++++++++++++++++++++++++-----------------
4 files changed, 109 insertions(+), 35 deletions(-)
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 562fb91..e44684a 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -107,6 +107,36 @@ virNetworkObjEndAPI(virNetworkObjPtr *net)
}
+pid_t
+virNetworkObjGetDnsmasqPid(virNetworkObjPtr obj)
+{
+ return obj->dnsmasqPid;
+}
+
+
+void
+virNetworkObjSetDnsmasqPid(virNetworkObjPtr obj,
+ pid_t dnsmasqPid)
+{
+ obj->dnsmasqPid = dnsmasqPid;
+}
+
+
+pid_t
+virNetworkObjGetRadvdPid(virNetworkObjPtr obj)
+{
+ return obj->radvdPid;
+}
+
+
+void
+virNetworkObjSetRadvdPid(virNetworkObjPtr obj,
+ pid_t radvdPid)
+{
+ obj->radvdPid = radvdPid;
+}
+
+
virMacMapPtr
virNetworkObjGetMacMap(virNetworkObjPtr obj)
{
diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h
index da12848..9323692 100644
--- a/src/conf/virnetworkobj.h
+++ b/src/conf/virnetworkobj.h
@@ -53,6 +53,20 @@ virNetworkObjNew(void);
virMacMapPtr
virNetworkObjGetMacMap(virNetworkObjPtr obj);
+pid_t
+virNetworkObjGetDnsmasqPid(virNetworkObjPtr obj);
+
+void
+virNetworkObjSetDnsmasqPid(virNetworkObjPtr obj,
+ pid_t dnsmasqPid);
+
+pid_t
+virNetworkObjGetRadvdPid(virNetworkObjPtr obj);
+
+void
+virNetworkObjSetRadvdPid(virNetworkObjPtr obj,
+ pid_t radvdPid);
+
void
virNetworkObjSetMacMap(virNetworkObjPtr obj,
virMacMapPtr macmap);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1907afe..56b969c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -931,8 +931,10 @@ virNetworkObjFindByName;
virNetworkObjFindByNameLocked;
virNetworkObjFindByUUID;
virNetworkObjFindByUUIDLocked;
+virNetworkObjGetDnsmasqPid;
virNetworkObjGetMacMap;
virNetworkObjGetPersistentDef;
+virNetworkObjGetRadvdPid;
virNetworkObjListExport;
virNetworkObjListForEach;
virNetworkObjListGetNames;
@@ -949,7 +951,9 @@ virNetworkObjRemoveInactive;
virNetworkObjReplacePersistentDef;
virNetworkObjSaveStatus;
virNetworkObjSetDefTransient;
+virNetworkObjSetDnsmasqPid;
virNetworkObjSetMacMap;
+virNetworkObjSetRadvdPid;
virNetworkObjTaint;
virNetworkObjUnrefMacMap;
virNetworkObjUnsetDefTransient;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index d8d3782..31a3d40 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -485,12 +485,15 @@ networkUpdateState(virNetworkObjPtr obj,
/* Try and read dnsmasq/radvd pids of active networks */
if (obj->active && obj->def->ips && (obj->def->nips
> 0)) {
+ pid_t radvdPid;
+ pid_t dnsmasqPid;
char *radvdpidbase;
ignore_value(virPidFileReadIfAlive(driver->pidDir,
obj->def->name,
- &obj->dnsmasqPid,
+ &dnsmasqPid,
dnsmasqCapsGetBinaryPath(dnsmasq_caps)));
+ virNetworkObjSetDnsmasqPid(obj, dnsmasqPid);
radvdpidbase = networkRadvdPidfileBasename(obj->def->name);
if (!radvdpidbase)
@@ -498,7 +501,8 @@ networkUpdateState(virNetworkObjPtr obj,
ignore_value(virPidFileReadIfAlive(driver->pidDir,
radvdpidbase,
- &obj->radvdPid, RADVD));
+ &radvdPid, RADVD));
+ virNetworkObjSetRadvdPid(obj, radvdPid);
VIR_FREE(radvdpidbase);
}
@@ -1481,7 +1485,7 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverStatePtr driver,
char *configstr = NULL;
char *leaseshelper_path = NULL;
- obj->dnsmasqPid = -1;
+ virNetworkObjSetDnsmasqPid(obj, -1);
if (networkDnsmasqConfContents(obj, pidfile, &configstr,
dctx, dnsmasq_caps) < 0)
@@ -1534,6 +1538,7 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr driver,
bool needDnsmasq = false;
virCommandPtr cmd = NULL;
char *pidfile = NULL;
+ pid_t dnsmasqPid;
int ret = -1;
dnsmasqContext *dctx = NULL;
@@ -1602,9 +1607,10 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr driver,
* pid
*/
- ret = virPidFileRead(driver->pidDir, obj->def->name,
&obj->dnsmasqPid);
+ ret = virPidFileRead(driver->pidDir, obj->def->name, &dnsmasqPid);
if (ret < 0)
goto cleanup;
+ virNetworkObjSetDnsmasqPid(obj, dnsmasqPid);
ret = 0;
cleanup:
@@ -1628,6 +1634,7 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr driver,
{
int ret = -1;
size_t i;
+ pid_t dnsmasqPid;
virNetworkIPDefPtr ipdef, ipv4def, ipv6def;
dnsmasqContext *dctx = NULL;
@@ -1636,7 +1643,8 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr driver,
return 0;
/* if there's no running dnsmasq, just start it */
- if (obj->dnsmasqPid <= 0 || (kill(obj->dnsmasqPid, 0) < 0))
+ dnsmasqPid = virNetworkObjGetDnsmasqPid(obj);
+ if (dnsmasqPid <= 0 || (kill(dnsmasqPid, 0) < 0))
return networkStartDhcpDaemon(driver, obj);
VIR_INFO("Refreshing dnsmasq for network %s", obj->def->bridge);
@@ -1677,7 +1685,8 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr driver,
if ((ret = dnsmasqSave(dctx)) < 0)
goto cleanup;
- ret = kill(obj->dnsmasqPid, SIGHUP);
+ dnsmasqPid = virNetworkObjGetDnsmasqPid(obj);
+ ret = kill(dnsmasqPid, SIGHUP);
cleanup:
dnsmasqContextFree(dctx);
return ret;
@@ -1695,10 +1704,12 @@ static int
networkRestartDhcpDaemon(virNetworkDriverStatePtr driver,
virNetworkObjPtr obj)
{
+ pid_t dnsmasqPid = virNetworkObjGetDnsmasqPid(obj);
+
/* if there is a running dnsmasq, kill it */
- if (obj->dnsmasqPid > 0) {
- networkKillDaemon(obj->dnsmasqPid, "dnsmasq",
obj->def->name);
- obj->dnsmasqPid = -1;
+ if (dnsmasqPid > 0) {
+ networkKillDaemon(dnsmasqPid, "dnsmasq", obj->def->name);
+ virNetworkObjSetDnsmasqPid(obj, -1);
}
/* now start dnsmasq if it should be started */
return networkStartDhcpDaemon(driver, obj);
@@ -1838,13 +1849,14 @@ networkStartRadvd(virNetworkDriverStatePtr driver,
virNetworkObjPtr obj)
{
dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
+ pid_t radvdPid;
char *pidfile = NULL;
char *radvdpidbase = NULL;
char *configfile = NULL;
virCommandPtr cmd = NULL;
int ret = -1;
- obj->radvdPid = -1;
+ virNetworkObjSetRadvdPid(obj, -1);
/* Is dnsmasq handling RA? */
if (DNSMASQ_RA_SUPPORT(dnsmasq_caps)) {
@@ -1908,8 +1920,9 @@ networkStartRadvd(virNetworkDriverStatePtr driver,
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
- if (virPidFileRead(driver->pidDir, radvdpidbase, &obj->radvdPid) < 0)
+ if (virPidFileRead(driver->pidDir, radvdpidbase, &radvdPid) < 0)
goto cleanup;
+ virNetworkObjSetRadvdPid(obj, radvdPid);
ret = 0;
cleanup:
@@ -1928,26 +1941,29 @@ networkRefreshRadvd(virNetworkDriverStatePtr driver,
{
dnsmasqCapsPtr dnsmasq_caps = networkGetDnsmasqCaps(driver);
char *radvdpidbase;
+ pid_t radvdPid;
/* Is dnsmasq handling RA? */
if (DNSMASQ_RA_SUPPORT(dnsmasq_caps)) {
virObjectUnref(dnsmasq_caps);
- if (obj->radvdPid <= 0)
+ radvdPid = virNetworkObjGetRadvdPid(obj);
+ if (radvdPid <= 0)
return 0;
/* radvd should not be running but in case it is */
- if ((networkKillDaemon(obj->radvdPid, "radvd", obj->def->name)
>= 0) &&
+ if ((networkKillDaemon(radvdPid, "radvd", obj->def->name) >=
0) &&
((radvdpidbase = networkRadvdPidfileBasename(obj->def->name))
!= NULL)) {
virPidFileDelete(driver->pidDir, radvdpidbase);
VIR_FREE(radvdpidbase);
}
- obj->radvdPid = -1;
+ virNetworkObjSetRadvdPid(obj, -1);
return 0;
}
virObjectUnref(dnsmasq_caps);
/* if there's no running radvd, just start it */
- if (obj->radvdPid <= 0 || (kill(obj->radvdPid, 0) < 0))
+ radvdPid = virNetworkObjGetRadvdPid(obj);
+ if (radvdPid <= 0 || (kill(radvdPid, 0) < 0))
return networkStartRadvd(driver, obj);
if (!virNetworkDefGetIPByIndex(obj->def, AF_INET6, 0)) {
@@ -1958,7 +1974,7 @@ networkRefreshRadvd(virNetworkDriverStatePtr driver,
if (networkRadvdConfWrite(driver, obj, NULL) < 0)
return -1;
- return kill(obj->radvdPid, SIGHUP);
+ return kill(radvdPid, SIGHUP);
}
@@ -1968,21 +1984,22 @@ static int
networkRestartRadvd(virNetworkObjPtr obj)
{
char *radvdpidbase;
+ pid_t radvdPid = virNeworkObjGetRadvdPid(obj);
/* if there is a running radvd, kill it */
- if (obj->radvdPid > 0) {
+ if (radvdPid > 0) {
/* essentially ignore errors from the following two functions,
* since there's really no better recovery to be done than to
* just push ahead (and that may be exactly what's needed).
*/
- if ((networkKillDaemon(obj->radvdPid, "radvd",
+ if ((networkKillDaemon(radvdPid, "radvd",
obj->def->name) >= 0) &&
((radvdpidbase = networkRadvdPidfileBasename(obj->def->name))
!= NULL)) {
virPidFileDelete(driver->pidDir, radvdpidbase);
VIR_FREE(radvdpidbase);
}
- obj->radvdPid = -1;
+ virNetworkObjSetRadvdPid(obj, -1);
}
/* now start radvd if it should be started */
return networkStartRadvd(obj);
@@ -2266,6 +2283,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
virMacMapPtr macmap;
char *macMapFile = NULL;
int tapfd = -1;
+ pid_t dnsmasqPid;
/* Check to see if any network IP collides with an existing route */
if (networkCheckRouteCollision(obj->def) < 0)
@@ -2433,9 +2451,10 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
if (!save_err)
save_err = virSaveLastError();
- if (obj->dnsmasqPid > 0) {
- kill(obj->dnsmasqPid, SIGTERM);
- obj->dnsmasqPid = -1;
+ dnsmasqPid = virNetworkObjGetDnsmasqPid(obj);
+ if (dnsmasqPid > 0) {
+ kill(dnsmasqPid, SIGTERM);
+ virNetworkObjSetDnsmasqPid(obj, -1);
}
err3:
@@ -2478,15 +2497,19 @@ static int
networkShutdownNetworkVirtual(virNetworkDriverStatePtr driver,
virNetworkObjPtr obj)
{
+ pid_t radvdPid;
+ pid_t dnsmasqPid;
+
if (obj->def->bandwidth)
virNetDevBandwidthClear(obj->def->bridge);
virNetworkObjUnrefMacMap(obj);
- if (obj->radvdPid > 0) {
+ radvdPid = virNetworkObjGetRadvdPid(obj);
+ if (radvdPid > 0) {
char *radvdpidbase;
- kill(obj->radvdPid, SIGTERM);
+ kill(radvdPid, SIGTERM);
/* attempt to delete the pidfile we created */
if ((radvdpidbase = networkRadvdPidfileBasename(obj->def->name))) {
virPidFileDelete(driver->pidDir, radvdpidbase);
@@ -2494,8 +2517,9 @@ networkShutdownNetworkVirtual(virNetworkDriverStatePtr driver,
}
}
- if (obj->dnsmasqPid > 0)
- kill(obj->dnsmasqPid, SIGTERM);
+ dnsmasqPid = virNetworkObjGetDnsmasqPid(obj);
+ if (dnsmasqPid > 0)
+ kill(dnsmasqPid, SIGTERM);
if (obj->def->mac_specified) {
char *macTapIfName = networkBridgeDummyNicName(obj->def->bridge);
@@ -2513,15 +2537,17 @@ networkShutdownNetworkVirtual(virNetworkDriverStatePtr driver,
ignore_value(virNetDevBridgeDelete(obj->def->bridge));
/* See if its still alive and really really kill it */
- if (obj->dnsmasqPid > 0 &&
- (kill(obj->dnsmasqPid, 0) == 0))
- kill(obj->dnsmasqPid, SIGKILL);
- obj->dnsmasqPid = -1;
-
- if (obj->radvdPid > 0 &&
- (kill(obj->radvdPid, 0) == 0))
- kill(obj->radvdPid, SIGKILL);
- obj->radvdPid = -1;
+ dnsmasqPid = virNetworkObjGetDnsmasqPid(obj);
+ if (dnsmasqPid > 0 &&
+ (kill(dnsmasqPid, 0) == 0))
+ kill(dnsmasqPid, SIGKILL);
+ virNetworkObjSetDnsmasqPid(obj, -1);
+
+ radvdPid = virNetworkObjGetRadvdPid(obj);
+ if (radvdPid > 0 &&
+ (kill(radvdPid, 0) == 0))
+ kill(radvdPid, SIGKILL);
+ virNetworkObjSetRadvdPid(obj, -1);
return 0;
}
--
2.9.3