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 1527449175634912.594077420709; Sun, 27 May 2018 12:26:15 -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 A2F24B6F22; Sun, 27 May 2018 19:26:13 +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 304D35DD6B; Sun, 27 May 2018 19:26:13 +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 DA2E74CA81; Sun, 27 May 2018 19:26:11 +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 w4RJQAsZ021796 for ; Sun, 27 May 2018 15:26:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 42B85A0A64; Sun, 27 May 2018 19:26:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B44760BA3 for ; Sun, 27 May 2018 19:26:06 +0000 (UTC) Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) (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 2718E9FD59 for ; Sun, 27 May 2018 19:25:55 +0000 (UTC) Received: by mail-qt0-f195.google.com with SMTP id q6-v6so12653101qtn.3 for ; Sun, 27 May 2018 12:25:55 -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.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 May 2018 12:25:53 -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=FXevZZ9zMFnvSoMZDqSZ3PJEjW+5lk1Zhk2YngeHREM=; b=ik1xEwHdqGgbn9Hi4Q/TeXbvRJYxtgAXAX3v2OYGFIqRHkAr22cyqnylvES7JurMv8 0dlreMAwCQPO+ih3XTh1PYH8Ua68lnZHLMCI82W8gVVadoJ1BhnCk1G3cMcF1seYvEXt dUOrw/Vae00yVK3MR63IY/AYZBRJjji6RuHBh/g1vBkm9roOTH7vIr+gNRAbKX30f4nr 5XSI7321yFAr6lDLgO0G6rp74pdz9SCIk8zaj3IoZ2nsQYroOpkwqnYgyzr7nI5kQzXl n60/c+aJiDQxKbYF/tGHiBW7ay3POwEbLTLBJ90zaq4lZ+OfZJ+gYJO5ja9JiBAw8OZr pi4g== 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=FXevZZ9zMFnvSoMZDqSZ3PJEjW+5lk1Zhk2YngeHREM=; b=YJw9ZXVGR9sP6DpB9++QyaQNIP6TXN+ndE2TAGLBTqWT0ebglDGg79DXJyc+z38+S5 k3DotR7JEdEOETMU2+2wwMbNehvAvNRG0URqmlIQT6C3egyFUYi8mhZYHA5SlmLAc7fm y96JrMFTh6kHn/4A58DLgYuSSUQVOpCq6HEwxOOy5I5jQ0xFAnhluWL3yRPs8+HYu7oK 5GXvK+lIhHJ5T4MSbZNalIVHh8FQwjdHs8p5GPnnnCmfJWvoOHFfKheaeb3jjFzV0kC9 Ze+6T4gNmI1puDgbCJPtvzbg4ymtgXUaiGxGnrLX3HTQ9oo2QWrBkpX2lsT/N2pbaUNh R7uw== X-Gm-Message-State: ALKqPwdCApLddQxuT2HHAPUgBo9QJ74qQz8pa5oYNDoY0YjuP3Wxcs0I 7ajEDPqFXmwGxHVzodNnLqpgSA== X-Google-Smtp-Source: ADUXVKL9UCHQabZFVwCqY56H5z7AwU8pywjr+DxphNttUJO/6r+YOqwtufZ9Mk4s8L/1P+9Dpi7vxQ== X-Received: by 2002:ac8:c41:: with SMTP id l1-v6mr9900875qti.317.1527449154118; Sun, 27 May 2018 12:25:54 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 27 May 2018 16:25:35 -0300 Message-Id: <20180527192539.17922-2-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.30]); Sun, 27 May 2018 19:25:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 27 May 2018 19:25:55 +0000 (UTC) for IP:'209.85.216.195' DOMAIN:'mail-qt0-f195.google.com' HELO:'mail-qt0-f195.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.216.195 mail-qt0-f195.google.com 209.85.216.195 mail-qt0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] storage: adding a skeleton for libvirt 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 27 May 2018 19:26:14 +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 adds some basic structures to support events for volumes as libvirt does with pools, networks, domains, secrets, etc. This commit add only lifecycle event to be included at create and delete actions. Signed-off-by: Julio Faracco --- include/libvirt/libvirt-storage.h | 86 ++++++++++++++++++++ src/libvirt-storage.c | 125 ++++++++++++++++++++++++++++++ src/libvirt_public.syms | 6 ++ 3 files changed, 217 insertions(+) diff --git a/include/libvirt/libvirt-storage.h b/include/libvirt/libvirt-st= orage.h index 413d9f6c4c..291742e5ef 100644 --- a/include/libvirt/libvirt-storage.h +++ b/include/libvirt/libvirt-storage.h @@ -496,4 +496,90 @@ typedef void (*virConnectStoragePoolEventLifecycleCall= back)(virConnectPtr conn, int detail, void *opaque); =20 +/** + * VIR_STORAGE_VOL_EVENT_CALLBACK: + * + * Used to cast the event specific callback into the generic one + * for use for virConnectStorageVolEventRegisterAny() + */ +# define VIR_STORAGE_VOL_EVENT_CALLBACK(cb)((virConnectStorageVolEventGene= ricCallback)(cb)) + +/** + * virStorageVolEventID: + * + * An enumeration of supported eventId parameters for + * virConnectStorageVolEventRegisterAny(). Each event id determines which + * signature of callback function will be used. + */ +typedef enum { + VIR_STORAGE_VOL_EVENT_ID_LIFECYCLE =3D 0, /* virConnectStorageVolEvent= LifecycleCallback */ + +# ifdef VIR_ENUM_SENTINELS + VIR_STORAGE_VOL_EVENT_ID_LAST +# endif +} virStorageVolEventID; + +/** + * virConnectStorageVolEventGenericCallback: + * @conn: the connection pointer + * @vol: the vol pointer + * @opaque: application specified data + * + * A generic storage vol event callback handler, for use with + * virConnectStorageVolEventRegisterAny(). Specific events usually + * have a customization with extra parameters, often with @opaque being + * passed in a different parameter position; use + * VIR_STORAGE_VOL_EVENT_CALLBACK() when registering an appropriate handle= r. + */ +typedef void (*virConnectStorageVolEventGenericCallback)(virConnectPtr con= n, + virStorageVolPtr = vol, + void *opaque); + +/* Use VIR_STORAGE_VOL_EVENT_CALLBACK() to cast the 'cb' parameter */ +int virConnectStorageVolEventRegisterAny(virConnectPtr conn, + virStorageVolPtr vol, /* optional= , to filter */ + int eventID, + virConnectStorageVolEventGenericC= allback cb, + void *opaque, + virFreeCallback freecb); + +int virConnectStorageVolEventDeregisterAny(virConnectPtr conn, + int callbackID); + +/** + * virStorageVolEventLifecycleType: + * + * a virStorageVolEventLifecycleType is emitted during storage vol + * lifecycle events + */ +typedef enum { + VIR_STORAGE_VOL_EVENT_CREATED =3D 0, + VIR_STORAGE_VOL_EVENT_DELETED =3D 1, + +# ifdef VIR_ENUM_SENTINELS + VIR_STORAGE_VOL_EVENT_LAST +# endif +} virStorageVolEventLifecycleType; + +/** + * virConnectStorageVolEventLifecycleCallback: + * @conn: connection object + * @vol: vol on which the event occurred + * @event: The specific virStorageVolEventLifeCycleType which occurred + * @detail: contains some details on the reason of the event. + * @opaque: application specified data + * + * This callback is called when a vol lifecycle action is performed, like = start + * or stop. + * + * The callback signature to use when registering for an event of type + * VIR_STORAGE_VOL_EVENT_ID_LIFECYCLE with + * virConnectStorageVolEventRegisterAny() + */ +typedef void (*virConnectStorageVolEventLifecycleCallback)(virConnectPtr c= onn, + virStorageVolPt= r vol, + int event, + int detail, + void *opaque); + #endif /* __VIR_LIBVIRT_STORAGE_H__ */ diff --git a/src/libvirt-storage.c b/src/libvirt-storage.c index 1879c6bd60..2bb033c98c 100644 --- a/src/libvirt-storage.c +++ b/src/libvirt-storage.c @@ -2350,3 +2350,128 @@ virConnectStoragePoolEventDeregisterAny(virConnectP= tr conn, virDispatchError(conn); return -1; } + +/** + * virConnectStorageVolEventRegisterAny: + * @conn: pointer to the connection + * @vol: pointer to the storage vol + * @eventID: the event type to receive + * @cb: callback to the function handling network events + * @opaque: opaque data to pass on to the callback + * @freecb: optional function to deallocate opaque when not used anymore + * + * Adds a callback to receive notifications of arbitrary storage vol events + * occurring on a storage vol. This function requires that an event loop + * has been previously registered with virEventRegisterImpl() or + * virEventRegisterDefaultImpl(). + * + * If @vol is NULL, then events will be monitored for any storage vol. + * If @vol is non-NULL, then only the specific storage vol will be monitor= ed. + * + * Most types of events have a callback providing a custom set of paramete= rs + * for the event. When registering an event, it is thus necessary to use + * the VIR_STORAGE_VOL_EVENT_CALLBACK() macro to cast the + * supplied function pointer to match the signature of this method. + * + * The virStorageVolPtr object handle passed into the callback upon delive= ry + * of an event is only valid for the duration of execution of the callback. + * If the callback wishes to keep the storage vol object after the callback + * returns, it shall take a reference to it, by calling virStorageVolRef(). + * The reference can be released once the object is no longer required + * by calling virStorageVolFree(). + * + * The return value from this method is a positive integer identifier + * for the callback. To unregister a callback, this callback ID should + * be passed to the virConnectStorageVolEventDeregisterAny() method. + * + * Returns a callback identifier on success, -1 on failure. + */ +int +virConnectStorageVolEventRegisterAny(virConnectPtr conn, + virStorageVolPtr vol, + int eventID, + virConnectStorageVolEventGenericCallb= ack cb, + void *opaque, + virFreeCallback freecb) +{ + VIR_DEBUG("conn=3D%p, vol=3D%p, eventID=3D%d, cb=3D%p, opaque=3D%p, fr= eecb=3D%p", + conn, vol, eventID, cb, opaque, freecb); + + virResetLastError(); + + virCheckConnectReturn(conn, -1); + if (vol) { + virCheckStorageVolGoto(vol, error); + if (vol->conn !=3D conn) { + virReportInvalidArg(vol, + _("storage vol '%s' in %s must match conne= ction"), + vol->name, __FUNCTION__); + goto error; + } + } + virCheckNonNullArgGoto(cb, error); + virCheckNonNegativeArgGoto(eventID, error); + + if (eventID >=3D VIR_STORAGE_VOL_EVENT_ID_LAST) { + virReportInvalidArg(eventID, + _("eventID in %s must be less than %d"), + __FUNCTION__, VIR_STORAGE_VOL_EVENT_ID_LAST); + goto error; + } + + if (conn->storageDriver && + conn->storageDriver->connectStorageVolEventRegisterAny) { + int ret; + ret =3D conn->storageDriver->connectStorageVolEventRegisterAny(con= n, + vol, + event= ID, + cb, + opaqu= e, + freec= b); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + +/** + * virConnectStorageVolEventDeregisterAny: + * @conn: pointer to the connection + * @callbackID: the callback identifier + * + * Removes an event callback. The callbackID parameter should be the + * value obtained from a previous virConnectStorageVolEventRegisterAny() m= ethod. + * + * Returns 0 on success, -1 on failure + */ +int +virConnectStorageVolEventDeregisterAny(virConnectPtr conn, + int callbackID) +{ + VIR_DEBUG("conn=3D%p, callbackID=3D%d", conn, callbackID); + + virResetLastError(); + + virCheckConnectReturn(conn, -1); + virCheckNonNegativeArgGoto(callbackID, error); + + if (conn->storageDriver && + conn->storageDriver->connectStorageVolEventDeregisterAny) { + int ret; + ret =3D conn->storageDriver->connectStorageVolEventDeregisterAny(c= onn, + cal= lbackID); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 95df3a0dbc..b0dee76771 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -785,4 +785,10 @@ LIBVIRT_4.1.0 { virStoragePoolLookupByTargetPath; } LIBVIRT_3.9.0; =20 +LIBVIRT_4.4.0 { + global: + virConnectStorageVolEventRegisterAny; + virConnectStorageVolEventDeregisterAny; +} LIBVIRT_4.1.0; + # .... define new API here using predicted next version number .... --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list