From nobody Thu May 2 04:02:22 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; 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 From nobody Thu May 2 04:02:22 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; 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 1527449191889140.60319352488318; Sun, 27 May 2018 12:26:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A1AB30C54F7; Sun, 27 May 2018 19:26:30 +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 3E95C308BDA9; Sun, 27 May 2018 19:26:30 +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 C710918033F5; Sun, 27 May 2018 19:26:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RJQBtA021804 for ; Sun, 27 May 2018 15:26:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4574F17B48; Sun, 27 May 2018 19:26:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D6A936FA for ; Sun, 27 May 2018 19:26:07 +0000 (UTC) Received: from mail-qk0-f169.google.com (mail-qk0-f169.google.com [209.85.220.169]) (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 06A6F30C715F for ; Sun, 27 May 2018 19:25:57 +0000 (UTC) Received: by mail-qk0-f169.google.com with SMTP id d125-v6so7757849qkb.8 for ; Sun, 27 May 2018 12:25:56 -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.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 May 2018 12:25:55 -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=p7wNJiXB24WMcGDnLh5s8KV/pnT2/rvtW4fUPeAAFvI=; b=PmWJqrmTroX2nqPIx1CZM0SIq4iDg5XZLMdfYQ45pKHSfbya8hA/mE5gTBwH8GmkLv EzAXXHVVHPWNNtJf6qrreDDkqCu3oOdbiPEANQfQZMo4Qw5SxOWwV5bFUqwiIuluUmej 348QyLlG7xh9i6QFC99+gQA4lBgltEuBGIaEh/2epAZi4l2DF5c6QcBeyLEPaUiqioj4 Gd/galG9biAVOvvmP+itnygUmGhxo+nsQeW8Yt8gTy2ZAaA81rn5m8Gu5kxT+E/lwjTC BB8J1VMTmB1axZBqDCggw+9z23jxx+V7mM0eGPNKe0IfIjvnF/iJxk1lOyU+lgsy2/f3 c9nA== 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=p7wNJiXB24WMcGDnLh5s8KV/pnT2/rvtW4fUPeAAFvI=; b=GPUIK0uR5iEefADWxhKKoTuvt9+ZHNdu1WjlMBg/XgmjiOwvxPLthPvw3GewZuj5eI cCnwTTtcgsWRuuQPTGzxM5oTt8l0yYyKEwIZK2WJlavNUguFQA4U8pg8Gf72XvzCeLYA hdo9c0PkM82c1qJ3R3qVpS/Au2otNji+zulNe7JatXIXHkEcTWGmfi+AylaDf+hBDEmC 1rRYjCwY5rQ/fPUm9iCuBZuvLmRaz29nGKhp9R8IgW63t257K4EUnyNyBRkbuuaMcvxz iAMQs6J6q0ulUrVMy2E+rd4iDEuZzDj/Z71DGNAbj2Fat/r6JQGozvsYPalkYrVWqcfm k/9A== X-Gm-Message-State: ALKqPwdJWoU6oa2E3an3YRLROXfBsP6hNFlPs+voEJmMjauellhaCm5D NNEwBkZVEvFH97y7LIzDGwvugg== X-Google-Smtp-Source: ADUXVKI+0yH+MNUoT8Cj7xbtqYJD4Lmka0idrmnVp6DnxOGZTXDNEDPWgZ66YqUhHIzCuDRWfxtqog== X-Received: by 2002:a37:a94a:: with SMTP id s71-v6mr8997230qke.221.1527449156072; Sun, 27 May 2018 12:25:56 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 27 May 2018 16:25:36 -0300 Message-Id: <20180527192539.17922-3-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.46]); Sun, 27 May 2018 19:25:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sun, 27 May 2018 19:25:57 +0000 (UTC) for IP:'209.85.220.169' DOMAIN:'mail-qk0-f169.google.com' HELO:'mail-qk0-f169.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.220.169 mail-qk0-f169.google.com 209.85.220.169 mail-qk0-f169.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] driver: adding two new driver functions to support 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sun, 27 May 2018 19:26:30 +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 two functions into the structure of the driver to support volume events: 'connectStorageVolEventRegisterAny' and 'connectStorageVolEventDeregisterAny'. Signed-off-by: Julio Faracco --- src/driver-storage.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/driver-storage.h b/src/driver-storage.h index 146eb88b2c..f332b9918f 100644 --- a/src/driver-storage.h +++ b/src/driver-storage.h @@ -213,10 +213,21 @@ typedef int void *opaque, virFreeCallback freecb); =20 +typedef int +(*virDrvConnectStorageVolEventRegisterAny)(virConnectPtr conn, + virStorageVolPtr vol, + int eventID, + virConnectStorageVolEventGeneri= cCallback cb, + void *opaque, + virFreeCallback freecb); + typedef int (*virDrvConnectStoragePoolEventDeregisterAny)(virConnectPtr conn, int callbackID); =20 +typedef int +(*virDrvConnectStorageVolEventDeregisterAny)(virConnectPtr conn, + int callbackID); =20 typedef struct _virStorageDriver virStorageDriver; typedef virStorageDriver *virStorageDriverPtr; @@ -237,6 +248,8 @@ struct _virStorageDriver { virDrvConnectFindStoragePoolSources connectFindStoragePoolSources; virDrvConnectStoragePoolEventRegisterAny connectStoragePoolEventRegist= erAny; virDrvConnectStoragePoolEventDeregisterAny connectStoragePoolEventDere= gisterAny; + virDrvConnectStorageVolEventRegisterAny connectStorageVolEventRegister= Any; + virDrvConnectStorageVolEventDeregisterAny connectStorageVolEventDeregi= sterAny; virDrvStoragePoolLookupByName storagePoolLookupByName; virDrvStoragePoolLookupByUUID storagePoolLookupByUUID; virDrvStoragePoolLookupByVolume storagePoolLookupByVolume; --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 04:02:22 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; 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 From nobody Thu May 2 04:02:22 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; 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 1527449194882889.2293020934816; Sun, 27 May 2018 12:26:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EEDA30A81B2; Sun, 27 May 2018 19:26:33 +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 424E958B8; Sun, 27 May 2018 19:26:33 +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 EC31E4CA83; Sun, 27 May 2018 19:26:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RJQCE1021811 for ; Sun, 27 May 2018 15:26:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3BB936FA; Sun, 27 May 2018 19:26:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A89A5DD6B for ; Sun, 27 May 2018 19:26:12 +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 55FF9A7036 for ; Sun, 27 May 2018 19:26:01 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id j12-v6so4424248qkk.4 for ; Sun, 27 May 2018 12:26:01 -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.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 May 2018 12:25:59 -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=gE2vnrCv8hanjvWJ/9YJyhQpISCpiwWO9UTpCPpvH3U=; b=Pm2XbOLEvXA+IBxEFvZdpZANNrpDLTSdMMsIIsgM9g18E0wznKKvjSf5LYnYh9/6Ck i3Ym4M1URdwN/Wo1xbo0kwld/UF+FBvY2wFZK3QbiCob56mx/tEWC4SviZYIIMIbqUj4 V2AWg/w6LpNC0l7IfR9G4WCW6Yz32D0vCDqcWHkvg2zKPhtTRzcuTCNpICE0X5y9ur59 8joM374aWM/fFMwgYOlxT0pX1hsdIOZd3jvb0k6P2AD7CiRkw3Sb1PcdHRNiYmqbIm3a pTfQMGCy+oKg1Abd5i3uJhLOKwlzDlEHs8d7WeKiasCcdjJQB9B7km3VfwD5PYaNm+ue gx4w== 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=gE2vnrCv8hanjvWJ/9YJyhQpISCpiwWO9UTpCPpvH3U=; b=eO1oLTkC1VQ1zAfYk6Ccbx8hFR7mJLQGBip2D+rKf6bYB09DRHhTrefbpdUKw7lq8r xaAnGSmXHFHQMD7ouWOoeAY4nQY74kWRCKmIAQmmKyAhINq9kALfA4KJpjOUk+9I3LyC k0r99nOtoePsqlTzVF0rTE3NsCLAUdh1ikLPAiWPXdGQmtNpz2hGz2HubstU5zpzhs+b 1XivetmzIX4ymf+k1mG7psM8MfYy5lLxMyo6FopPsb/KI8C76cwdcM2R3qkQ7jEaNwKy 9L5Z84wuEK9gjfNKbQuFBr6+kL1va/biyIaFzVF5wxb+mgB2HPgZlC9hVI6DITRgTpYF oKig== X-Gm-Message-State: ALKqPwfkl7eWmQdiYw/GbtobnzE3PH7wOH8iYnJiIDi0HSjpbJo9mDf3 Wfxuz7vUAzHr18HqLG8zejJXhw== X-Google-Smtp-Source: ADUXVKJeTXqKDzr4LwC6tLs6q/GguN2XS9LidtAa7gLmUZjv8zaqOx3oEVE9Zmgwn/LqoUrRLgfptA== X-Received: by 2002:a37:7844:: with SMTP id t65-v6mr9509325qkc.56.1527449160266; Sun, 27 May 2018 12:26:00 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 27 May 2018 16:25:38 -0300 Message-Id: <20180527192539.17922-5-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.26]); Sun, 27 May 2018 19:26:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 27 May 2018 19:26:01 +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.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] virsh: implementing 'vol-event' command. 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sun, 27 May 2018 19:26:33 +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" As we have some basics events for volumes, virsh can have the 'vol-event' command to check some events related to volumes. Signed-off-by: Julio Faracco --- tools/virsh-completer.c | 27 ++++++ tools/virsh-completer.h | 4 + tools/virsh-volume.c | 192 ++++++++++++++++++++++++++++++++++++++++ tools/virsh-volume.h | 8 ++ 4 files changed, 231 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index d3effe59ea..30cc595376 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -26,6 +26,7 @@ #include "virsh-domain.h" #include "virsh.h" #include "virsh-pool.h" +#include "virsh-volume.h" #include "virsh-nodedev.h" #include "virsh-util.h" #include "virsh-secret.h" @@ -732,6 +733,32 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_= UNUSED, } =20 =20 +char ** +virshVolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (VIR_ALLOC_N(ret, VIR_STORAGE_VOL_EVENT_ID_LAST) < 0) + goto error; + + for (i =3D 0; i < VIR_STORAGE_VOL_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(ret[i], virshVolEventCallbacks[i].name) < 0) + goto error; + } + + return ret; + + error: + virStringListFree(ret); + return NULL; +} + + char ** virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index ee7eec68c5..831be73d7e 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -90,6 +90,10 @@ char ** virshPoolEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshVolEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + char ** virshNodedevEventNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 9d6ebd2325..63497b7d8c 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -42,6 +42,7 @@ #include "virsh-pool.h" #include "virxml.h" #include "virstring.h" +#include "virtime.h" =20 #define VIRSH_COMMON_OPT_POOL_FULL \ VIRSH_COMMON_OPT_POOL(N_("pool name or uuid"), \ @@ -1772,6 +1773,191 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd) return true; } =20 +/* + * "vol-event" command + */ +VIR_ENUM_DECL(virshVolEvent) +VIR_ENUM_IMPL(virshVolEvent, + VIR_STORAGE_VOL_EVENT_LAST, + N_("Created"), + N_("Deleted")) + +static const char * +virshVolEventToString(int event) +{ + const char *str =3D virshVolEventTypeToString(event); + return str ? _(str) : _("unknown"); +} + +struct virshVolEventData { + vshControl *ctl; + bool loop; + bool timestamp; + int count; + virshVolEventCallback *cb; +}; +typedef struct virshVolEventData virshVolEventData; + + +static void +vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED, + virStorageVolPtr vol, + int event, + int detail ATTRIBUTE_UNUSED, + void *opaque) +{ + virshVolEventData *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, _("%s: event 'lifecycle' for storage vol %s: %= s\n"), + timestamp, + virStorageVolGetName(vol), + virshVolEventToString(event)); + } else { + vshPrint(data->ctl, _("event 'lifecycle' for storage vol %s: %s\n"= ), + virStorageVolGetName(vol), + virshVolEventToString(event)); + } + + data->count++; + if (!data->loop) + vshEventDone(data->ctl); +} + +virshVolEventCallback virshVolEventCallbacks[] =3D { + { "lifecycle", + VIR_STORAGE_VOL_EVENT_CALLBACK(vshEventLifecyclePrint), } +}; +verify(VIR_STORAGE_VOL_EVENT_ID_LAST =3D=3D ARRAY_CARDINALITY(virshVolEven= tCallbacks)); + + +static const vshCmdInfo info_vol_event[] =3D { + {.name =3D "help", + .data =3D N_("Storage Vol Events") + }, + {.name =3D "desc", + .data =3D N_("List event types, or wait for storage vol events to occ= ur") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_vol_event[] =3D { + {.name =3D "vol", + .type =3D VSH_OT_STRING, + .help =3D N_("filter by storage vol name or uuid") + }, + {.name =3D "event", + .type =3D VSH_OT_STRING, + .completer =3D virshVolEventNameCompleter, + .help =3D N_("which event type to wait for") + }, + {.name =3D "loop", + .type =3D VSH_OT_BOOL, + .help =3D N_("loop until timeout or interrupt, rather than one-shot") + }, + {.name =3D "timeout", + .type =3D VSH_OT_INT, + .help =3D N_("timeout seconds") + }, + {.name =3D "list", + .type =3D VSH_OT_BOOL, + .help =3D N_("list valid event types") + }, + {.name =3D "timestamp", + .type =3D VSH_OT_BOOL, + .help =3D N_("show timestamp for each printed event") + }, + {.name =3D NULL} +}; + +static bool +cmdVolEvent(vshControl *ctl, const vshCmd *cmd) +{ + virStorageVolPtr vol =3D NULL; + bool ret =3D false; + int eventId =3D -1; + int timeout =3D 0; + virshVolEventData data; + const char *eventName =3D NULL; + int event; + virshControlPtr priv =3D ctl->privData; + + if (vshCommandOptBool(cmd, "list")) { + size_t i; + + for (i =3D 0; i < VIR_STORAGE_VOL_EVENT_ID_LAST; i++) + vshPrint(ctl, "%s\n", virshVolEventCallbacks[i].name); + return true; + } + + if (vshCommandOptStringReq(ctl, cmd, "event", &eventName) < 0) + return false; + if (!eventName) { + vshError(ctl, "%s", _("either --list or --event is required= ")); + return false; + } + + for (event =3D 0; event < VIR_STORAGE_VOL_EVENT_ID_LAST; event++) + if (STREQ(eventName, virshVolEventCallbacks[event].name)) + break; + if (event =3D=3D VIR_STORAGE_VOL_EVENT_ID_LAST) { + vshError(ctl, _("unknown event type %s"), eventName); + return false; + } + + data.ctl =3D ctl; + data.loop =3D vshCommandOptBool(cmd, "loop"); + data.timestamp =3D vshCommandOptBool(cmd, "timestamp"); + data.count =3D 0; + data.cb =3D &virshVolEventCallbacks[event]; + if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) + return false; + + if (vshCommandOptBool(cmd, "vol")) + vol =3D virshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL, + VIRSH_BYUUID); + + if (vshEventStart(ctl, timeout) < 0) + goto cleanup; + + if ((eventId =3D virConnectStorageVolEventRegisterAny(priv->conn, vol,= event, + data.cb->cb, + &data, NULL)) < 0) + goto cleanup; + switch (vshEventWait(ctl)) { + case VSH_EVENT_INTERRUPT: + vshPrint(ctl, "%s", _("event loop interrupted\n")); + break; + case VSH_EVENT_TIMEOUT: + vshPrint(ctl, "%s", _("event loop timed out\n")); + break; + case VSH_EVENT_DONE: + break; + default: + goto cleanup; + } + vshPrint(ctl, _("events received: %d\n"), data.count); + if (data.count) + ret =3D true; + + cleanup: + vshEventCleanup(ctl); + if (eventId >=3D 0 && + virConnectStorageVolEventDeregisterAny(priv->conn, eventId) < 0) + ret =3D false; + if (vol) + virStorageVolFree(vol); + return ret; +} + const vshCmdDef storageVolCmds[] =3D { {.name =3D "vol-clone", .handler =3D cmdVolClone, @@ -1869,5 +2055,11 @@ const vshCmdDef storageVolCmds[] =3D { .info =3D info_vol_wipe, .flags =3D 0 }, + {.name =3D "vol-event", + .handler =3D cmdVolEvent, + .opts =3D opts_vol_event, + .info =3D info_vol_event, + .flags =3D 0 + }, {.name =3D NULL} }; diff --git a/tools/virsh-volume.h b/tools/virsh-volume.h index 60f647776e..7869d3bfaf 100644 --- a/tools/virsh-volume.h +++ b/tools/virsh-volume.h @@ -38,6 +38,14 @@ virStorageVolPtr virshCommandOptVolBy(vshControl *ctl, c= onst vshCmd *cmd, virshCommandOptVolBy(_ctl, _cmd, _optname, _pooloptname, _name, \ VIRSH_BYUUID | VIRSH_BYNAME) =20 +struct virshVolEventCallback { + const char *name; + virConnectStorageVolEventGenericCallback cb; +}; +typedef struct virshVolEventCallback virshVolEventCallback; + +extern virshVolEventCallback virshVolEventCallbacks[]; + extern const vshCmdDef storageVolCmds[]; =20 #endif /* VIRSH_VOLUME_H */ --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 04:02:22 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; 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 1527449197817809.4014891002194; Sun, 27 May 2018 12:26:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E495BB2DFF; Sun, 27 May 2018 19:26:35 +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 A79A71691A; Sun, 27 May 2018 19:26:35 +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 56A7818033F0; Sun, 27 May 2018 19:26:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4RJQGPM021831 for ; Sun, 27 May 2018 15:26:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id E01735E1CD; Sun, 27 May 2018 19:26:16 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6221177D7 for ; Sun, 27 May 2018 19:26:14 +0000 (UTC) Received: from mail-qk0-f181.google.com (mail-qk0-f181.google.com [209.85.220.181]) (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 41D07F8055 for ; Sun, 27 May 2018 19:26:03 +0000 (UTC) Received: by mail-qk0-f181.google.com with SMTP id 185-v6so7764187qkk.11 for ; Sun, 27 May 2018 12:26:03 -0700 (PDT) Received: from localhost.localdomain ([186.223.96.215]) by smtp.gmail.com with ESMTPSA id 73-v6sm5901971qkc.96.2018.05.27.12.26.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 May 2018 12:26:01 -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=VIa/F1UkYGffjVyYTmyFydkq3GPdfp+rEdHWrz2fqns=; b=lxdqy48vJJQeE9kZfeXM3BPQvlQe4DlnY9U7VrGEgkOAlzay7jmXRZUtS5v3n5YD8S KTAaCyh/wu0pFNuABC8P8QZfbdV29EonoNnsOKTVaQptNmYpt1CxUy1qkLVDfgoXeVjM dKNYqnrhkGRSuC+UwXkz9x2cFQTgR1vz2sVS0eOJBvy8it+Uq/GmtzDFI+WS/XX4tEiK fsAPLw1Ihc12wzTDkJ1oCmYf5evhOf/VlU00PEHir6aEAl/eBQg6U9RnsDMJC/zRudm6 F0lrGLdCR7w+xnVCXEl9EwjzDwe0rxPntbkcksloj7vLYyav/vvF6gbOEt7/X7F/ibc9 6cYQ== 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=VIa/F1UkYGffjVyYTmyFydkq3GPdfp+rEdHWrz2fqns=; b=TRhEPPET5rWGTLgqJ3Yb93eFHv26RLN4iSTKW9GNtGfxf4/UJSjWBdpXGHz7sZ4xf2 M0UERjg3AEFvEWHFrg2u1r74RO0HRUseiB6naVZvF5BNojhazdG+qu0l+gv6cl2eu/Yv gMzQsnLLlTVZgXQMozXLLmCKkNCILmV29oRYg6NUjGVC6ZC6/dLqoMI2Rx9jP4cBzR7e qShDzS07se3FXVPnIFZ3OF+BP9MNqJUpYNWEe2ocmJZ8uRLPdRFXxFZi2GMqYW+9GQF1 EeQAazzCltdbNNzmaqEeVeYLJ8B/6mEvCEbpu30pI4yjWiwdWLerrvLlJ/vG0XO5dDo7 7t8w== X-Gm-Message-State: ALKqPwfprQrp1Lw4oLeTTf2gSg4U3ZYrNI1NAf12mA+/JRC3XLw+XErO Zu5asTaH+jYYWSVCT4NGOKI2PA== X-Google-Smtp-Source: ADUXVKLOJAFvHHCr5kq5Q7FDY+jCdbfu2jAKkfQR2eGiq1nLlcYv5X3QX8Ifonfj+8/l8+IvC+YNpw== X-Received: by 2002:a37:6f01:: with SMTP id k1-v6mr9118451qkc.140.1527449162231; Sun, 27 May 2018 12:26:02 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 27 May 2018 16:25:39 -0300 Message-Id: <20180527192539.17922-6-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.27]); Sun, 27 May 2018 19:26:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sun, 27 May 2018 19:26:03 +0000 (UTC) for IP:'209.85.220.181' DOMAIN:'mail-qk0-f181.google.com' HELO:'mail-qk0-f181.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.220.181 mail-qk0-f181.google.com 209.85.220.181 mail-qk0-f181.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] examples: adding volume events into event-test example. 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 27 May 2018 19:26:36 +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" After including volume events, event-test inside examples needs to be updated with some volume events too. Signed-off-by: Julio Faracco --- examples/object-events/event-test.c | 65 +++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/examples/object-events/event-test.c b/examples/object-events/e= vent-test.c index 8499e0b38e..605490fa68 100644 --- a/examples/object-events/event-test.c +++ b/examples/object-events/event-test.c @@ -366,6 +366,20 @@ storagePoolEventToString(int event) return "unknown"; } =20 +static const char * +storageVolEventToString(int event) +{ + switch ((virStorageVolEventLifecycleType) event) { + case VIR_STORAGE_VOL_EVENT_CREATED: + return "Created"; + case VIR_STORAGE_VOL_EVENT_DELETED: + return "Deleted"; + case VIR_STORAGE_VOL_EVENT_LAST: + break; + } + return "unknown"; +} + static const char * nodeDeviceEventToString(int event) { @@ -730,6 +744,19 @@ myStoragePoolEventRefreshCallback(virConnectPtr conn A= TTRIBUTE_UNUSED, return 0; } =20 +static int +myStorageVolEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED, + virStorageVolPtr vol, + int event, + int detail, + void *opaque ATTRIBUTE_UNUSED) +{ + printf("%s EVENT: Storage volume %s %s %d\n", __func__, + virStorageVolGetName(vol), + storageVolEventToString(event), + detail); + return 0; +} =20 static int myNodeDeviceEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED, @@ -1099,6 +1126,20 @@ struct storagePoolEventData storagePoolEvents[] =3D { STORAGE_POOL_EVENT(VIR_STORAGE_POOL_EVENT_ID_REFRESH, myStoragePoolEve= ntRefreshCallback), }; =20 +struct storageVolEventData { + int event; + int id; + virConnectStorageVolEventGenericCallback cb; + const char *name; +}; + +#define STORAGE_VOL_EVENT(event, callback) \ + {event, -1, VIR_STORAGE_VOL_EVENT_CALLBACK(callback), #event} + +struct storageVolEventData storageVolEvents[] =3D { + STORAGE_VOL_EVENT(VIR_STORAGE_VOL_EVENT_ID_LIFECYCLE, myStorageVolEven= tCallback), +}; + struct nodeDeviceEventData { int event; int id; @@ -1132,6 +1173,7 @@ struct secretEventData secretEvents[] =3D { /* make sure that the events are kept in sync */ verify(ARRAY_CARDINALITY(domainEvents) =3D=3D VIR_DOMAIN_EVENT_ID_LAST); verify(ARRAY_CARDINALITY(storagePoolEvents) =3D=3D VIR_STORAGE_POOL_EVENT_= ID_LAST); +verify(ARRAY_CARDINALITY(storageVolEvents) =3D=3D VIR_STORAGE_VOL_EVENT_ID= _LAST); verify(ARRAY_CARDINALITY(nodeDeviceEvents) =3D=3D VIR_NODE_DEVICE_EVENT_ID= _LAST); verify(ARRAY_CARDINALITY(secretEvents) =3D=3D VIR_SECRET_EVENT_ID_LAST); =20 @@ -1225,6 +1267,22 @@ main(int argc, char **argv) } } =20 + /* register common storage volume callbacks */ + for (i =3D 0; i < ARRAY_CARDINALITY(storageVolEvents); i++) { + struct storageVolEventData *event =3D storageVolEvents + i; + + event->id =3D virConnectStorageVolEventRegisterAny(dconn, NULL, + event->event, + event->cb, + strdup(event->nam= e), + myFreeFunc); + + if (event->id < 0) { + fprintf(stderr, "Failed to register event '%s'\n", event->name= ); + goto cleanup; + } + } + /* register common node device callbacks */ for (i =3D 0; i < ARRAY_CARDINALITY(nodeDeviceEvents); i++) { struct nodeDeviceEventData *event =3D nodeDeviceEvents + i; @@ -1293,6 +1351,13 @@ main(int argc, char **argv) } =20 =20 + printf("Deregistering storage volume event callbacks\n"); + for (i =3D 0; i < ARRAY_CARDINALITY(storageVolEvents); i++) { + if (storageVolEvents[i].id > 0) + virConnectStorageVolEventDeregisterAny(dconn, storageVolEvents= [i].id); + } + + printf("Deregistering node device event callbacks\n"); for (i =3D 0; i < ARRAY_CARDINALITY(nodeDeviceEvents); i++) { if (nodeDeviceEvents[i].id > 0) --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list