From nobody Wed May 14 10:07:37 2025 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527449180055786.021110106735; Sun, 27 May 2018 12:26:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94000C0050A0; Sun, 27 May 2018 19:26:18 +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 5E15760BA3; Sun, 27 May 2018 19:26:18 +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 E1BF818033F1; Sun, 27 May 2018 19:26:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RJQE7P021819 for ; Sun, 27 May 2018 15:26:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 952151690A; Sun, 27 May 2018 19:26:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C34816910 for ; Sun, 27 May 2018 19:26:10 +0000 (UTC) Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DC5030B9FC7 for ; Sun, 27 May 2018 19:25:59 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id a195-v6so5213287qkg.3 for ; Sun, 27 May 2018 12:25:59 -0700 (PDT) Received: from localhost.localdomain ([186.223.96.215]) by smtp.gmail.com with ESMTPSA id 73-v6sm5901971qkc.96.2018.05.27.12.25.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 May 2018 12:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=BFZkjT+Pm95oNDOdIvtuf9q9ICYUKkHtJxbY7xZvOhs=; b=MVRJIk2e9f9DEXElULY6BIeN2gZiZfGro52Y0xxxpWwR1aM0l2HY/87CxGwbxdYVjm vB2YoS4edciS156GY9KjsGrUZL47E+/cdZX5LeP1PaW5BBypC3B3+JldTxayiYXEy/02 VdM3DgBpOnw6KEOSz4+9XvVD+dv9maNv3gfr0eV1WBfJVn/ovN2SV5WabcIun+ij8B05 JbjJHScxdHrdyc2wOCi1VU2DFlR50qGzI+lR0ooyJOgWYJvdB7v5UcmC3nOF1112zKCY MIlRgiVut503hyDSxpGnYVK6Aibts5b7lim/Vi8VlWBuAVGKhDHR55PURt/YxQh710KE NFng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=BFZkjT+Pm95oNDOdIvtuf9q9ICYUKkHtJxbY7xZvOhs=; b=lIrd9Kz1PO5QRVNHm7DuBlB4ja1pRsfBMOhdGl725bqByd4I+lljhGDP5vDyLHThO5 jumR0/PG/kskeHJaYnqrNJ0C1EfUtbkgBuGQS9MuYx/aI3al3pZpOBE5VbQu4ptM+ebi SV5dQ9vc40HbHhwYIjZW+k9g5VHKYNjL05HppOIBXCJ1i09HdOSgCysJHsLZOmTCCX3l Qy6GvFNQ5xyyVOu5/X6KnpJX+eDLXZWJw0dAZdGyCS3d7dqo0ZFC8qDCfijRMAilZuke 1UbWTvY920IIWIbO4z866ksc/wL4G1JVjwUlEJMjJXlYCBy59/iCgYgevLL3tHiqC2RV zbyg== X-Gm-Message-State: ALKqPwc07lvFc4CDFJUvTvBvyyfxP8oYosugco3ZrIDTum+VHbG5qqga qgK0NWip5O6A+FsARgH1rExLJw== X-Google-Smtp-Source: ADUXVKL/x/Pebgf56j5ilzpvivOXBL0O7LNPv3L1eVWgPTF1uQmWW6RsJm5CtpYu1cRM8T1PAcGZ4g== X-Received: by 2002:a37:9044:: with SMTP id s65-v6mr9220378qkd.73.1527449158026; Sun, 27 May 2018 12:25:58 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 27 May 2018 16:25:37 -0300 Message-Id: <20180527192539.17922-4-jcfaracco@gmail.com> In-Reply-To: <20180527192539.17922-1-jcfaracco@gmail.com> References: <20180527192539.17922-1-jcfaracco@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sun, 27 May 2018 19:25:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sun, 27 May 2018 19:25:59 +0000 (UTC) for IP:'209.85.220.193' DOMAIN:'mail-qk0-f193.google.com' HELO:'mail-qk0-f193.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.220.193 mail-qk0-f193.google.com 209.85.220.193 mail-qk0-f193.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] conf: implementing some functions to generate volume events. 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: , MIME-Version: 1.0 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 27 May 2018 19:26:19 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This commit defines some functions to create new events for volumes according the events available for volumes. Signed-off-by: Julio Faracco --- src/conf/storage_event.c | 155 +++++++++++++++++++++++++++++++++++++++ src/conf/storage_event.h | 19 +++++ src/libvirt_private.syms | 2 + 3 files changed, 176 insertions(+) diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c index 32a12eb63f..8d77b2a6cb 100644 --- a/src/conf/storage_event.c +++ b/src/conf/storage_event.c @@ -56,6 +56,24 @@ struct _virStoragePoolEventRefresh { typedef struct _virStoragePoolEventRefresh virStoragePoolEventRefresh; typedef virStoragePoolEventRefresh *virStoragePoolEventRefreshPtr; =20 +struct _virStorageVolEvent { + virObjectEvent parent; + + /* Unused attribute to allow for subclass creation */ + bool dummy; +}; +typedef struct _virStorageVolEvent virStorageVolEvent; +typedef virStorageVolEvent *virStorageVolEventPtr; + +struct _virStorageVolEventLifecycle { + virStorageVolEvent parent; + + int type; + int detail; +}; +typedef struct _virStorageVolEventLifecycle virStorageVolEventLifecycle; +typedef virStorageVolEventLifecycle *virStorageVolEventLifecyclePtr; + static virClassPtr virStoragePoolEventClass; static virClassPtr virStoragePoolEventLifecycleClass; static virClassPtr virStoragePoolEventRefreshClass; @@ -63,6 +81,11 @@ static void virStoragePoolEventDispose(void *obj); static void virStoragePoolEventLifecycleDispose(void *obj); static void virStoragePoolEventRefreshDispose(void *obj); =20 +static virClassPtr virStorageVolEventClass; +static virClassPtr virStorageVolEventLifecycleClass; +static void virStorageVolEventDispose(void *obj); +static void virStorageVolEventLifecycleDispose(void *obj); + static int virStoragePoolEventsOnceInit(void) { @@ -78,7 +101,20 @@ virStoragePoolEventsOnceInit(void) return 0; } =20 +static int +virStorageVolEventsOnceInit(void) +{ + if (!VIR_CLASS_NEW(virStorageVolEvent, virClassForObjectEvent())) + return -1; + + if (!VIR_CLASS_NEW(virStorageVolEventLifecycle, virStorageVolEventClas= s)) + return -1; + + return 0; +} + VIR_ONCE_GLOBAL_INIT(virStoragePoolEvents) +VIR_ONCE_GLOBAL_INIT(virStorageVolEvents) =20 static void virStoragePoolEventDispose(void *obj) @@ -103,6 +139,20 @@ virStoragePoolEventRefreshDispose(void *obj) VIR_DEBUG("obj=3D%p", event); } =20 +static void +virStorageVolEventDispose(void *obj) +{ + virStorageVolEventPtr event =3D obj; + VIR_DEBUG("obj=3D%p", event); +} + + +static void +virStorageVolEventLifecycleDispose(void *obj) +{ + virStorageVolEventLifecyclePtr event =3D obj; + VIR_DEBUG("obj=3D%p", event); +} =20 static void virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn, @@ -147,6 +197,40 @@ virStoragePoolEventDispatchDefaultFunc(virConnectPtr c= onn, } =20 =20 +static void +virStorageVolEventDispatchDefaultFunc(virConnectPtr conn, + virObjectEventPtr event, + virConnectObjectEventGenericCallback= cb ATTRIBUTE_UNUSED, + void *cbopaque ATTRIBUTE_UNUSED) +{ + virStorageVolPtr vol =3D virStorageVolLookupByKey(conn, + event->meta.key); + if (!vol) + return; + + switch ((virStorageVolEventID)event->eventID) { + case VIR_STORAGE_VOL_EVENT_ID_LIFECYCLE: + { + virStorageVolEventLifecyclePtr storageVolLifecycleEvent; + + storageVolLifecycleEvent =3D (virStorageVolEventLifecyclePtr)e= vent; + ((virConnectStorageVolEventLifecycleCallback)cb)(conn, vol, + storageVolLif= ecycleEvent->type, + storageVolLif= ecycleEvent->detail, + cbopaque); + goto cleanup; + } + + case VIR_STORAGE_VOL_EVENT_ID_LAST: + break; + } + VIR_WARN("Unexpected event ID %d", event->eventID); + + cleanup: + virObjectUnref(vol); +} + + /** * virStoragePoolEventStateRegisterID: * @conn: connection to associate with callback @@ -189,6 +273,44 @@ virStoragePoolEventStateRegisterID(virConnectPtr conn, false, callbackID, false); } =20 +/** + * virStorageVolEventStateRegisterID: + * @conn: connection to associate with callback + * @state: object event state + * @vol: storage vol to filter on or NULL for all storage volumes + * @eventID: ID of the event type to register for + * @cb: function to invoke when event occurs + * @opaque: data blob to pass to @callback + * @freecb: callback to free @opaque + * @callbackID: filled with callback ID + * + * Register the function @cb with connection @conn, from @state, for + * events of type @eventID, and return the registration handle in + * @callbackID. + * + * Returns: the number of callbacks now registered, or -1 on error + */ +int +virStorageVolEventStateRegisterID(virConnectPtr conn, + virObjectEventStatePtr state, + virStorageVolPtr vol, + int eventID, + virConnectStorageVolEventGenericCallback= cb, + void *opaque, + virFreeCallback freecb, + int *callbackID) +{ + if (virStorageVolEventsInitialize() < 0) + return -1; + + return virObjectEventStateRegisterID(conn, state, vol ? vol->key : NUL= L, + NULL, NULL, + virStorageVolEventClass, eventID, + VIR_OBJECT_EVENT_CALLBACK(cb), + opaque, freecb, + false, callbackID, false); +} + =20 /** * virStoragePoolEventStateRegisterClient: @@ -268,6 +390,39 @@ virStoragePoolEventLifecycleNew(const char *name, return (virObjectEventPtr)event; } =20 +/** + * virStorageVolEventLifecycleNew: + * @name: name of the storage volume object the event describes + * @key: key of the storage volume object the event describes + * @type: type of lifecycle event + * @detail: more details about @type + * + * Create a new storage volume lifecycle event. + */ +virObjectEventPtr +virStorageVolEventLifecycleNew(const char *pool, + const char *name, + const unsigned char *key, + int type, + int detail) +{ + virStorageVolEventLifecyclePtr event; + + if (virStorageVolEventsInitialize() < 0) + return NULL; + + if (!(event =3D virObjectEventNew(virStorageVolEventLifecycleClass, + virStorageVolEventDispatchDefaultFunc, + VIR_STORAGE_VOL_EVENT_ID_LIFECYCLE, + 0, name, key, pool))) + return NULL; + + event->type =3D type; + event->detail =3D detail; + + return (virObjectEventPtr)event; +} + =20 /** * virStoragePoolEventRefreshNew: diff --git a/src/conf/storage_event.h b/src/conf/storage_event.h index ea726911fa..59adf622d7 100644 --- a/src/conf/storage_event.h +++ b/src/conf/storage_event.h @@ -39,6 +39,18 @@ virStoragePoolEventStateRegisterID(virConnectPtr conn, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(8); =20 +int +virStorageVolEventStateRegisterID(virConnectPtr conn, + virObjectEventStatePtr state, + virStorageVolPtr vol, + int eventID, + virConnectStorageVolEventGenericCallback= cb, + void *opaque, + virFreeCallback freecb, + int *callbackID) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5) + ATTRIBUTE_NONNULL(8); + int virStoragePoolEventStateRegisterClient(virConnectPtr conn, virObjectEventStatePtr state, @@ -61,4 +73,11 @@ virObjectEventPtr virStoragePoolEventRefreshNew(const char *name, const unsigned char *uuid); =20 +virObjectEventPtr +virStorageVolEventLifecycleNew(const char *pool, + const char *name, + const unsigned char *key, + int type, + int detail); + #endif diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a97b7fe223..4e62a02c02 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -940,6 +940,8 @@ virStorageVolTypeToString; virStoragePoolEventLifecycleNew; virStoragePoolEventRefreshNew; virStoragePoolEventStateRegisterID; +virStorageVolEventLifecycleNew; +virStorageVolEventStateRegisterID; =20 =20 # conf/virchrdev.h --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list