events: Pass in UUID as a string

This should not have any functional difference, it's just a step
towards matching on non-uuid string keys
This commit is contained in:
Cole Robinson 2016-06-23 11:50:05 -04:00
parent 7926c5a5be
commit d7c96a7245
5 changed files with 48 additions and 19 deletions

View File

@ -1998,10 +1998,14 @@ virDomainEventStateRegisterID(virConnectPtr conn,
virFreeCallback freecb, virFreeCallback freecb,
int *callbackID) int *callbackID)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virDomainEventsInitialize() < 0) if (virDomainEventsInitialize() < 0)
return -1; 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, NULL, NULL,
virDomainEventClass, eventID, virDomainEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb), VIR_OBJECT_EVENT_CALLBACK(cb),
@ -2042,10 +2046,14 @@ virDomainEventStateRegisterClient(virConnectPtr conn,
int *callbackID, int *callbackID,
bool remoteID) bool remoteID)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virDomainEventsInitialize() < 0) if (virDomainEventsInitialize() < 0)
return -1; 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, NULL, NULL,
virDomainEventClass, eventID, virDomainEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb), VIR_OBJECT_EVENT_CALLBACK(cb),
@ -2180,6 +2188,7 @@ virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
{ {
virDomainQemuMonitorEventData *data = NULL; virDomainQemuMonitorEventData *data = NULL;
virObjectEventCallbackFilter filter = NULL; virObjectEventCallbackFilter filter = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virDomainEventsInitialize() < 0) if (virDomainEventsInitialize() < 0)
return -1; return -1;
@ -2220,7 +2229,9 @@ virDomainQemuMonitorEventStateRegisterID(virConnectPtr conn,
filter = virDomainQemuMonitorEventFilter; filter = virDomainQemuMonitorEventFilter;
freecb = virDomainQemuMonitorEventCleanup; 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, filter, data,
virDomainQemuMonitorEventClass, 0, virDomainQemuMonitorEventClass, 0,
VIR_OBJECT_EVENT_CALLBACK(cb), VIR_OBJECT_EVENT_CALLBACK(cb),

View File

@ -150,10 +150,14 @@ virNetworkEventStateRegisterID(virConnectPtr conn,
virFreeCallback freecb, virFreeCallback freecb,
int *callbackID) int *callbackID)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virNetworkEventsInitialize() < 0) if (virNetworkEventsInitialize() < 0)
return -1; 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, NULL, NULL,
virNetworkEventClass, eventID, virNetworkEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb), VIR_OBJECT_EVENT_CALLBACK(cb),
@ -190,10 +194,14 @@ virNetworkEventStateRegisterClient(virConnectPtr conn,
virFreeCallback freecb, virFreeCallback freecb,
int *callbackID) int *callbackID)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virNetworkEventsInitialize() < 0) if (virNetworkEventsInitialize() < 0)
return -1; 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, NULL, NULL,
virNetworkEventClass, eventID, virNetworkEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb), VIR_OBJECT_EVENT_CALLBACK(cb),

View File

@ -45,7 +45,7 @@ struct _virObjectEventCallback {
virConnectPtr conn; virConnectPtr conn;
int remoteID; int remoteID;
bool uuid_filter; bool uuid_filter;
unsigned char uuid[VIR_UUID_BUFLEN]; char *uuid;
virObjectEventCallbackFilter filter; virObjectEventCallbackFilter filter;
void *filter_opaque; void *filter_opaque;
virConnectObjectEventGenericCallback cb; virConnectObjectEventGenericCallback cb;
@ -138,6 +138,7 @@ virObjectEventCallbackFree(virObjectEventCallbackPtr cb)
return; return;
virObjectUnref(cb->conn); virObjectUnref(cb->conn);
VIR_FREE(cb->uuid);
VIR_FREE(cb); VIR_FREE(cb);
} }
@ -192,7 +193,7 @@ virObjectEventCallbackListCount(virConnectPtr conn,
virObjectEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
virClassPtr klass, virClassPtr klass,
int eventID, int eventID,
unsigned char uuid[VIR_UUID_BUFLEN], const char *uuid,
bool serverFilter) bool serverFilter)
{ {
size_t i; size_t i;
@ -209,8 +210,7 @@ virObjectEventCallbackListCount(virConnectPtr conn,
!cb->deleted && !cb->deleted &&
(!serverFilter || (!serverFilter ||
(cb->remoteID >= 0 && (cb->remoteID >= 0 &&
((uuid && cb->uuid_filter && ((uuid && cb->uuid_filter && STREQ(cb->uuid, uuid)) ||
memcmp(cb->uuid, uuid, VIR_UUID_BUFLEN) == 0) ||
(!uuid && !cb->uuid_filter))))) (!uuid && !cb->uuid_filter)))))
ret++; ret++;
} }
@ -326,7 +326,7 @@ virObjectEventCallbackListPurgeMarked(virObjectEventCallbackListPtr cbList)
static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
virObjectEventCallbackLookup(virConnectPtr conn, virObjectEventCallbackLookup(virConnectPtr conn,
virObjectEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
unsigned char uuid[VIR_UUID_BUFLEN], const char *uuid,
virClassPtr klass, virClassPtr klass,
int eventID, int eventID,
virConnectObjectEventGenericCallback callback, virConnectObjectEventGenericCallback callback,
@ -346,8 +346,7 @@ virObjectEventCallbackLookup(virConnectPtr conn,
if (cb->klass == klass && if (cb->klass == klass &&
cb->eventID == eventID && cb->eventID == eventID &&
cb->conn == conn && cb->conn == conn &&
((uuid && cb->uuid_filter && ((uuid && cb->uuid_filter && STREQ(cb->uuid, uuid)) ||
memcmp(cb->uuid, uuid, VIR_UUID_BUFLEN) == 0) ||
(!uuid && !cb->uuid_filter))) { (!uuid && !cb->uuid_filter))) {
if (remoteID) if (remoteID)
*remoteID = cb->remoteID; *remoteID = cb->remoteID;
@ -381,7 +380,7 @@ virObjectEventCallbackLookup(virConnectPtr conn,
static int static int
virObjectEventCallbackListAddID(virConnectPtr conn, virObjectEventCallbackListAddID(virConnectPtr conn,
virObjectEventCallbackListPtr cbList, virObjectEventCallbackListPtr cbList,
unsigned char uuid[VIR_UUID_BUFLEN], const char *uuid,
virObjectEventCallbackFilter filter, virObjectEventCallbackFilter filter,
void *filter_opaque, void *filter_opaque,
virClassPtr klass, virClassPtr klass,
@ -434,7 +433,8 @@ virObjectEventCallbackListAddID(virConnectPtr conn,
* Xen migration. */ * Xen migration. */
if (uuid) { if (uuid) {
cb->uuid_filter = true; 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 = filter;
cb->filter_opaque = filter_opaque; cb->filter_opaque = filter_opaque;
@ -707,8 +707,10 @@ virObjectEventDispatchMatchCallback(virObjectEventPtr event,
* running & shutoff states & ignoring 'name' since * running & shutoff states & ignoring 'name' since
* Xen sometimes renames guests during migration, thus * Xen sometimes renames guests during migration, thus
* leaving 'uuid' as the only truly reliable ID we can use. */ * 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; return true;
} }
@ -874,7 +876,7 @@ virObjectEventStateFlush(virObjectEventStatePtr state)
int int
virObjectEventStateRegisterID(virConnectPtr conn, virObjectEventStateRegisterID(virConnectPtr conn,
virObjectEventStatePtr state, virObjectEventStatePtr state,
unsigned char *uuid, const char *uuid,
virObjectEventCallbackFilter filter, virObjectEventCallbackFilter filter,
void *filter_opaque, void *filter_opaque,
virClassPtr klass, virClassPtr klass,

View File

@ -72,7 +72,7 @@ virClassForObjectEvent(void);
int int
virObjectEventStateRegisterID(virConnectPtr conn, virObjectEventStateRegisterID(virConnectPtr conn,
virObjectEventStatePtr state, virObjectEventStatePtr state,
unsigned char *uuid, const char *uuid,
virObjectEventCallbackFilter filter, virObjectEventCallbackFilter filter,
void *filter_opaque, void *filter_opaque,
virClassPtr klass, virClassPtr klass,

View File

@ -183,10 +183,14 @@ virStoragePoolEventStateRegisterID(virConnectPtr conn,
virFreeCallback freecb, virFreeCallback freecb,
int *callbackID) int *callbackID)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virStoragePoolEventsInitialize() < 0) if (virStoragePoolEventsInitialize() < 0)
return -1; 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, NULL, NULL,
virStoragePoolEventClass, eventID, virStoragePoolEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb), VIR_OBJECT_EVENT_CALLBACK(cb),
@ -223,10 +227,14 @@ virStoragePoolEventStateRegisterClient(virConnectPtr conn,
virFreeCallback freecb, virFreeCallback freecb,
int *callbackID) int *callbackID)
{ {
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (virStoragePoolEventsInitialize() < 0) if (virStoragePoolEventsInitialize() < 0)
return -1; 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, NULL, NULL,
virStoragePoolEventClass, eventID, virStoragePoolEventClass, eventID,
VIR_OBJECT_EVENT_CALLBACK(cb), VIR_OBJECT_EVENT_CALLBACK(cb),