[PATCH 4/8] Add methods to create Metadata change events

K Shiva Kiran posted 8 patches 10 months, 1 week ago
[PATCH 4/8] Add methods to create Metadata change events
Posted by K Shiva Kiran 10 months, 1 week ago
Adds two new private methods to create metadata change events:
- virNetworkEventMetadataChangeNewFromNet()
- virNetworkEventMetadataChangeNewFromObj()

Signed-off-by: K Shiva Kiran <shiva_kr@riseup.net>
---
 src/conf/network_event.c | 48 ++++++++++++++++++++++++++++++++++++++++
 src/conf/network_event.h | 11 +++++++++
 src/libvirt_private.syms |  2 ++
 3 files changed, 61 insertions(+)

diff --git a/src/conf/network_event.c b/src/conf/network_event.c
index d1b3aa5721..5eb9c3d48f 100644
--- a/src/conf/network_event.c
+++ b/src/conf/network_event.c
@@ -267,3 +267,51 @@ virNetworkEventMetadataChangeDispose(void *obj)
 
     g_free(event->nsuri);
 }
+
+
+static virObjectEvent *
+virNetworkEventMetadataChangeNew(const char *name,
+                                 unsigned char *uuid,
+                                 int type,
+                                 const char *nsuri)
+{
+    virNetworkEventMetadataChange *event;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    if (virNetworkEventsInitialize() < 0)
+        return NULL;
+
+    virUUIDFormat(uuid, uuidstr);
+    if (!(event = virObjectEventNew(virNetworkEventMetadataChangeClass,
+                                    virNetworkEventDispatchDefaultFunc,
+                                    VIR_NETWORK_EVENT_ID_METADATA_CHANGE,
+                                    0, name, uuid, uuidstr)))
+        return NULL;
+
+    event->type = type;
+    if (nsuri)
+        event->nsuri = g_strdup(nsuri);
+
+    return (virObjectEvent *)event;
+}
+
+
+virObjectEvent *
+virNetworkEventMetadataChangeNewFromObj(virNetworkObj *obj,
+                                        int type,
+                                        const char *nsuri)
+{
+    virNetworkDef *def = virNetworkObjGetDef(obj);
+    return virNetworkEventMetadataChangeNew(def->name, 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..a91a238fed 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);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1e3e407097..7a59828af0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -861,6 +861,8 @@ virPortGroupFindByName;
 
 # conf/network_event.h
 virNetworkEventLifecycleNew;
+virNetworkEventMetadataChangeNewFromNet;
+virNetworkEventMetadataChangeNewFromObj;
 virNetworkEventStateRegisterID;
 
 
-- 
2.42.0
Re: [PATCH 4/8] Add methods to create Metadata change events
Posted by Michal Prívozník 9 months, 4 weeks ago
On 9/3/23 16:58, K Shiva Kiran wrote:
> Adds two new private methods to create metadata change events:
> - virNetworkEventMetadataChangeNewFromNet()
> - virNetworkEventMetadataChangeNewFromObj()
> 
> Signed-off-by: K Shiva Kiran <shiva_kr@riseup.net>
> ---
>  src/conf/network_event.c | 48 ++++++++++++++++++++++++++++++++++++++++
>  src/conf/network_event.h | 11 +++++++++
>  src/libvirt_private.syms |  2 ++
>  3 files changed, 61 insertions(+)
> 
> diff --git a/src/conf/network_event.c b/src/conf/network_event.c
> index d1b3aa5721..5eb9c3d48f 100644
> --- a/src/conf/network_event.c
> +++ b/src/conf/network_event.c
> @@ -267,3 +267,51 @@ virNetworkEventMetadataChangeDispose(void *obj)
>  
>      g_free(event->nsuri);
>  }
> +
> +
> +static virObjectEvent *
> +virNetworkEventMetadataChangeNew(const char *name,
> +                                 unsigned char *uuid,
> +                                 int type,
> +                                 const char *nsuri)
> +{
> +    virNetworkEventMetadataChange *event;
> +    char uuidstr[VIR_UUID_STRING_BUFLEN];
> +
> +    if (virNetworkEventsInitialize() < 0)
> +        return NULL;
> +
> +    virUUIDFormat(uuid, uuidstr);
> +    if (!(event = virObjectEventNew(virNetworkEventMetadataChangeClass,
> +                                    virNetworkEventDispatchDefaultFunc,
> +                                    VIR_NETWORK_EVENT_ID_METADATA_CHANGE,
> +                                    0, name, uuid, uuidstr)))
> +        return NULL;
> +
> +    event->type = type;
> +    if (nsuri)
> +        event->nsuri = g_strdup(nsuri);

This check if effectively a dead code. The first thing g_strdup() does
is check for NULL. There are a few places in our code where this pattern
occurs, I'll be sending a patch that fixes them.

> +
> +    return (virObjectEvent *)event;
> +}
> +

Michal