From patchwork Thu Jun 23 16:27:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 70773 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp518793qgy; Thu, 23 Jun 2016 09:31:23 -0700 (PDT) X-Received: by 10.194.162.168 with SMTP id yb8mr33341300wjb.32.1466699483894; Thu, 23 Jun 2016 09:31:23 -0700 (PDT) Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com. [209.132.183.25]) by mx.google.com with ESMTPS id e9si1104770wjd.201.2016.06.23.09.31.23 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 23 Jun 2016 09:31:23 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u5NGSLMT007303; Thu, 23 Jun 2016 12:28:21 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u5NGRvR2020080 for ; Thu, 23 Jun 2016 12:27:57 -0400 Received: from colepc.redhat.com (ovpn-116-65.rdu2.redhat.com [10.10.116.65]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5NGRs9O010505; Thu, 23 Jun 2016 12:27:56 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 23 Jun 2016 12:27:47 -0400 Message-Id: <4b062a329e41056bbde4d363178018df258fa94a.1466699232.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/6] events: Pass in UUID as a string X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com 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 --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),