diff mbox

[4/6] events: Pass in UUID as a string

Message ID 4b062a329e41056bbde4d363178018df258fa94a.1466699232.git.crobinso@redhat.com
State Accepted
Commit d7c96a7245990581a77cc8602f69c8f2058620e1
Headers show

Commit Message

Cole Robinson June 23, 2016, 4:27 p.m. UTC
This should not have any functional difference, it's just a step
towards matching on non-uuid string keys
---
 src/conf/domain_event.c         | 17 ++++++++++++++---
 src/conf/network_event.c        | 12 ++++++++++--
 src/conf/object_event.c         | 24 +++++++++++++-----------
 src/conf/object_event_private.h |  2 +-
 src/conf/storage_event.c        | 12 ++++++++++--
 5 files changed, 48 insertions(+), 19 deletions(-)

-- 
2.7.4

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

Patch

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 58823e8..7ad6d2c 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -1998,10 +1998,14 @@  virDomainEventStateRegisterID(virConnectPtr conn,
                               virFreeCallback freecb,
                               int *callbackID)
 {
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
     if (virDomainEventsInitialize() < 0)
         return -1;
 
-    return virObjectEventStateRegisterID(conn, state, dom ? dom->uuid : NULL,
+    if (dom)
+        virUUIDFormat(dom->uuid, uuidstr);
+    return virObjectEventStateRegisterID(conn, state, dom ? uuidstr : NULL,
                                          NULL, NULL,
                                          virDomainEventClass, eventID,
                                          VIR_OBJECT_EVENT_CALLBACK(cb),
@@ -2042,10 +2046,14 @@  virDomainEventStateRegisterClient(virConnectPtr conn,
                                   int *callbackID,
                                   bool remoteID)
 {
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
     if (virDomainEventsInitialize() < 0)
         return -1;
 
-    return virObjectEventStateRegisterID(conn, state, dom ? dom->uuid : NULL,
+    if (dom)
+        virUUIDFormat(dom->uuid, uuidstr);
+    return virObjectEventStateRegisterID(conn, state, dom ? uuidstr : NULL,
                                          NULL, NULL,
                                          virDomainEventClass, eventID,
                                          VIR_OBJECT_EVENT_CALLBACK(cb),
@@ -2180,6 +2188,7 @@  virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
 {
     virDomainQemuMonitorEventData *data = NULL;
     virObjectEventCallbackFilter filter = NULL;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
     if (virDomainEventsInitialize() < 0)
         return -1;
@@ -2220,7 +2229,9 @@  virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
         filter = virDomainQemuMonitorEventFilter;
     freecb = virDomainQemuMonitorEventCleanup;
 
-    return virObjectEventStateRegisterID(conn, state, dom ? dom->uuid : NULL,
+    if (dom)
+        virUUIDFormat(dom->uuid, uuidstr);
+    return virObjectEventStateRegisterID(conn, state, dom ? uuidstr : NULL,
                                          filter, data,
                                          virDomainQemuMonitorEventClass, 0,
                                          VIR_OBJECT_EVENT_CALLBACK(cb),
diff --git a/src/conf/network_event.c b/src/conf/network_event.c
index 8623940..21f6db1 100644
--- a/src/conf/network_event.c
+++ b/src/conf/network_event.c
@@ -150,10 +150,14 @@  virNetworkEventStateRegisterID(virConnectPtr conn,
                                virFreeCallback freecb,
                                int *callbackID)
 {
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
     if (virNetworkEventsInitialize() < 0)
         return -1;
 
-    return virObjectEventStateRegisterID(conn, state, net ? net->uuid : NULL,
+    if (net)
+        virUUIDFormat(net->uuid, uuidstr);
+    return virObjectEventStateRegisterID(conn, state, net ? uuidstr : NULL,
                                          NULL, NULL,
                                          virNetworkEventClass, eventID,
                                          VIR_OBJECT_EVENT_CALLBACK(cb),
@@ -190,10 +194,14 @@  virNetworkEventStateRegisterClient(virConnectPtr conn,
                                    virFreeCallback freecb,
                                    int *callbackID)
 {
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
     if (virNetworkEventsInitialize() < 0)
         return -1;
 
-    return virObjectEventStateRegisterID(conn, state, net ? net->uuid : NULL,
+    if (net)
+        virUUIDFormat(net->uuid, uuidstr);
+    return virObjectEventStateRegisterID(conn, state, net ? uuidstr : NULL,
                                          NULL, NULL,
                                          virNetworkEventClass, eventID,
                                          VIR_OBJECT_EVENT_CALLBACK(cb),
diff --git a/src/conf/object_event.c b/src/conf/object_event.c
index 2230eec..8fd182d 100644
--- a/src/conf/object_event.c
+++ b/src/conf/object_event.c
@@ -45,7 +45,7 @@  struct _virObjectEventCallback {
     virConnectPtr conn;
     int remoteID;
     bool uuid_filter;
-    unsigned char uuid[VIR_UUID_BUFLEN];
+    char *uuid;
     virObjectEventCallbackFilter filter;
     void *filter_opaque;
     virConnectObjectEventGenericCallback cb;
@@ -138,6 +138,7 @@  virObjectEventCallbackFree(virObjectEventCallbackPtr cb)
         return;
 
     virObjectUnref(cb->conn);
+    VIR_FREE(cb->uuid);
     VIR_FREE(cb);
 }
 
@@ -192,7 +193,7 @@  virObjectEventCallbackListCount(virConnectPtr conn,
                                 virObjectEventCallbackListPtr cbList,
                                 virClassPtr klass,
                                 int eventID,
-                                unsigned char uuid[VIR_UUID_BUFLEN],
+                                const char *uuid,
                                 bool serverFilter)
 {
     size_t i;
@@ -209,8 +210,7 @@  virObjectEventCallbackListCount(virConnectPtr conn,
             !cb->deleted &&
             (!serverFilter ||
              (cb->remoteID >= 0 &&
-              ((uuid && cb->uuid_filter &&
-                memcmp(cb->uuid, uuid, VIR_UUID_BUFLEN) == 0) ||
+              ((uuid && cb->uuid_filter && STREQ(cb->uuid, uuid)) ||
                (!uuid && !cb->uuid_filter)))))
             ret++;
     }
@@ -326,7 +326,7 @@  virObjectEventCallbackListPurgeMarked(virObjectEventCallbackListPtr cbList)
 static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
 virObjectEventCallbackLookup(virConnectPtr conn,
                              virObjectEventCallbackListPtr cbList,
-                             unsigned char uuid[VIR_UUID_BUFLEN],
+                             const char *uuid,
                              virClassPtr klass,
                              int eventID,
                              virConnectObjectEventGenericCallback callback,
@@ -346,8 +346,7 @@  virObjectEventCallbackLookup(virConnectPtr conn,
         if (cb->klass == klass &&
             cb->eventID == eventID &&
             cb->conn == conn &&
-            ((uuid && cb->uuid_filter &&
-              memcmp(cb->uuid, uuid, VIR_UUID_BUFLEN) == 0) ||
+            ((uuid && cb->uuid_filter && STREQ(cb->uuid, uuid)) ||
              (!uuid && !cb->uuid_filter))) {
             if (remoteID)
                 *remoteID = cb->remoteID;
@@ -381,7 +380,7 @@  virObjectEventCallbackLookup(virConnectPtr conn,
 static int
 virObjectEventCallbackListAddID(virConnectPtr conn,
                                 virObjectEventCallbackListPtr cbList,
-                                unsigned char uuid[VIR_UUID_BUFLEN],
+                                const char *uuid,
                                 virObjectEventCallbackFilter filter,
                                 void *filter_opaque,
                                 virClassPtr klass,
@@ -434,7 +433,8 @@  virObjectEventCallbackListAddID(virConnectPtr conn,
      * Xen migration.  */
     if (uuid) {
         cb->uuid_filter = true;
-        memcpy(cb->uuid, uuid, VIR_UUID_BUFLEN);
+        if (VIR_STRDUP(cb->uuid, uuid) < 0)
+            goto cleanup;
     }
     cb->filter = filter;
     cb->filter_opaque = filter_opaque;
@@ -707,8 +707,10 @@  virObjectEventDispatchMatchCallback(virObjectEventPtr event,
          * 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 memcmp(event->meta.uuid, cb->uuid, VIR_UUID_BUFLEN) == 0;
+        return STREQ(uuidstr, cb->uuid);
     }
     return true;
 }
@@ -874,7 +876,7 @@  virObjectEventStateFlush(virObjectEventStatePtr state)
 int
 virObjectEventStateRegisterID(virConnectPtr conn,
                               virObjectEventStatePtr state,
-                              unsigned char *uuid,
+                              const char *uuid,
                               virObjectEventCallbackFilter filter,
                               void *filter_opaque,
                               virClassPtr klass,
diff --git a/src/conf/object_event_private.h b/src/conf/object_event_private.h
index a19a0d3..cae74ef 100644
--- a/src/conf/object_event_private.h
+++ b/src/conf/object_event_private.h
@@ -72,7 +72,7 @@  virClassForObjectEvent(void);
 int
 virObjectEventStateRegisterID(virConnectPtr conn,
                               virObjectEventStatePtr state,
-                              unsigned char *uuid,
+                              const char *uuid,
                               virObjectEventCallbackFilter filter,
                               void *filter_opaque,
                               virClassPtr klass,
diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c
index c5688be..de4f1ea 100644
--- a/src/conf/storage_event.c
+++ b/src/conf/storage_event.c
@@ -152,10 +152,14 @@  virStoragePoolEventStateRegisterID(virConnectPtr conn,
                                    virFreeCallback freecb,
                                    int *callbackID)
 {
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
     if (virStoragePoolEventsInitialize() < 0)
         return -1;
 
-    return virObjectEventStateRegisterID(conn, state, pool ? pool->uuid : NULL,
+    if (pool)
+        virUUIDFormat(pool->uuid, uuidstr);
+    return virObjectEventStateRegisterID(conn, state, pool ? uuidstr : NULL,
                                          NULL, NULL,
                                          virStoragePoolEventClass, eventID,
                                          VIR_OBJECT_EVENT_CALLBACK(cb),
@@ -192,10 +196,14 @@  virStoragePoolEventStateRegisterClient(virConnectPtr conn,
                                        virFreeCallback freecb,
                                        int *callbackID)
 {
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
     if (virStoragePoolEventsInitialize() < 0)
         return -1;
 
-    return virObjectEventStateRegisterID(conn, state,  pool ? pool->uuid : NULL,
+    if (pool)
+        virUUIDFormat(pool->uuid, uuidstr);
+    return virObjectEventStateRegisterID(conn, state, pool ? uuidstr : NULL,
                                          NULL, NULL,
                                          virStoragePoolEventClass, eventID,
                                          VIR_OBJECT_EVENT_CALLBACK(cb),