[PATCH v3 2/7] conf: add storage_event handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Changes since v2: rename STORAGE_POOL_EVENT_SOURCES to
STORAGE_EVENT_SOURCES, change copyright

Add storage event handling infrastructure to storage_event.[ch], following
the network_event.[ch] pattern.
---
 src/Makefile.am          |   5 +
 src/conf/storage_conf.h  |   1 +
 src/conf/storage_event.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/storage_event.h |  58 ++++++++++++
 src/libvirt_private.syms |   5 +
 5 files changed, 304 insertions(+)
 create mode 100644 src/conf/storage_event.c
 create mode 100644 src/conf/storage_event.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 1aff57d..1aaa00e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -343,6 +343,9 @@ DOMAIN_EVENT_SOURCES =						\
 NETWORK_EVENT_SOURCES =						\
 		conf/network_event.c conf/network_event.h
 
+STORAGE_EVENT_SOURCES =						\
+                conf/storage_event.c conf/storage_event.h
+
 # Network driver generic impl APIs
 NETWORK_CONF_SOURCES =						\
 		conf/network_conf.c conf/network_conf.h \
@@ -393,6 +396,7 @@ CONF_SOURCES =							\
 		$(OBJECT_EVENT_SOURCES)				\
 		$(DOMAIN_EVENT_SOURCES)				\
 		$(NETWORK_EVENT_SOURCES)			\
+		$(STORAGE_EVENT_SOURCES)			\
 		$(NETWORK_CONF_SOURCES)				\
 		$(NWFILTER_CONF_SOURCES)			\
 		$(NODE_DEVICE_CONF_SOURCES)			\
@@ -2360,6 +2364,7 @@ libvirt_setuid_rpc_client_la_SOURCES = 		\
 		conf/domain_event.c		\
 		conf/network_event.c		\
 		conf/object_event.c		\
+		conf/storage_event.c            \
 		rpc/virnetsocket.c		\
 		rpc/virnetsocket.h		\
 		rpc/virnetmessage.h		\
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 54116a6..c803ccf 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -31,6 +31,7 @@
 # include "virthread.h"
 # include "device_conf.h"
 # include "node_device_conf.h"
+# include "object_event.h"
 
 # include <libxml/tree.h>
 
diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c
new file mode 100644
index 0000000..670194a
--- /dev/null
+++ b/src/conf/storage_event.c
@@ -0,0 +1,235 @@
+/*
+ * storage_event.c: storage event queue processing helpers
+ *
+ * Copyright (C) 2016 Jovanka Gulicoska jovanka.gulicoska@xxxxxxxxx
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+*/
+
+#include <config.h>
+
+#include "storage_event.h"
+#include "object_event.h"
+#include "object_event_private.h"
+#include "datatypes.h"
+#include "virlog.h"
+
+VIR_LOG_INIT("conf.storage_event");
+
+struct _virStoragePoolEvent {
+    virObjectEvent parent;
+
+    /* Unused attribute to allow for subclass creation */
+    bool dummy;
+};
+typedef struct _virStoragePoolEvent virStoragePoolEvent;
+typedef virStoragePoolEvent *virStoragePoolEventPtr;
+
+struct _virStoragePoolEventLifecycle {
+    virStoragePoolEvent parent;
+
+    int type;
+    int detail;
+};
+typedef struct _virStoragePoolEventLifecycle virStoragePoolEventLifecycle;
+typedef virStoragePoolEventLifecycle *virStoragePoolEventLifecyclePtr;
+
+static virClassPtr virStoragePoolEventClass;
+static virClassPtr virStoragePoolEventLifecycleClass;
+static void virStoragePoolEventDispose(void *obj);
+static void virStoragePoolEventLifecycleDispose(void *obj);
+
+static int
+virStoragePoolEventsOnceInit(void)
+{
+    if (!(virStoragePoolEventClass =
+          virClassNew(virClassForObjectEvent(),
+                      "virStoragePoolEvent",
+                      sizeof(virStoragePoolEvent),
+                      virStoragePoolEventDispose)))
+        return -1;
+    if (!(virStoragePoolEventLifecycleClass =
+          virClassNew(virStoragePoolEventClass,
+                      "virStoragePoolEventLifecycle",
+                      sizeof(virStoragePoolEventLifecycle),
+                      virStoragePoolEventLifecycleDispose)))
+        return -1;
+    return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virStoragePoolEvents)
+
+static void
+virStoragePoolEventDispose(void *obj)
+{
+    virStoragePoolEventPtr event = obj;
+    VIR_DEBUG("obj=%p", event);
+}
+
+
+static void
+virStoragePoolEventLifecycleDispose(void *obj)
+{
+    virStoragePoolEventLifecyclePtr event = obj;
+    VIR_DEBUG("obj=%p", event);
+}
+
+
+static void
+virStoragePoolEventDispatchDefaultFunc(virConnectPtr conn,
+                                       virObjectEventPtr event,
+                                       virConnectObjectEventGenericCallback cb,
+                                       void *cbopaque)
+{
+    virStoragePoolPtr pool = virGetStoragePool(conn,
+                                               event->meta.name,
+                                               event->meta.uuid,
+                                               NULL, NULL);
+    if (!pool)
+        return;
+
+    switch ((virStoragePoolEventID)event->eventID) {
+    case VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE:
+        {
+            virStoragePoolEventLifecyclePtr storagePoolLifecycleEvent;
+
+            storagePoolLifecycleEvent = (virStoragePoolEventLifecyclePtr)event;
+            ((virConnectStoragePoolEventLifecycleCallback)cb)(conn, pool,
+                                                              storagePoolLifecycleEvent->type,
+                                                              storagePoolLifecycleEvent->detail,
+                                                              cbopaque);
+            goto cleanup;
+        }
+
+    case VIR_STORAGE_POOL_EVENT_ID_LAST:
+        break;
+    }
+    VIR_WARN("Unexpected event ID %d", event->eventID);
+
+ cleanup:
+    virObjectUnref(pool);
+}
+
+
+/**
+ * virStoragePoolEventStateRegisterID:
+ * @conn: connection to associate with callback
+ * @state: object event state
+ * @pool: storage pool to filter on or NULL for all storage pools
+ * @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
+virStoragePoolEventStateRegisterID(virConnectPtr conn,
+                                   virObjectEventStatePtr state,
+                                   virStoragePoolPtr pool,
+                                   int eventID,
+                                   virConnectStoragePoolEventGenericCallback cb,
+                                   void *opaque,
+                                   virFreeCallback freecb,
+                                   int *callbackID)
+{
+    if (virStoragePoolEventsInitialize() < 0)
+        return -1;
+
+    return virObjectEventStateRegisterID(conn, state, pool ? pool->uuid : NULL,
+                                         NULL, NULL,
+                                         virStoragePoolEventClass, eventID,
+                                         VIR_OBJECT_EVENT_CALLBACK(cb),
+                                         opaque, freecb,
+                                         false, callbackID, false);
+}
+
+
+/**
+ * virStoragePoolEventStateRegisterClient:
+ * @conn: connection to associate with callback
+ * @state: object event state
+ * @pool: storage pool to filter on or NULL for all storage pools
+ * @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.  This version is intended for use on the client side
+ * of RPC.
+ *
+ * Returns: the number of callbacks now registered, or -1 on error
+ */
+int
+virStoragePoolEventStateRegisterClient(virConnectPtr conn,
+                                       virObjectEventStatePtr state,
+                                       virStoragePoolPtr pool,
+                                       int eventID,
+                                       virConnectStoragePoolEventGenericCallback cb,
+                                       void *opaque,
+                                       virFreeCallback freecb,
+                                       int *callbackID)
+{
+    if (virStoragePoolEventsInitialize() < 0)
+        return -1;
+
+    return virObjectEventStateRegisterID(conn, state,  pool ? pool->uuid : NULL,
+                                         NULL, NULL,
+                                         virStoragePoolEventClass, eventID,
+                                         VIR_OBJECT_EVENT_CALLBACK(cb),
+                                         opaque, freecb,
+                                         false, callbackID, true);
+}
+
+
+/**
+ * virStoragePoolEventLifecycleNew:
+ * @name: name of the storage pool object the event describes
+ * @uuid: uuid of the storage pool object the event describes
+ * @type: type of lifecycle event
+ * @detail: more details about @type
+ *
+ * Create a new storage pool lifecycle event.
+ */
+virObjectEventPtr
+virStoragePoolEventLifecycleNew(const char *name,
+                                const unsigned char *uuid,
+                                int type,
+                                int detail)
+{
+    virStoragePoolEventLifecyclePtr event;
+
+    if (virStoragePoolEventsInitialize() < 0)
+        return NULL;
+
+    if (!(event = virObjectEventNew(virStoragePoolEventLifecycleClass,
+                                    virStoragePoolEventDispatchDefaultFunc,
+                                    VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
+                                    0, name, uuid)))
+        return NULL;
+
+    event->type = type;
+    event->detail = detail;
+
+    return (virObjectEventPtr)event;
+}
diff --git a/src/conf/storage_event.h b/src/conf/storage_event.h
new file mode 100644
index 0000000..c2aabde
--- /dev/null
+++ b/src/conf/storage_event.h
@@ -0,0 +1,58 @@
+/*
+ * storage_event.h: storage event queue processing helpers
+ *
+ * Copyright (C) 2016 Jovanka Gulicoska jovanka.gulicoska@xxxxxxxxx
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+*/
+
+#include "internal.h"
+#include "object_event.h"
+#include "object_event_private.h"
+
+#ifndef __STORAGE_EVENT_H__
+# define __STORAGE_EVENT_H__
+
+int
+virStoragePoolEventStateRegisterID(virConnectPtr conn,
+                                   virObjectEventStatePtr state,
+                                   virStoragePoolPtr pool,
+                                   int eventID,
+                                   virConnectStoragePoolEventGenericCallback 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,
+                                   virStoragePoolPtr pool,
+                                   int eventID,
+                                   virConnectStoragePoolEventGenericCallback cb,
+                                   void *opaque,
+                                   virFreeCallback freecb,
+                                   int *callbackID)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5)
+    ATTRIBUTE_NONNULL(8);
+
+virObjectEventPtr
+virStoragePoolEventLifecycleNew(const char *name,
+                                const unsigned char *uuid,
+                                int type,
+                                int detail);
+
+#endif
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e939de3..af30476 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -878,6 +878,11 @@ virStorageVolTypeFromString;
 virStorageVolTypeToString;
 
 
+# conf/storage_event.h
+virStoragePoolEventLifecycleNew;
+virStoragePoolEventStateRegisterID;
+
+
 # conf/virchrdev.h
 virChrdevAlloc;
 virChrdevFree;
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]