[PATCH 1/3] Introduce node device update event as top level event

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

 



Also includes node device update event implementation for udev
backend.

Node device Update API:
virConnectNodeDeviceEventUpdateCallback
---
 daemon/remote.c                    | 29 ++++++++++++++++++++
 include/libvirt/libvirt-nodedev.h  |  1 +
 src/conf/node_device_event.c       | 55 ++++++++++++++++++++++++++++++++++++++
 src/conf/node_device_event.h       |  3 +++
 src/libvirt_private.syms           |  1 +
 src/node_device/node_device_udev.c |  2 ++
 src/remote/remote_driver.c         | 30 +++++++++++++++++++++
 src/remote/remote_protocol.x       | 13 ++++++++-
 src/remote_protocol-structs        |  5 ++++
 9 files changed, 138 insertions(+), 1 deletion(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 9e75472..155e9b0 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -1388,8 +1388,37 @@ remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn,
     return 0;
 }
 
+static int
+remoteRelayNodeDeviceEventUpdate(virConnectPtr conn,
+                                 virNodeDevicePtr dev,
+                                 void *opaque)
+{
+    daemonClientEventCallbackPtr callback = opaque;
+    remote_node_device_event_update_msg data;
+
+    if (callback->callbackID < 0 ||
+        !remoteRelayNodeDeviceEventCheckACL(callback->client, conn, dev))
+        return -1;
+
+    VIR_DEBUG("Relaying node device update event callback %d",
+              callback->callbackID);
+
+    /* build return data */
+    memset(&data, 0, sizeof(data));
+    make_nonnull_node_device(&data.dev, dev);
+    data.callbackID = callback->callbackID;
+
+    remoteDispatchObjectEventSend(callback->client, remoteProgram,
+                                  REMOTE_PROC_NODE_DEVICE_EVENT_UPDATE,
+                                  (xdrproc_t)xdr_remote_node_device_event_update_msg,
+                                  &data);
+
+    return 0;
+}
+
 static virConnectNodeDeviceEventGenericCallback nodeDeviceEventCallbacks[] = {
     VIR_NODE_DEVICE_EVENT_CALLBACK(remoteRelayNodeDeviceEventLifecycle),
+    VIR_NODE_DEVICE_EVENT_CALLBACK(remoteRelayNodeDeviceEventUpdate),
 };
 
 verify(ARRAY_CARDINALITY(nodeDeviceEventCallbacks) == VIR_NODE_DEVICE_EVENT_ID_LAST);
diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-nodedev.h
index 4ab6917..4ff8b41 100644
--- a/include/libvirt/libvirt-nodedev.h
+++ b/include/libvirt/libvirt-nodedev.h
@@ -138,6 +138,7 @@ int                     virNodeDeviceDestroy    (virNodeDevicePtr dev);
  */
 typedef enum {
     VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE = 0, /* virConnectNodeDeviceEventLifecycleCallback */
+    VIR_NODE_DEVICE_EVENT_ID_UPDATE = 1, /* virConnectNodeDeviceEventUpdateCallback */
 
 # ifdef VIR_ENUM_SENTINELS
     VIR_NODE_DEVICE_EVENT_ID_LAST
diff --git a/src/conf/node_device_event.c b/src/conf/node_device_event.c
index 61bc912..312ef51 100644
--- a/src/conf/node_device_event.c
+++ b/src/conf/node_device_event.c
@@ -48,10 +48,20 @@ struct _virNodeDeviceEventLifecycle {
 typedef struct _virNodeDeviceEventLifecycle virNodeDeviceEventLifecycle;
 typedef virNodeDeviceEventLifecycle *virNodeDeviceEventLifecyclePtr;
 
+struct _virNodeDeviceEventUpdate {
+    virNodeDeviceEvent parent;
+
+    bool dummy;
+};
+typedef struct _virNodeDeviceEventUpdate virNodeDeviceEventUpdate;
+typedef virNodeDeviceEventUpdate *virNodeDeviceEventUpdatePtr;
+
 static virClassPtr virNodeDeviceEventClass;
 static virClassPtr virNodeDeviceEventLifecycleClass;
+static virClassPtr virNodeDeviceEventUpdateClass;
 static void virNodeDeviceEventDispose(void *obj);
 static void virNodeDeviceEventLifecycleDispose(void *obj);
+static void virNodeDeviceEventUpdateDispose(void *obj);
 
 static int
 virNodeDeviceEventsOnceInit(void)
@@ -68,6 +78,12 @@ virNodeDeviceEventsOnceInit(void)
                       sizeof(virNodeDeviceEventLifecycle),
                       virNodeDeviceEventLifecycleDispose)))
         return -1;
+    if (!(virNodeDeviceEventUpdateClass =
+          virClassNew(virNodeDeviceEventClass,
+                      "virNodeDeviceEventUpdate",
+                      sizeof(virNodeDeviceEventUpdate),
+                      virNodeDeviceEventUpdateDispose)))
+        return -1;
     return 0;
 }
 
@@ -90,6 +106,14 @@ virNodeDeviceEventLifecycleDispose(void *obj)
 
 
 static void
+virNodeDeviceEventUpdateDispose(void *obj)
+{
+    virNodeDeviceEventUpdatePtr event = obj;
+    VIR_DEBUG("obj=%p", event);
+}
+
+
+static void
 virNodeDeviceEventDispatchDefaultFunc(virConnectPtr conn,
                                       virObjectEventPtr event,
                                       virConnectObjectEventGenericCallback cb,
@@ -114,6 +138,13 @@ virNodeDeviceEventDispatchDefaultFunc(virConnectPtr conn,
             goto cleanup;
         }
 
+    case VIR_NODE_DEVICE_EVENT_ID_UPDATE:
+        {
+            ((virConnectNodeDeviceEventGenericCallback)cb)(conn, dev,
+                                                           cbopaque);
+            goto cleanup;
+        }
+
     case VIR_NODE_DEVICE_EVENT_ID_LAST:
         break;
     }
@@ -232,3 +263,27 @@ virNodeDeviceEventLifecycleNew(const char *name,
 
     return (virObjectEventPtr)event;
 }
+
+
+/**
+ * virNodeDeviceEventUpdateNew:
+ * @name: name of the node device object the event describes
+ *
+ * Create a new node device update event.
+ */
+virObjectEventPtr
+virNodeDeviceEventUpdateNew(const char *name)
+{
+    virNodeDeviceEventUpdatePtr event;
+
+    if (virNodeDeviceEventsInitialize() < 0)
+        return NULL;
+
+    if (!(event = virObjectEventNew(virNodeDeviceEventUpdateClass,
+                                    virNodeDeviceEventDispatchDefaultFunc,
+                                    VIR_NODE_DEVICE_EVENT_ID_UPDATE,
+                                    0, name, NULL, name)))
+        return NULL;
+
+    return (virObjectEventPtr)event;
+}
diff --git a/src/conf/node_device_event.h b/src/conf/node_device_event.h
index 9c99633..5a32d33 100644
--- a/src/conf/node_device_event.h
+++ b/src/conf/node_device_event.h
@@ -56,4 +56,7 @@ virNodeDeviceEventLifecycleNew(const char *name,
                                int type,
                                int detail);
 
+virObjectEventPtr
+virNodeDeviceEventUpdateNew(const char *name);
+
 #endif
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 419c33d..a32ce1c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -687,6 +687,7 @@ virNodeDeviceObjUnlock;
 # conf/node_device_event.h
 virNodeDeviceEventLifecycleNew;
 virNodeDeviceEventStateRegisterID;
+virNodeDeviceEventUpdateNew;
 
 
 # conf/numa_conf.h
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 4182d5b..ddf3d88 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1147,6 +1147,8 @@ static int udevAddOneDevice(struct udev_device *device)
         event = virNodeDeviceEventLifecycleNew(dev->def->name,
                                                VIR_NODE_DEVICE_EVENT_CREATED,
                                                0);
+    else
+        event = virNodeDeviceEventUpdateNew(dev->def->name);
 
     virNodeDeviceObjUnlock(dev);
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 6637a1d..68b8434 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -375,6 +375,11 @@ remoteNodeDeviceBuildEventLifecycle(virNetClientProgramPtr prog ATTRIBUTE_UNUSED
                                     void *evdata, void *opaque);
 
 static void
+remoteNodeDeviceBuildEventUpdate(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
+                                 virNetClientPtr client ATTRIBUTE_UNUSED,
+                                 void *evdata, void *opaque);
+
+static void
 remoteConnectNotifyEventConnectionClosed(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                          virNetClientPtr client ATTRIBUTE_UNUSED,
                                          void *evdata, void *opaque);
@@ -565,6 +570,10 @@ static virNetClientProgramEvent remoteEvents[] = {
       remoteNodeDeviceBuildEventLifecycle,
       sizeof(remote_node_device_event_lifecycle_msg),
       (xdrproc_t)xdr_remote_node_device_event_lifecycle_msg },
+    { REMOTE_PROC_NODE_DEVICE_EVENT_UPDATE,
+      remoteNodeDeviceBuildEventUpdate,
+      sizeof(remote_node_device_event_update_msg),
+      (xdrproc_t)xdr_remote_node_device_event_update_msg },
 };
 
 static void
@@ -5286,6 +5295,27 @@ remoteNodeDeviceBuildEventLifecycle(virNetClientProgramPtr prog ATTRIBUTE_UNUSED
 }
 
 static void
+remoteNodeDeviceBuildEventUpdate(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
+                                 virNetClientPtr client ATTRIBUTE_UNUSED,
+                                 void *evdata, void *opaque)
+{
+    virConnectPtr conn = opaque;
+    struct private_data *priv = conn->privateData;
+    remote_node_device_event_update_msg *msg = evdata;
+    virNodeDevicePtr dev;
+    virObjectEventPtr event = NULL;
+
+    dev = get_nonnull_node_device(conn, msg->dev);
+    if (!dev)
+        return;
+
+    event = virNodeDeviceEventUpdateNew(dev->name);
+    virObjectUnref(dev);
+
+    remoteEventQueue(priv, event, msg->callbackID);
+}
+
+static void
 remoteDomainBuildQemuMonitorEvent(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
                                   virNetClientPtr client ATTRIBUTE_UNUSED,
                                   void *evdata, void *opaque)
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index b4fd057..49db071 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -3151,6 +3151,11 @@ struct remote_node_device_event_lifecycle_msg {
     int detail;
 };
 
+struct remote_node_device_event_update_msg {
+    int callbackID;
+    remote_nonnull_node_device dev;
+};
+
 struct remote_domain_fsfreeze_args {
     remote_nonnull_domain dom;
     remote_nonnull_string mountpoints<REMOTE_DOMAIN_FSFREEZE_MOUNTPOINTS_MAX>; /* (const char **) */
@@ -5923,5 +5928,11 @@ enum remote_procedure {
      * @generate: both
      * @acl: none
      */
-    REMOTE_PROC_NODE_DEVICE_EVENT_LIFECYCLE = 376
+    REMOTE_PROC_NODE_DEVICE_EVENT_LIFECYCLE = 376,
+
+    /**
+     * @generate: both
+     * @acl: none
+     */
+    REMOTE_PROC_NODE_DEVICE_EVENT_UPDATE = 377
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 24401d1..4552913 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2587,6 +2587,10 @@ struct remote_node_device_event_lifecycle_msg {
         int                        event;
         int                        detail;
 };
+struct remote_node_device_event_update_msg {
+        int                        callbackID;
+        remote_nonnull_node_device dev;
+};
 struct remote_domain_fsfreeze_args {
         remote_nonnull_domain      dom;
         struct {
@@ -3164,4 +3168,5 @@ enum remote_procedure {
         REMOTE_PROC_CONNECT_NODE_DEVICE_EVENT_REGISTER_ANY = 374,
         REMOTE_PROC_CONNECT_NODE_DEVICE_EVENT_DEREGISTER_ANY = 375,
         REMOTE_PROC_NODE_DEVICE_EVENT_LIFECYCLE = 376,
+        REMOTE_PROC_NODE_DEVICE_EVENT_UPDATE = 377,
 };
-- 
2.7.4

--
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]