]> xenbits.xensource.com Git - libvirt.git/commitdiff
events: Add explicit lookup 'key' value
authorCole Robinson <crobinso@redhat.com>
Thu, 23 Jun 2016 16:06:39 +0000 (12:06 -0400)
committerCole Robinson <crobinso@redhat.com>
Fri, 1 Jul 2016 11:15:38 +0000 (07:15 -0400)
This allows event implementations to match on something other
than an object's uuid, like nodedev or interface objects which
don't have a uuid.

src/conf/domain_event.c
src/conf/network_event.c
src/conf/object_event.c
src/conf/object_event_private.h
src/conf/storage_event.c

index 7ad6d2c7e488dc5c504dc13d7b639f01dc6ffbf1..63ae9e1a02df548e3e8997a96cd67a12af362e9a 100644 (file)
@@ -581,6 +581,7 @@ virDomainEventNew(virClassPtr klass,
                   const unsigned char *uuid)
 {
     virDomainEventPtr event;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     if (virDomainEventsInitialize() < 0)
         return NULL;
@@ -592,10 +593,14 @@ virDomainEventNew(virClassPtr klass,
         return NULL;
     }
 
+    /* We use uuid for matching key. We ignore 'name' because
+     * Xen sometimes renames guests during migration, thus
+     * 'uuid' is the only truly reliable key we can use. */
+    virUUIDFormat(uuid, uuidstr);
     if (!(event = virObjectEventNew(klass,
                                     virDomainEventDispatchDefaultFunc,
                                     eventID,
-                                    id, name, uuid)))
+                                    id, name, uuid, uuidstr)))
         return NULL;
 
     return (virObjectEventPtr)event;
@@ -1873,13 +1878,15 @@ virDomainQemuMonitorEventNew(int id,
                              const char *details)
 {
     virDomainQemuMonitorEventPtr ev;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     if (virDomainEventsInitialize() < 0)
         return NULL;
 
+    virUUIDFormat(uuid, uuidstr);
     if (!(ev = virObjectEventNew(virDomainQemuMonitorEventClass,
                                  virDomainQemuMonitorEventDispatchFunc,
-                                 0, id, name, uuid)))
+                                 0, id, name, uuid, uuidstr)))
         return NULL;
 
     /* event is mandatory, details are optional */
index 21f6db1b200ba4ded97d3a4c8ddc4c9f820ce76e..e0d1a3d5ca026ee3a2d9a4389114a0e4d809f887 100644 (file)
@@ -226,14 +226,16 @@ virNetworkEventLifecycleNew(const char *name,
                             int detail)
 {
     virNetworkEventLifecyclePtr event;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     if (virNetworkEventsInitialize() < 0)
         return NULL;
 
+    virUUIDFormat(uuid, uuidstr);
     if (!(event = virObjectEventNew(virNetworkEventLifecycleClass,
                                     virNetworkEventDispatchDefaultFunc,
                                     VIR_NETWORK_EVENT_ID_LIFECYCLE,
-                                    0, name, uuid)))
+                                    0, name, uuid, uuidstr)))
         return NULL;
 
     event->type = type;
index 8fd182d4d72a222b68a0914178ae1fa83e020613..573423014818226bcecd70203c427edc09a7da35 100644 (file)
@@ -123,6 +123,7 @@ virObjectEventDispose(void *obj)
     VIR_DEBUG("obj=%p", event);
 
     VIR_FREE(event->meta.name);
+    VIR_FREE(event->meta.key);
 }
 
 /**
@@ -619,6 +620,7 @@ virObjectEventStateNew(void)
  * @id: id of the object the event describes, or 0
  * @name: name of the object the event describes
  * @uuid: uuid of the object the event describes
+ * @key: key for per-object filtering
  *
  * Create a new event, with the information common to all events.
  */
@@ -628,7 +630,8 @@ virObjectEventNew(virClassPtr klass,
                   int eventID,
                   int id,
                   const char *name,
-                  const unsigned char *uuid)
+                  const unsigned char *uuid,
+                  const char *key)
 {
     virObjectEventPtr event;
 
@@ -653,6 +656,11 @@ virObjectEventNew(virClassPtr klass,
         VIR_FREE(event);
         return NULL;
     }
+    if (VIR_STRDUP(event->meta.key, key) < 0) {
+        VIR_FREE(event->meta.name);
+        VIR_FREE(event);
+        return NULL;
+    }
     event->meta.id = id;
     memcpy(event->meta.uuid, uuid, VIR_UUID_BUFLEN);
 
@@ -701,17 +709,8 @@ virObjectEventDispatchMatchCallback(virObjectEventPtr event,
     if (cb->filter && !(cb->filter)(cb->conn, event, cb->filter_opaque))
         return false;
 
-    if (cb->uuid_filter) {
-        /* Deliberately ignoring 'id' for matching, since that
-         * will cause problems when a domain switches between
-         * running & shutoff states & ignoring 'name' since
-         * Xen sometimes renames guests during migration, thus
-         * leaving 'uuid' as the only truly reliable ID we can use. */
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(event->meta.uuid, uuidstr);
-
-        return STREQ(uuidstr, cb->uuid);
-    }
+    if (cb->uuid_filter)
+        return STREQ(event->meta.key, cb->uuid);
     return true;
 }
 
index cae74efe60008eeee7bfa454fe0e5436af16df27..95b2120ff22670efba1c608b952d323b96806d39 100644 (file)
@@ -31,6 +31,7 @@ struct _virObjectMeta {
     int id;
     char *name;
     unsigned char uuid[VIR_UUID_BUFLEN];
+    char *key;
 };
 typedef struct _virObjectMeta virObjectMeta;
 typedef virObjectMeta *virObjectMetaPtr;
@@ -102,8 +103,9 @@ virObjectEventNew(virClassPtr klass,
                   int eventID,
                   int id,
                   const char *name,
-                  const unsigned char *uuid)
+                  const unsigned char *uuid,
+                  const char *key)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5)
-    ATTRIBUTE_NONNULL(6);
+    ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7);
 
 #endif
index 501b211a0cfb41735972b52c7769d9866e4704fc..f9b796878a6ab0314a110a96f25593f1a1e565fe 100644 (file)
@@ -259,14 +259,16 @@ virStoragePoolEventLifecycleNew(const char *name,
                                 int detail)
 {
     virStoragePoolEventLifecyclePtr event;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     if (virStoragePoolEventsInitialize() < 0)
         return NULL;
 
+    virUUIDFormat(uuid, uuidstr);
     if (!(event = virObjectEventNew(virStoragePoolEventLifecycleClass,
                                     virStoragePoolEventDispatchDefaultFunc,
                                     VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
-                                    0, name, uuid)))
+                                    0, name, uuid, uuidstr)))
         return NULL;
 
     event->type = type;
@@ -288,14 +290,16 @@ virStoragePoolEventRefreshNew(const char *name,
                               const unsigned char *uuid)
 {
     virStoragePoolEventRefreshPtr event;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     if (virStoragePoolEventsInitialize() < 0)
         return NULL;
 
+    virUUIDFormat(uuid, uuidstr);
     if (!(event = virObjectEventNew(virStoragePoolEventRefreshClass,
                                     virStoragePoolEventDispatchDefaultFunc,
                                     VIR_STORAGE_POOL_EVENT_ID_REFRESH,
-                                    0, name, uuid)))
+                                    0, name, uuid, uuidstr)))
         return NULL;
 
     return (virObjectEventPtr)event;