Added: - Methods to handle metadata change events. Signed-off-by: K Shiva <shiva_kr@xxxxxxxxxx> --- po/POTFILES | 1 + src/conf/network_event.c | 115 +++++++++++++++++++++++++++++++++++++++ src/conf/network_event.h | 11 ++++ 3 files changed, 127 insertions(+) diff --git a/po/POTFILES b/po/POTFILES index 5d6ec195b4..933a2e07a4 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -39,6 +39,7 @@ src/conf/netdev_bandwidth_conf.c src/conf/netdev_vlan_conf.c src/conf/netdev_vport_profile_conf.c src/conf/network_conf.c +src/conf/network_event.c src/conf/networkcommon_conf.c src/conf/node_device_conf.c src/conf/node_device_util.c diff --git a/src/conf/network_event.c b/src/conf/network_event.c index 6f25e43711..0e12cc2687 100644 --- a/src/conf/network_event.c +++ b/src/conf/network_event.c @@ -26,6 +26,9 @@ #include "object_event_private.h" #include "datatypes.h" #include "virlog.h" +#include "virerror.h" + +#define VIR_FROM_THIS VIR_FROM_NETWORK VIR_LOG_INIT("conf.network_event"); @@ -45,10 +48,21 @@ struct _virNetworkEventLifecycle { }; typedef struct _virNetworkEventLifecycle virNetworkEventLifecycle; +struct _virNetworkEventMetadataChange { + virNetworkEvent parent; + + int type; + char *nsuri; +}; +typedef struct _virNetworkEventMetadataChange virNetworkEventMetadataChange; + static virClass *virNetworkEventClass; static virClass *virNetworkEventLifecycleClass; +static virClass *virNetworkEventMetadataChangeClass; + static void virNetworkEventDispose(void *obj); static void virNetworkEventLifecycleDispose(void *obj); +static void virNetworkEventMetadataChangeDispose(void *obj); static int virNetworkEventsOnceInit(void) @@ -59,6 +73,9 @@ virNetworkEventsOnceInit(void) if (!VIR_CLASS_NEW(virNetworkEventLifecycle, virNetworkEventClass)) return -1; + if (!VIR_CLASS_NEW(virNetworkEventMetadataChange, virNetworkEventClass)) + return -1; + return 0; } @@ -104,9 +121,22 @@ virNetworkEventDispatchDefaultFunc(virConnectPtr conn, return; } + case VIR_NETWORK_EVENT_ID_METADATA_CHANGE: + { + virNetworkEventMetadataChange *metadataChangeEvent; + + metadataChangeEvent = (virNetworkEventMetadataChange *)event; + ((virConnectNetworkEventMetadataChangeCallback)cb)(conn, net, + metadataChangeEvent->type, + metadataChangeEvent->nsuri, + cbopaque); + return; + } + case VIR_NETWORK_EVENT_ID_LAST: break; } + VIR_WARN("Unexpected event ID %d", event->eventID); } @@ -231,3 +261,88 @@ virNetworkEventLifecycleNew(const char *name, return (virObjectEvent *)event; } + + +static void * +virNetworkEventNew(virClass *klass, + int eventID, + const char *name, + const unsigned char *uuid) +{ + virNetworkEvent *event; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + if (virNetworkEventsInitialize() < 0) + return NULL; + + if (!virClassIsDerivedFrom(klass, virNetworkEventClass)) { + virReportInvalidArg(klass, + _("Class %1$s must derive from virNetworkEvent"), + virClassName(klass)); + return NULL; + } + + /* We use uuid for matching key. We ignore 'name' because + * Xen sometimes renames guests during migration, thus + * 'uuid' is the only truly reliable key we can use. */ + virUUIDFormat(uuid, uuidstr); + if (!(event = virObjectEventNew(klass, + virNetworkEventDispatchDefaultFunc, + eventID, + 0, name, uuid, uuidstr))) + return NULL; + + return (virObjectEvent *)event; +} + + +static void +virNetworkEventMetadataChangeDispose(void *obj) +{ + virNetworkEventMetadataChange *event = obj; + VIR_DEBUG("obj=%p", event); + + g_free(event->nsuri); +} + + +static virObjectEvent * +virNetworkEventMetadataChangeNew(const char *name, + unsigned char *uuid, + int type, + const char *nsuri) +{ + virNetworkEventMetadataChange *ev; + + if (virNetworkEventsInitialize() < 0) + return NULL; + + if (!(ev = virNetworkEventNew(virNetworkEventMetadataChangeClass, + VIR_NETWORK_EVENT_ID_METADATA_CHANGE, + name, uuid))) + return NULL; + + ev->type = type; + if (nsuri) + ev->nsuri = g_strdup(nsuri); + + return (virObjectEvent *)ev; +} + +virObjectEvent * +virNetworkEventMetadataChangeNewFromObj(virNetworkObj *obj, + int type, + const char *nsuri) +{ + return virNetworkEventMetadataChangeNew(obj->def->name, + obj->def->uuid, type, nsuri); +} + +virObjectEvent * +virNetworkEventMetadataChangeNewFromNet(virNetworkPtr net, + int type, + const char *nsuri) +{ + return virNetworkEventMetadataChangeNew(net->name, net->uuid, + type, nsuri); +} diff --git a/src/conf/network_event.h b/src/conf/network_event.h index 4502bfcaef..7c98a6ac92 100644 --- a/src/conf/network_event.h +++ b/src/conf/network_event.h @@ -23,6 +23,7 @@ #include "internal.h" #include "object_event.h" +#include "virnetworkobj.h" int virNetworkEventStateRegisterID(virConnectPtr conn, @@ -53,3 +54,13 @@ virNetworkEventLifecycleNew(const char *name, const unsigned char *uuid, int type, int detail); + +virObjectEvent * +virNetworkEventMetadataChangeNewFromObj(virNetworkObj *obj, + int type, + const char *nsuri); + +virObjectEvent * +virNetworkEventMetadataChangeNewFromNet(virNetworkPtr net, + int type, + const char *nsuri); -- 2.41.0