diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index f604b2695c..550759881a 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -501,9 +501,13 @@ networkUpdateState(virNetworkObj *obj, return -1; } - if (virNetworkObjIsActive(obj)) + if (virNetworkObjIsActive(obj)) { virNetworkObjPortForEach(obj, networkUpdatePort, obj); + if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback) + driver->inhibitCallback(true, driver->inhibitOpaque); + } + /* Try and read dnsmasq pids of both active and inactive networks, just in * case a network became inactive and we need to clean up. */ if (def->ips && (def->nips > 0)) { @@ -617,8 +621,8 @@ static virDrvStateInitResult networkStateInitialize(bool privileged, const char *root, bool monolithic G_GNUC_UNUSED, - virStateInhibitCallback callback G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED) + virStateInhibitCallback callback, + void *opaque) { virNetworkDriverConfig *cfg; bool autostart = true; @@ -640,6 +644,9 @@ networkStateInitialize(bool privileged, goto error; } + network_driver->inhibitCallback = callback; + network_driver->inhibitOpaque = opaque; + network_driver->privileged = privileged; if (!(network_driver->xmlopt = networkDnsmasqCreateXMLConf())) @@ -2419,6 +2426,9 @@ networkStartNetwork(virNetworkDriverState *driver, obj, network_driver->xmlopt) < 0) goto cleanup; + if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback) + driver->inhibitCallback(true, driver->inhibitOpaque); + virNetworkObjSetActive(obj, true); VIR_INFO("Network '%s' started up", def->name); ret = 0; @@ -2492,6 +2502,10 @@ networkShutdownNetwork(virNetworkDriverState *driver, VIR_HOOK_SUBOP_END); virNetworkObjSetActive(obj, false); + + if (g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCallback) + driver->inhibitCallback(false, driver->inhibitOpaque); + virNetworkObjUnsetDefTransient(obj); return ret; } diff --git a/src/network/bridge_driver_conf.h b/src/network/bridge_driver_conf.h index 8f221f391e..1beed01efb 100644 --- a/src/network/bridge_driver_conf.h +++ b/src/network/bridge_driver_conf.h @@ -21,7 +21,7 @@ #pragma once -#include "internal.h" +#include "libvirt_internal.h" #include "virthread.h" #include "virdnsmasq.h" #include "virnetworkobj.h" @@ -49,6 +49,13 @@ typedef struct _virNetworkDriverState virNetworkDriverState; struct _virNetworkDriverState { virMutex lock; + /* Atomic inc/dec only */ + unsigned int nactive; + + /* Immutable pointers. Caller must provide locking */ + virStateInhibitCallback inhibitCallback; + void *inhibitOpaque; + /* Read-only */ bool privileged;