From nobody Thu May 2 14:34:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554451069811324.3189934846613; Fri, 5 Apr 2019 00:57:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36FA930024AD; Fri, 5 Apr 2019 07:57:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3D9A1001DF9; Fri, 5 Apr 2019 07:57:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C408C41F3D; Fri, 5 Apr 2019 07:57:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x357vigs002769 for ; Fri, 5 Apr 2019 03:57:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8DDEF605CF; Fri, 5 Apr 2019 07:57:44 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E45E4605AF for ; Fri, 5 Apr 2019 07:57:43 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 09:57:36 +0200 Message-Id: <479f19fd3a1b97d6c2ebef85e140f31e19b1a8d9.1554450927.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] qemuDomainAttachDeviceLive: Rework event emitting X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 05 Apr 2019 07:57:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Some devices that we want to emit event for do not have an alias. Rework event emitting to make code more generic. Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7e5bbc3cc9..6eabcfce18 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7838,15 +7838,15 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev, virQEMUDriverPtr driver) { + virObjectEventPtr event =3D NULL; int ret =3D -1; - const char *alias =3D NULL; =20 switch ((virDomainDeviceType)dev->type) { case VIR_DOMAIN_DEVICE_DISK: qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL); ret =3D qemuDomainAttachDeviceDiskLive(driver, vm, dev); if (!ret) { - alias =3D dev->data.disk->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.di= sk->info.alias); dev->data.disk =3D NULL; } break; @@ -7854,7 +7854,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_CONTROLLER: ret =3D qemuDomainAttachControllerDevice(driver, vm, dev->data.con= troller); if (!ret) { - alias =3D dev->data.controller->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.co= ntroller->info.alias); dev->data.controller =3D NULL; } break; @@ -7870,7 +7870,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, qemuDomainObjCheckNetTaint(driver, vm, dev->data.net, NULL); ret =3D qemuDomainAttachNetDevice(driver, vm, dev->data.net); if (!ret) { - alias =3D dev->data.net->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.ne= t->info.alias); dev->data.net =3D NULL; } break; @@ -7880,7 +7880,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainAttachHostDevice(driver, vm, dev->data.hostdev); if (!ret) { - alias =3D dev->data.hostdev->info->alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.ho= stdev->info->alias); dev->data.hostdev =3D NULL; } break; @@ -7889,7 +7889,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainAttachRedirdevDevice(driver, vm, dev->data.redirdev); if (!ret) { - alias =3D dev->data.redirdev->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.re= dirdev->info.alias); dev->data.redirdev =3D NULL; } break; @@ -7898,7 +7898,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainAttachChrDevice(driver, vm, dev->data.chr); if (!ret) { - alias =3D dev->data.chr->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.ch= r->info.alias); dev->data.chr =3D NULL; } break; @@ -7907,7 +7907,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainAttachRNGDevice(driver, vm, dev->data.rng); if (!ret) { - alias =3D dev->data.rng->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.rn= g->info.alias); dev->data.rng =3D NULL; } break; @@ -7924,7 +7924,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainAttachShmemDevice(driver, vm, dev->data.shmem); if (!ret) { - alias =3D dev->data.shmem->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.sh= mem->info.alias); dev->data.shmem =3D NULL; } break; @@ -7933,7 +7933,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, ret =3D qemuDomainAttachWatchdog(driver, vm, dev->data.watchdog); if (!ret) { - alias =3D dev->data.watchdog->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.wa= tchdog->info.alias); dev->data.watchdog =3D NULL; } break; @@ -7941,7 +7941,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_INPUT: ret =3D qemuDomainAttachInputDevice(driver, vm, dev->data.input); if (ret =3D=3D 0) { - alias =3D dev->data.input->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.in= put->info.alias); dev->data.input =3D NULL; } break; @@ -7949,7 +7949,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_VSOCK: ret =3D qemuDomainAttachVsockDevice(driver, vm, dev->data.vsock); if (ret =3D=3D 0) { - alias =3D dev->data.vsock->info.alias; + event =3D virDomainEventDeviceAddedNewFromObj(vm, dev->data.vs= ock->info.alias); dev->data.vsock =3D NULL; } break; @@ -7973,14 +7973,10 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, break; } =20 - if (alias) { - /* queue the event before the alias has a chance to get freed - * if the domain disappears while qemuDomainUpdateDeviceList - * is in monitor */ - virObjectEventPtr event; - event =3D virDomainEventDeviceAddedNewFromObj(vm, alias); - virObjectEventStateQueue(driver->domainEventState, event); - } + /* queue the event before the alias has a chance to get freed + * if the domain disappears while qemuDomainUpdateDeviceList + * is in monitor */ + virObjectEventStateQueue(driver->domainEventState, event); =20 if (ret =3D=3D 0) ret =3D qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE= ); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 14:34:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554451077787826.0078685220617; Fri, 5 Apr 2019 00:57:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B4125D672; Fri, 5 Apr 2019 07:57:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 675C95DA24; Fri, 5 Apr 2019 07:57:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 24BC1181AC46; Fri, 5 Apr 2019 07:57:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x357vjqs002780 for ; Fri, 5 Apr 2019 03:57:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 858EA60637; Fri, 5 Apr 2019 07:57:45 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB235605AF for ; Fri, 5 Apr 2019 07:57:44 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 09:57:37 +0200 Message-Id: <6ce089f97417213b256a3aa0d14b5a34741a0614.1554450927.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] Introduce VIR_DOMAIN_EVENT_ID_LEASE_CHANGE X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 05 Apr 2019 07:57:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1639228 This event will be emitted whenever a lease is attached or detached. Signed-off-by: Michal Privoznik --- examples/object-events/event-test.c | 34 +++++++++++ include/libvirt/libvirt-domain.h | 33 +++++++++++ src/conf/domain_event.c | 89 +++++++++++++++++++++++++++++ src/conf/domain_event.h | 12 ++++ src/libvirt_private.syms | 2 + src/remote/remote_daemon_dispatch.c | 40 +++++++++++++ src/remote/remote_driver.c | 32 +++++++++++ src/remote/remote_protocol.x | 16 +++++- src/remote_protocol-structs | 8 +++ tools/virsh-domain.c | 31 ++++++++++ 10 files changed, 296 insertions(+), 1 deletion(-) diff --git a/examples/object-events/event-test.c b/examples/object-events/e= vent-test.c index fcf4492470..e9775d7450 100644 --- a/examples/object-events/event-test.c +++ b/examples/object-events/event-test.c @@ -957,6 +957,39 @@ myDomainEventBlockThresholdCallback(virConnectPtr conn= ATTRIBUTE_UNUSED, } =20 =20 +static const char * +leaseActionTypeToStr(int action) +{ + switch ((virConnectDomainEventLeaseAction) action) { + case VIR_CONNECT_DOMAIN_EVENT_LEASE_ACTION_ATTACH: + return "attach"; + + case VIR_CONNECT_DOMAIN_EVENT_LEASE_ACTION_DETACH: + return "detach"; + + case VIR_CONNECT_DOMAIN_EVENT_LEASE_ACTION_LAST: + break; + } + + return "unknown"; +} + + +static int +myDomainEventLeaseChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + int action, + const char *lockspace, + const char *key, + void *opaque ATTRIBUTE_UNUSED) +{ + printf("%s EVENT domain %s(%d) lease change: action %s lockspace %s ke= y %s", + __func__, virDomainGetName(dom), virDomainGetID(dom), + leaseActionTypeToStr(action), lockspace, key); + return 0; +} + + static int myDomainEventMigrationIterationCallback(virConnectPtr conn ATTRIBUTE_UNUSE= D, virDomainPtr dom, @@ -1087,6 +1120,7 @@ struct domainEventData domainEvents[] =3D { DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED, myDomainEventD= eviceRemovalFailedCallback), DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_METADATA_CHANGE, myDomainEventMetadat= aChangeCallback), DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD, myDomainEventBlockTh= resholdCallback), + DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_LEASE_CHANGE, myDomainEventLeaseChang= eCallback), }; =20 struct storagePoolEventData { diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 7d36820b5a..8a68b84135 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -4473,6 +4473,38 @@ typedef void (*virConnectDomainEventBlockThresholdCa= llback)(virConnectPtr conn, unsigned long = long excess, void *opaque); =20 + +typedef enum { + VIR_CONNECT_DOMAIN_EVENT_LEASE_ACTION_ATTACH =3D 1, /* lease attached = */ + VIR_CONNECT_DOMAIN_EVENT_LEASE_ACTION_DETACH =3D 2, /* lease detached = */ + +# ifdef VIR_ENUM_SENTINELS + VIR_CONNECT_DOMAIN_EVENT_LEASE_ACTION_LAST +# endif +} virConnectDomainEventLeaseAction; + +/** + * virConnectDomainEventLeaseChangeCallback: + * @conn: connection object + * @dom: domain on which the event occurred + * @action: action which occurred, one of virConnectDomainEventLeaseAction + * @lockspace: string identifying within which lockspace @key is held + * @key: unique key + * @opaque: application specified data + * + * The callback occurs on lease attach or detach. + * + * The callback signature to use when registering for an event of type + * VIR_DOMAIN_EVENT_ID_LEASE_CHANGE with virConnectDomainEventRegisterAny() + */ +typedef void (*virConnectDomainEventLeaseChangeCallback)(virConnectPtr con= n, + virDomainPtr dom, + int action, + const char *locks= pace, + const char *key, + void *opaque); + + /** * VIR_DOMAIN_EVENT_CALLBACK: * @@ -4515,6 +4547,7 @@ typedef enum { VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED =3D 22, /* virConnectDomainE= ventDeviceRemovalFailedCallback */ VIR_DOMAIN_EVENT_ID_METADATA_CHANGE =3D 23, /* virConnectDomainEventMe= tadataChangeCallback */ VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD =3D 24, /* virConnectDomainEventBl= ockThresholdCallback */ + VIR_DOMAIN_EVENT_ID_LEASE_CHANGE =3D 25, /* virConnectDomainEventLe= aseChangeCallback */ =20 # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_EVENT_ID_LAST diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index b33589f472..436a0c9eb1 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -59,6 +59,7 @@ static virClassPtr virDomainEventJobCompletedClass; static virClassPtr virDomainEventDeviceRemovalFailedClass; static virClassPtr virDomainEventMetadataChangeClass; static virClassPtr virDomainEventBlockThresholdClass; +static virClassPtr virDomainEventLeaseChangeClass; =20 static void virDomainEventDispose(void *obj); static void virDomainEventLifecycleDispose(void *obj); @@ -81,6 +82,7 @@ static void virDomainEventJobCompletedDispose(void *obj); static void virDomainEventDeviceRemovalFailedDispose(void *obj); static void virDomainEventMetadataChangeDispose(void *obj); static void virDomainEventBlockThresholdDispose(void *obj); +static void virDomainEventLeaseChangeDispose(void *obj); =20 static void virDomainEventDispatchDefaultFunc(virConnectPtr conn, @@ -289,6 +291,17 @@ struct _virDomainEventBlockThreshold { typedef struct _virDomainEventBlockThreshold virDomainEventBlockThreshold; typedef virDomainEventBlockThreshold *virDomainEventBlockThresholdPtr; =20 +struct _virDomainEventLeaseChange { + virDomainEvent parent; + + int action; + + char *lockspace; + char *key; +}; +typedef struct _virDomainEventLeaseChange virDomainEventLeaseChange; +typedef virDomainEventLeaseChange *virDomainEventLeaseChangePtr; + =20 static int virDomainEventsOnceInit(void) @@ -335,6 +348,8 @@ virDomainEventsOnceInit(void) return -1; if (!VIR_CLASS_NEW(virDomainEventBlockThreshold, virDomainEventClass)) return -1; + if (!VIR_CLASS_NEW(virDomainEventLeaseChange, virDomainEventClass)) + return -1; return 0; } =20 @@ -544,6 +559,17 @@ virDomainEventBlockThresholdDispose(void *obj) } =20 =20 +static void +virDomainEventLeaseChangeDispose(void *obj) +{ + virDomainEventLeaseChangePtr event =3D obj; + VIR_DEBUG("obj=3D%p", event); + + VIR_FREE(event->lockspace); + VIR_FREE(event->key); +} + + static void * virDomainEventNew(virClassPtr klass, int eventID, @@ -1672,6 +1698,55 @@ virDomainEventBlockThresholdNewFromDom(virDomainPtr = dom, } =20 =20 +static virObjectEventPtr +virDomainEventLeaseChangeNew(int id, + const char *name, + unsigned char *uuid, + int action, + const char *lockspace, + const char *key) +{ + virDomainEventLeaseChangePtr ev; + + if (virDomainEventsInitialize() < 0) + return NULL; + + if (!(ev =3D virDomainEventNew(virDomainEventLeaseChangeClass, + VIR_DOMAIN_EVENT_ID_LEASE_CHANGE, + id, name, uuid))) + return NULL; + + if (VIR_STRDUP(ev->lockspace, lockspace) < 0 || + VIR_STRDUP(ev->key, key) < 0) { + virObjectUnref(ev); + return NULL; + } + ev->action =3D action; + + return (virObjectEventPtr)ev; +} + +virObjectEventPtr +virDomainEventLeaseChangeNewFromObj(virDomainObjPtr obj, + int action, + const char *lockspace, + const char *key) +{ + return virDomainEventLeaseChangeNew(obj->def->id, obj->def->name, + obj->def->uuid, action, lockspace,= key); +} + +virObjectEventPtr +virDomainEventLeaseChangeNewFromDom(virDomainPtr dom, + int action, + const char *lockspace, + const char *key) +{ + return virDomainEventLeaseChangeNew(dom->id, dom->name, dom->uuid, + action, lockspace, key); +} + + static void virDomainEventDispatchDefaultFunc(virConnectPtr conn, virObjectEventPtr event, @@ -1955,6 +2030,20 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn, cbopaque); goto cleanup; } + + case VIR_DOMAIN_EVENT_ID_LEASE_CHANGE: + { + virDomainEventLeaseChangePtr leaseChangeEvent; + + leaseChangeEvent =3D (virDomainEventLeaseChangePtr)event; + ((virConnectDomainEventLeaseChangeCallback)cb)(conn, dom, + leaseChangeEven= t->action, + leaseChangeEven= t->lockspace, + leaseChangeEven= t->key, + cbopaque); + goto cleanup; + } + case VIR_DOMAIN_EVENT_ID_LAST: break; } diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h index 637f1daf68..bcd9c139a2 100644 --- a/src/conf/domain_event.h +++ b/src/conf/domain_event.h @@ -256,6 +256,18 @@ virDomainEventBlockThresholdNewFromDom(virDomainPtr do= m, unsigned long long threshold, unsigned long long excess); =20 +virObjectEventPtr +virDomainEventLeaseChangeNewFromObj(virDomainObjPtr obj, + int action, + const char *lockspace, + const char *key); + +virObjectEventPtr +virDomainEventLeaseChangeNewFromDom(virDomainPtr dom, + int action, + const char *lockspace, + const char *key); + int virDomainEventStateRegister(virConnectPtr conn, virObjectEventStatePtr state, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 212adf53c1..06295b031d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -635,6 +635,8 @@ virDomainEventIOErrorReasonNewFromDom; virDomainEventIOErrorReasonNewFromObj; virDomainEventJobCompletedNewFromDom; virDomainEventJobCompletedNewFromObj; +virDomainEventLeaseChangeNewFromDom; +virDomainEventLeaseChangeNewFromObj; virDomainEventLifecycleNew; virDomainEventLifecycleNewFromDef; virDomainEventLifecycleNewFromDom; diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index df28259042..82a75c73bd 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1449,6 +1449,45 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr c= onn, } =20 =20 +static int +remoteRelayDomainEventLeaseChange(virConnectPtr conn, + virDomainPtr dom, + int action, + const char *lockspace, + const char *key, + void *opaque) +{ + daemonClientEventCallbackPtr callback =3D opaque; + remote_domain_event_lease_change_msg data; + + if (callback->callbackID < 0 || + !remoteRelayDomainEventCheckACL(callback->client, conn, dom)) + return -1; + + VIR_DEBUG("Relaying domain lease change event %s %d %d %s %s, callback= %d", + dom->name, dom->id, action, lockspace, key, callback->callba= ckID); + + memset(&data, 0, sizeof(data)); + data.callbackID =3D callback->callbackID; + if (VIR_STRDUP(data.locspace, lockspace) < 0 || + VIR_STRDUP(data.key, key) < 0) + goto error; + data.action =3D action; + if (make_nonnull_domain(&data.dom, dom) < 0) + goto error; + + remoteDispatchObjectEventSend(callback->client, remoteProgram, + REMOTE_PROC_DOMAIN_EVENT_LEASE_CHANGE, + (xdrproc_t)xdr_remote_domain_event_lease= _change_msg, &data); + return 0; + + error: + xdr_free((xdrproc_t)xdr_remote_domain_event_lease_change_msg, + (char *) &data); + return -1; +} + + static virConnectDomainEventGenericCallback domainEventCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot), @@ -1475,6 +1514,7 @@ static virConnectDomainEventGenericCallback domainEve= ntCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDeviceRemovalFailed), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMetadataChange), VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockThreshold), + VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLeaseChange), }; =20 verify(ARRAY_CARDINALITY(domainEventCallbacks) =3D=3D VIR_DOMAIN_EVENT_ID_= LAST); diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 5c4dd41227..7f6a463f2b 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -418,6 +418,11 @@ remoteDomainBuildEventBlockThreshold(virNetClientProgr= amPtr prog, virNetClientPtr client, void *evdata, void *opaque); =20 +static void +remoteDomainBuildEventLeaseChange(virNetClientProgramPtr prog, + virNetClientPtr client, + void *evdata, void *opaque); + static void remoteConnectNotifyEventConnectionClosed(virNetClientProgramPtr prog ATTRI= BUTE_UNUSED, virNetClientPtr client ATTRIBUTE_= UNUSED, @@ -629,6 +634,10 @@ static virNetClientProgramEvent remoteEvents[] =3D { remoteDomainBuildEventBlockThreshold, sizeof(remote_domain_event_block_threshold_msg), (xdrproc_t)xdr_remote_domain_event_block_threshold_msg }, + { REMOTE_PROC_DOMAIN_EVENT_LEASE_CHANGE, + remoteDomainBuildEventLeaseChange, + sizeof(remote_domain_event_lease_change_msg), + (xdrproc_t)xdr_remote_domain_event_lease_change_msg }, }; =20 static void @@ -5590,6 +5599,29 @@ remoteDomainBuildEventBlockThreshold(virNetClientPro= gramPtr prog ATTRIBUTE_UNUSE } =20 =20 +static void +remoteDomainBuildEventLeaseChange(virNetClientProgramPtr prog ATTRIBUTE_UN= USED, + virNetClientPtr client ATTRIBUTE_UNUSED, + void *evdata, void *opaque) +{ + virConnectPtr conn =3D opaque; + remote_domain_event_lease_change_msg *msg =3D evdata; + struct private_data *priv =3D conn->privateData; + virDomainPtr dom; + virObjectEventPtr event =3D NULL; + + if (!(dom =3D get_nonnull_domain(conn, msg->dom))) + return; + + event =3D virDomainEventLeaseChangeNewFromDom(dom, + msg->action, + msg->locspace, + msg->key); + virObjectUnref(dom); + virObjectEventStateQueueRemote(priv->eventState, event, msg->callbackI= D); +} + + static int remoteStreamSend(virStreamPtr st, const char *data, diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 74be4b37d0..780b2ca9cb 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3573,6 +3573,14 @@ struct remote_connect_get_storage_pool_capabilities_= ret { remote_nonnull_string capabilities; }; =20 +struct remote_domain_event_lease_change_msg { + int callbackID; + remote_nonnull_domain dom; + int action; + remote_nonnull_string locspace; + remote_nonnull_string key; +}; + /*----- Protocol. -----*/ =20 /* Define the program number, protocol version and procedure numbers here.= */ @@ -6342,5 +6350,11 @@ enum remote_procedure { * @generate: both * @acl: connect:read */ - REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403 + REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403, + + /** + * @generate: both + * @acl: none + */ + REMOTE_PROC_DOMAIN_EVENT_LEASE_CHANGE =3D 404 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 768189c573..5aae22bf78 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -2981,6 +2981,13 @@ struct remote_connect_get_storage_pool_capabilities_= args { struct remote_connect_get_storage_pool_capabilities_ret { remote_nonnull_string capabilities; }; +struct remote_domain_event_lease_change_msg { + int callbackID; + remote_nonnull_domain dom; + int action; + remote_nonnull_string locspace; + remote_nonnull_string key; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3385,4 +3392,5 @@ enum remote_procedure { REMOTE_PROC_CONNECT_LIST_ALL_NWFILTER_BINDINGS =3D 401, REMOTE_PROC_DOMAIN_SET_IOTHREAD_PARAMS =3D 402, REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403, + REMOTE_PROC_DOMAIN_EVENT_LEASE_CHANGE =3D 404, }; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e8d5404acf..ced5e62484 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13405,6 +13405,35 @@ virshEventBlockThresholdPrint(virConnectPtr conn A= TTRIBUTE_UNUSED, } =20 =20 +VIR_ENUM_DECL(virshEventLeaseChangeAction); +VIR_ENUM_IMPL(virshEventLeaseChangeAction, + VIR_CONNECT_DOMAIN_EVENT_LEASE_ACTION_LAST, + N_("unknown"), + N_("attach"), + N_("detach")); + + +static void +virshEventLeaseChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom, + int action, + const char *lockspace, + const char *key, + void *opaque) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, + _("event 'lease-change' for domain %s: " + "action: %s lockspace: %s key: %s\n"), + virDomainGetName(dom), + UNKNOWNSTR(virshEventLeaseChangeActionTypeToString(a= ction)), + lockspace, key); + + virshEventPrint(opaque, &buf); +} + + virshDomainEventCallback virshDomainEventCallbacks[] =3D { { "lifecycle", VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), }, @@ -13454,6 +13483,8 @@ virshDomainEventCallback virshDomainEventCallbacks[= ] =3D { VIR_DOMAIN_EVENT_CALLBACK(virshEventMetadataChangePrint), }, { "block-threshold", VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), }, + { "lease-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventLeaseChangePrint), }, }; verify(VIR_DOMAIN_EVENT_ID_LAST =3D=3D ARRAY_CARDINALITY(virshDomainEventC= allbacks)); =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 14:34:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554451079843429.9654736465038; Fri, 5 Apr 2019 00:57:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CE6380F91; Fri, 5 Apr 2019 07:57:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51664614C7; Fri, 5 Apr 2019 07:57:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 06D0A181AC8E; Fri, 5 Apr 2019 07:57:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x357vkfr002785 for ; Fri, 5 Apr 2019 03:57:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5745C605CF; Fri, 5 Apr 2019 07:57:46 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3597605AF for ; Fri, 5 Apr 2019 07:57:45 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 5 Apr 2019 09:57:38 +0200 Message-Id: <56e83472ffdfdc05241332e41d516dbf487c6c1d.1554450927.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] qemu: Emit event on lease attach/detach X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 05 Apr 2019 07:57:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1639228 Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 7 ++++++- src/qemu/qemu_hotplug.c | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6eabcfce18..dad5fff6a8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7862,8 +7862,13 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, case VIR_DOMAIN_DEVICE_LEASE: ret =3D qemuDomainAttachLease(driver, vm, dev->data.lease); - if (ret =3D=3D 0) + if (ret =3D=3D 0) { + event =3D virDomainEventLeaseChangeNewFromObj(vm, + VIR_CONNECT_DOMAIN= _EVENT_LEASE_ACTION_ATTACH, + dev->data.lease->l= ockspace, + dev->data.lease->k= ey); dev->data.lease =3D NULL; + } break; =20 case VIR_DOMAIN_DEVICE_NET: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 34249bd030..10dee24724 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5934,6 +5934,7 @@ qemuDomainDetachDeviceLease(virQEMUDriverPtr driver, virDomainLeaseDefPtr lease) { virDomainLeaseDefPtr det_lease; + virObjectEventPtr event =3D NULL; int idx; =20 if ((idx =3D virDomainLeaseIndex(vm->def, lease)) < 0) { @@ -5946,6 +5947,12 @@ qemuDomainDetachDeviceLease(virQEMUDriverPtr driver, if (virDomainLockLeaseDetach(driver->lockManager, vm, lease) < 0) return -1; =20 + event =3D virDomainEventLeaseChangeNewFromObj(vm, + VIR_CONNECT_DOMAIN_EVENT_L= EASE_ACTION_DETACH, + lease->lockspace, + lease->key); + virObjectEventStateQueue(driver->domainEventState, event); + det_lease =3D virDomainLeaseRemoveAt(vm->def, idx); virDomainLeaseDefFree(det_lease); return 0; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list