Re: [PATCH 3/8] Add Event ID, Server side dispatcher and virsh print function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/3/23 16:58, K Shiva Kiran wrote:
> Adds the following for Network Metadata change callback events:
> 
> - New Event ID VIR_NETWORK_EVENT_ID_METADATA_CHANGE
> - Server side dispatcher
> 
> virsh:
> - New event type `metadata-change`
> - vshEventMetadataChangePrint() to display the above defined
>   event type in virsh via `net-event`
> 
> Signed-off-by: K Shiva Kiran <shiva_kr@xxxxxxxxxx>
> ---
> I was unable to split this patch due to static assertions (perfomed
> against VIR_NETWORK_EVENT_ID_LAST) in remote_daemon_dispatch.c and
> virsh-network.c
> Please let me know if there is a way to split patches in such cases.
> 
>  include/libvirt/libvirt-network.h   |  1 +
>  src/conf/network_event.c            | 12 ++++++++
>  src/remote/remote_daemon_dispatch.c | 38 ++++++++++++++++++++++++
>  src/remote/remote_protocol.x        | 15 +++++++++-
>  src/remote_protocol-structs         |  6 ++++
>  tools/virsh-network.c               | 46 ++++++++++++++++++++++++++++-
>  6 files changed, 116 insertions(+), 2 deletions(-)
> 
> diff --git a/include/libvirt/libvirt-network.h b/include/libvirt/libvirt-network.h
> index 4b121ae0e7..58591be7ac 100644
> --- a/include/libvirt/libvirt-network.h
> +++ b/include/libvirt/libvirt-network.h
> @@ -330,6 +330,7 @@ typedef void (*virConnectNetworkEventLifecycleCallback)(virConnectPtr conn,
>   */
>  typedef enum {
>      VIR_NETWORK_EVENT_ID_LIFECYCLE = 0,       /* virConnectNetworkEventLifecycleCallback (Since: 1.2.1) */
> +    VIR_NETWORK_EVENT_ID_METADATA_CHANGE = 1,   /* virConnectNetworkEventMetadataChangeCallback (Since: 9.8.0) */
>  
>  # ifdef VIR_ENUM_SENTINELS
>      VIR_NETWORK_EVENT_ID_LAST
> diff --git a/src/conf/network_event.c b/src/conf/network_event.c
> index 51fa092ffd..d1b3aa5721 100644
> --- a/src/conf/network_event.c
> +++ b/src/conf/network_event.c
> @@ -118,6 +118,18 @@ 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;
>      }
> diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
> index 2bb9e306a4..7daf503b51 100644
> --- a/src/remote/remote_daemon_dispatch.c
> +++ b/src/remote/remote_daemon_dispatch.c
> @@ -1385,8 +1385,46 @@ remoteRelayNetworkEventLifecycle(virConnectPtr conn,
>      return 0;
>  }
>  
> +static int
> +remoteRelayNetworkEventMetadataChange(virConnectPtr conn,
> +                                      virNetworkPtr net,
> +                                      int type,
> +                                      const char *nsuri,
> +                                      void *opaque)
> +{
> +    daemonClientEventCallback *callback = opaque;
> +    remote_network_event_callback_metadata_change_msg data;
> +
> +    if (callback->callbackID < 0 ||
> +        !remoteRelayNetworkEventCheckACL(callback->client, conn, net))
> +        return -1;
> +
> +    VIR_DEBUG("Relaying network metadata change %s %d %s, callback %d",
> +              net->name, type, NULLSTR(nsuri), callback->callbackID);
> +
> +    /* build return data */
> +    memset(&data, 0, sizeof(data));

Declaring the variable with = { 0 } initializer is preferred (see
v9.7.0-rc1~160).	

> +
> +    data.type = type;
> +    if (nsuri) {
> +        data.nsuri = g_new0(remote_nonnull_string, 1);
> +        *(data.nsuri) = g_strdup(nsuri);
> +    }
> +
> +    make_nonnull_network(&data.net, net);
> +    data.callbackID = callback->callbackID;
> +
> +    remoteDispatchObjectEventSend(callback->client, callback->program,
> +                                  REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE,
> +                                  (xdrproc_t)xdr_remote_network_event_callback_metadata_change_msg,
> +                                  &data);
> +    return 0;
> +}
> +
> +
>  static virConnectNetworkEventGenericCallback networkEventCallbacks[] = {
>      VIR_NETWORK_EVENT_CALLBACK(remoteRelayNetworkEventLifecycle),
> +    VIR_NETWORK_EVENT_CALLBACK(remoteRelayNetworkEventMetadataChange),
>  };
>  
>  G_STATIC_ASSERT(G_N_ELEMENTS(networkEventCallbacks) == VIR_NETWORK_EVENT_ID_LAST);
> diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
> index 7ff059e393..e295b0acc3 100644
> --- a/src/remote/remote_protocol.x
> +++ b/src/remote/remote_protocol.x
> @@ -3323,6 +3323,13 @@ struct remote_network_event_lifecycle_msg {
>      int detail;
>  };
>  
> +struct remote_network_event_callback_metadata_change_msg {
> +    int callbackID;
> +    remote_nonnull_network net;
> +    int type;
> +    remote_string nsuri;
> +};
> +
>  struct remote_network_set_metadata_args {
>      remote_nonnull_network network;
>      int type;
> @@ -7008,5 +7015,11 @@ enum remote_procedure {
>       * @generate: both
>       * @acl: network:read
>       */
> -    REMOTE_PROC_NETWORK_GET_METADATA = 445
> +    REMOTE_PROC_NETWORK_GET_METADATA = 445,
> +
> +    /**
> +     * @generate: both
> +     * @acl: none
> +     */
> +    REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE = 446
>  };
> diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
> index c07e0af1e6..e6132bee71 100644
> --- a/src/remote_protocol-structs
> +++ b/src/remote_protocol-structs
> @@ -2687,6 +2687,12 @@ struct remote_network_event_lifecycle_msg {
>          int                        event;
>          int                        detail;
>  };
> +struct remote_network_event_callback_metadata_change_msg {
> +        int                        callbackID;
> +        remote_nonnull_network     net;
> +        int                        type;
> +        remote_string              nsuri;
> +};
>  struct remote_network_set_metadata_args {
>          remote_nonnull_network     network;
>          int                        type;

REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE = 446

is missing

Michal




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux