From nobody Wed Feb 5 14:07:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=riseup.net ARC-Seal: i=1; a=rsa-sha256; t=1693753611; cv=none; d=zohomail.com; s=zohoarc; b=FrN5dYVaQl0JEzNWIbvuB+Ael1eupkF4T0y/Eb+gsdx8hZt6zkFmOBRZnFmLzy0unKjaswx/ovuiOnCCf4mMPNOb+uyD+L9f/finjsK7N70tkNJT98vcvNtHCPV/gttYhBkrBZxjNOPfb59opeEpEILkEVqargxcAz+nluvX9Oc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693753611; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9nlPKJ1AvkbZ5aeXXsgfvFFZjkGVwjp7k0L4JM5s5q8=; b=NvjX/9EzuXOnS2SPm8atVBDbdL4OojkSJ5VLLQ0No7ueQckkx08lvYHoOfEgjmOvrLUSZqQ0fdhKCHYDRKpfj1WlNz1kyYT+FG7zS28BI+TN6H9PcUCqqbeC1SIb1bboFp73Oeni83isKygHkisXnvzKGcUvMOF6jzGVjHPbxn8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 16937536118291009.0777679763212; Sun, 3 Sep 2023 08:06:51 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-189-f0Mb-xGjP_GUkYg8KAwQNg-1; Sun, 03 Sep 2023 11:06:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 276DC805BFB; Sun, 3 Sep 2023 15:06:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10DD4200A86A; Sun, 3 Sep 2023 15:06:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CCE7F1946588; Sun, 3 Sep 2023 15:06:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 414261946586 for ; Sun, 3 Sep 2023 15:06:42 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 27CBA493112; Sun, 3 Sep 2023 15:06:42 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2059A493110 for ; Sun, 3 Sep 2023 15:06:42 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5CAD3806714 for ; Sun, 3 Sep 2023 15:06:41 +0000 (UTC) Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-259-8jaBeLsPPV2XZDfRcH-MUg-1; Sun, 03 Sep 2023 11:06:39 -0400 Received: from fews02-sea.riseup.net (fews02-sea-pn.riseup.net [10.0.1.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx1.riseup.net (Postfix) with ESMTPS id 4Rdw8Z1FyyzDr89 for ; Sun, 3 Sep 2023 15:06:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews02-sea.riseup.net (Postfix) with ESMTPSA id 4Rdw8X74zfzFq1y; Sun, 3 Sep 2023 15:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693753610; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9nlPKJ1AvkbZ5aeXXsgfvFFZjkGVwjp7k0L4JM5s5q8=; b=ADzmUf56rdFnVmG+nwbrYGmmLCo0dvZCslYYj6M2HuDsMrLN8SPxXtDYccIEquZ9hwoWkK y65yaIZWqHko0TWTjL7DljorTdbGTCdxiVSpCSTY0C2E/7Iv2n232tTYTu6SzpvYHCZaxQ WHMS/UwHcgdskb6Oj7F4qVYyIyqnlNM= X-MC-Unique: f0Mb-xGjP_GUkYg8KAwQNg-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: 8jaBeLsPPV2XZDfRcH-MUg-1 X-Riseup-User-ID: 2B43F9B51FEB0A952A8726AD2A276786E240FB2D10654902C19B4136BA479A69 From: K Shiva Kiran To: libvir-list@redhat.com Subject: [PATCH 3/8] Add Event ID, Server side dispatcher and virsh print function Date: Sun, 3 Sep 2023 20:28:35 +0530 Message-ID: <20230903150541.200896-4-shiva_kr@riseup.net> In-Reply-To: <20230903150541.200896-1-shiva_kr@riseup.net> References: <20230903150541.200896-1-shiva_kr@riseup.net> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: K Shiva Kiran Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: riseup.net Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693753614075100003 Content-Type: text/plain; charset="utf-8"; x-default="true" 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 --- 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-ne= twork.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 =3D 0, /* virConnectNetworkEventL= ifecycleCallback (Since: 1.2.1) */ + VIR_NETWORK_EVENT_ID_METADATA_CHANGE =3D 1, /* virConnectNetworkEven= tMetadataChangeCallback (Since: 9.8.0) */ =20 # 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; } =20 + case VIR_NETWORK_EVENT_ID_METADATA_CHANGE: + { + virNetworkEventMetadataChange *metadataChangeEvent; + + metadataChangeEvent =3D (virNetworkEventMetadataChange *)event; + ((virConnectNetworkEventMetadataChangeCallback)cb)(conn, net, + metadataCha= ngeEvent->type, + metadataCha= ngeEvent->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; } =20 +static int +remoteRelayNetworkEventMetadataChange(virConnectPtr conn, + virNetworkPtr net, + int type, + const char *nsuri, + void *opaque) +{ + daemonClientEventCallback *callback =3D 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)); + + data.type =3D type; + if (nsuri) { + data.nsuri =3D g_new0(remote_nonnull_string, 1); + *(data.nsuri) =3D g_strdup(nsuri); + } + + make_nonnull_network(&data.net, net); + data.callbackID =3D callback->callbackID; + + remoteDispatchObjectEventSend(callback->client, callback->program, + REMOTE_PROC_NETWORK_EVENT_CALLBACK_METAD= ATA_CHANGE, + (xdrproc_t)xdr_remote_network_event_call= back_metadata_change_msg, + &data); + return 0; +} + + static virConnectNetworkEventGenericCallback networkEventCallbacks[] =3D { VIR_NETWORK_EVENT_CALLBACK(remoteRelayNetworkEventLifecycle), + VIR_NETWORK_EVENT_CALLBACK(remoteRelayNetworkEventMetadataChange), }; =20 G_STATIC_ASSERT(G_N_ELEMENTS(networkEventCallbacks) =3D=3D VIR_NETWORK_EVE= NT_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; }; =20 +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 =3D 445 + REMOTE_PROC_NETWORK_GET_METADATA =3D 445, + + /** + * @generate: both + * @acl: none + */ + REMOTE_PROC_NETWORK_EVENT_CALLBACK_METADATA_CHANGE =3D 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; diff --git a/tools/virsh-network.c b/tools/virsh-network.c index de5d60593a..8965d87c9c 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -1582,7 +1582,8 @@ typedef struct virshNetEventData virshNetEventData; VIR_ENUM_DECL(virshNetworkEventId); VIR_ENUM_IMPL(virshNetworkEventId, VIR_NETWORK_EVENT_ID_LAST, - "lifecycle"); + "lifecycle", + "metadata-change"); =20 static void vshEventLifecyclePrint(virConnectPtr conn G_GNUC_UNUSED, @@ -1615,9 +1616,52 @@ vshEventLifecyclePrint(virConnectPtr conn G_GNUC_UNU= SED, vshEventDone(data->ctl); } =20 +VIR_ENUM_DECL(virshNetworkEventMetadataChangeType); +VIR_ENUM_IMPL(virshNetworkEventMetadataChangeType, + VIR_NETWORK_METADATA_LAST, + N_("description"), + N_("title"), + N_("element")); + +#define UNKNOWNSTR(str) (str ? str : N_("unsupported value")) + +static void +vshEventMetadataChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virNetworkPtr net, + int type, + const char *nsuri, + void *opaque) +{ + virshNetEventData *data =3D opaque; + + if (!data->loop && data->count) + return; + + if (data->timestamp) { + char timestamp[VIR_TIME_STRING_BUFLEN]; + + if (virTimeStringNowRaw(timestamp) < 0) + timestamp[0] =3D '\0'; + + vshPrint(data->ctl, _("%1$s: event 'metadata-change' for network %= 2$s: type %3$s, uri %4$s\n"), + timestamp, virNetworkGetName(net), + UNKNOWNSTR(virshNetworkEventMetadataChangeTypeTypeToStrin= g(type)), NULLSTR(nsuri)); + } else { + vshPrint(data->ctl, _("event 'metadata-change' for network %1$s: t= ype %2$s, uri %3$s\n"), + virNetworkGetName(net), + UNKNOWNSTR(virshNetworkEventMetadataChangeTypeTypeToStrin= g(type)), NULLSTR(nsuri)); + } + + data->count++; + if (!data->loop) + vshEventDone(data->ctl); +} + virshNetworkEventCallback virshNetworkEventCallbacks[] =3D { { "lifecycle", VIR_NETWORK_EVENT_CALLBACK(vshEventLifecyclePrint), }, + { "metadata-change", + VIR_NETWORK_EVENT_CALLBACK(vshEventMetadataChangePrint), }, }; G_STATIC_ASSERT(VIR_NETWORK_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshNetwork= EventCallbacks)); =20 --=20 2.42.0