---
src/network/bridge_driver.c | 90 ++++++++++++++++++++++++++++++++++++
src/network/bridge_driver_platform.h | 3 ++
2 files changed, 93 insertions(+)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 80c5acb..4c0c352 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -70,6 +70,7 @@
#include "virfile.h"
#include "virstring.h"
#include "viraccessapicheck.h"
+#include "network_event.h"
#define VIR_FROM_THIS VIR_FROM_NETWORK
@@ -438,6 +439,8 @@ networkStateInitialize(bool privileged,
networkReloadFirewallRules(driverState);
networkRefreshDaemons(driverState);
+ driverState->networkEventState = virObjectEventStateNew();
+
networkDriverUnlock(driverState);
#ifdef HAVE_FIREWALLD
@@ -532,6 +535,8 @@ networkStateCleanup(void) {
networkDriverLock(driverState);
+ virObjectEventStateFree(driverState->networkEventState);
+
/* free inactive networks */
virNetworkObjListFree(&driverState->networks);
@@ -2290,6 +2295,55 @@ cleanup:
return ret;
}
+static int
+networkConnectNetworkEventRegisterAny(virConnectPtr conn,
+ virNetworkPtr net,
+ int eventID,
+ virConnectNetworkEventGenericCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
+{
+ virNetworkDriverStatePtr driver = conn->networkPrivateData;
+ int ret = -1;
+
+ networkDriverLock(driver);
+
+ if (virConnectNetworkEventRegisterAnyEnsureACL(conn) < 0)
+ goto cleanup;
+
+ if (virNetworkEventStateRegisterID(conn, driver->networkEventState,
+ net, eventID,
+ VIR_OBJECT_EVENT_CALLBACK(callback),
+ opaque, freecb, &ret) < 0)
+ ret = -1;
+
+ networkDriverUnlock(driver);
+
+cleanup:
+ return ret;
+}
+
+static int
+networkConnectNetworkEventDeregisterAny(virConnectPtr conn,
+ int callbackID)
+{
+ virNetworkDriverStatePtr driver = conn->networkPrivateData;
+ int ret = -1;
+
+ if (virConnectNetworkEventDeregisterAnyEnsureACL(conn) < 0)
+ goto cleanup;
+
+
+ networkDriverLock(driver);
+ ret = virObjectEventStateDeregisterID(conn,
+ driver->networkEventState,
+ callbackID);
+ networkDriverUnlock(driver);
+
+cleanup:
+ return ret;
+}
+
static int networkIsActive(virNetworkPtr net)
{
virNetworkObjPtr obj;
@@ -2483,6 +2537,7 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const char
*xml) {
virNetworkDefPtr def;
virNetworkObjPtr network = NULL;
virNetworkPtr ret = NULL;
+ virObjectEventPtr event = NULL;
networkDriverLock(driver);
@@ -2509,11 +2564,17 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, const
char *xml) {
goto cleanup;
}
+ event = virNetworkEventLifecycleNew(network->def->name,
+ network->def->uuid,
+ VIR_NETWORK_EVENT_STARTED);
+
VIR_INFO("Creating network '%s'", network->def->name);
ret = virGetNetwork(conn, network->def->name, network->def->uuid);
cleanup:
virNetworkDefFree(def);
+ if (event)
+ virObjectEventStateQueue(driver->networkEventState, event);
if (network)
virNetworkObjUnlock(network);
networkDriverUnlock(driver);
@@ -2526,6 +2587,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const char
*xml) {
bool freeDef = true;
virNetworkObjPtr network = NULL;
virNetworkPtr ret = NULL;
+ virObjectEventPtr event = NULL;
networkDriverLock(driver);
@@ -2565,10 +2627,15 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, const
char *xml) {
goto cleanup;
}
+ event = virNetworkEventLifecycleNew(def->name, def->uuid,
+ VIR_NETWORK_EVENT_DEFINED);
+
VIR_INFO("Defining network '%s'", def->name);
ret = virGetNetwork(conn, def->name, def->uuid);
cleanup:
+ if (event)
+ virObjectEventStateQueue(driver->networkEventState, event);
if (freeDef)
virNetworkDefFree(def);
if (network)
@@ -2583,6 +2650,7 @@ networkUndefine(virNetworkPtr net) {
virNetworkObjPtr network;
int ret = -1;
bool active = false;
+ virObjectEventPtr event = NULL;
networkDriverLock(driver);
@@ -2610,6 +2678,10 @@ networkUndefine(virNetworkPtr net) {
virNetworkDefFree(network->newDef);
network->newDef = NULL;
+ event = virNetworkEventLifecycleNew(network->def->name,
+ network->def->uuid,
+ VIR_NETWORK_EVENT_UNDEFINED);
+
VIR_INFO("Undefining network '%s'", network->def->name);
if (!active) {
if (networkRemoveInactive(driver, network) < 0) {
@@ -2622,6 +2694,8 @@ networkUndefine(virNetworkPtr net) {
ret = 0;
cleanup:
+ if (event)
+ virObjectEventStateQueue(driver->networkEventState, event);
if (network)
virNetworkObjUnlock(network);
networkDriverUnlock(driver);
@@ -2805,6 +2879,7 @@ static int networkCreate(virNetworkPtr net) {
virNetworkDriverStatePtr driver = net->conn->networkPrivateData;
virNetworkObjPtr network;
int ret = -1;
+ virObjectEventPtr event = NULL;
networkDriverLock(driver);
network = virNetworkFindByUUID(&driver->networks, net->uuid);
@@ -2820,7 +2895,13 @@ static int networkCreate(virNetworkPtr net) {
ret = networkStartNetwork(driver, network);
+ event = virNetworkEventLifecycleNew(network->def->name,
+ network->def->uuid,
+ VIR_NETWORK_EVENT_STARTED);
+
cleanup:
+ if (event)
+ virObjectEventStateQueue(driver->networkEventState, event);
if (network)
virNetworkObjUnlock(network);
networkDriverUnlock(driver);
@@ -2831,6 +2912,7 @@ static int networkDestroy(virNetworkPtr net) {
virNetworkDriverStatePtr driver = net->conn->networkPrivateData;
virNetworkObjPtr network;
int ret = -1;
+ virObjectEventPtr event = NULL;
networkDriverLock(driver);
network = virNetworkFindByUUID(&driver->networks, net->uuid);
@@ -2853,6 +2935,10 @@ static int networkDestroy(virNetworkPtr net) {
if ((ret = networkShutdownNetwork(driver, network)) < 0)
goto cleanup;
+ event = virNetworkEventLifecycleNew(network->def->name,
+ network->def->uuid,
+ VIR_NETWORK_EVENT_STOPPED);
+
if (!network->persistent) {
if (networkRemoveInactive(driver, network) < 0) {
network = NULL;
@@ -2863,6 +2949,8 @@ static int networkDestroy(virNetworkPtr net) {
}
cleanup:
+ if (event)
+ virObjectEventStateQueue(driver->networkEventState, event);
if (network)
virNetworkObjUnlock(network);
networkDriverUnlock(driver);
@@ -3021,6 +3109,8 @@ static virNetworkDriver networkDriver = {
.connectNumOfDefinedNetworks = networkConnectNumOfDefinedNetworks, /* 0.2.0 */
.connectListDefinedNetworks = networkConnectListDefinedNetworks, /* 0.2.0 */
.connectListAllNetworks = networkConnectListAllNetworks, /* 0.10.2 */
+ .connectNetworkEventRegisterAny = networkConnectNetworkEventRegisterAny, /* 1.2.1 */
+ .connectNetworkEventDeregisterAny = networkConnectNetworkEventDeregisterAny, /* 1.2.1
*/
.networkLookupByUUID = networkLookupByUUID, /* 0.2.0 */
.networkLookupByName = networkLookupByName, /* 0.2.0 */
.networkCreateXML = networkCreateXML, /* 0.2.0 */
diff --git a/src/network/bridge_driver_platform.h b/src/network/bridge_driver_platform.h
index 289ab79..82d96f6 100644
--- a/src/network/bridge_driver_platform.h
+++ b/src/network/bridge_driver_platform.h
@@ -29,6 +29,7 @@
# include "virthread.h"
# include "virdnsmasq.h"
# include "network_conf.h"
+# include "object_event.h"
/* Main driver state */
struct _virNetworkDriverState {
@@ -43,6 +44,8 @@ struct _virNetworkDriverState {
char *dnsmasqStateDir;
char *radvdStateDir;
dnsmasqCapsPtr dnsmasqCaps;
+
+ virObjectEventStatePtr networkEventState;
};
typedef struct _virNetworkDriverState virNetworkDriverState;
--
1.8.4.4