From patchwork Thu Jun 23 16:27:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 70771 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp518690qgy; Thu, 23 Jun 2016 09:31:13 -0700 (PDT) X-Received: by 10.194.239.163 with SMTP id vt3mr30141146wjc.78.1466699471607; Thu, 23 Jun 2016 09:31:11 -0700 (PDT) Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com. [209.132.183.24]) by mx.google.com with ESMTPS id y13si7413062wmh.72.2016.06.23.09.31.10 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 23 Jun 2016 09:31:11 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 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 mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u5NGSD8x007431; Thu, 23 Jun 2016 12:28:14 -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 u5NGRvw7020085 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 u5NGRs9P010505; Thu, 23 Jun 2016 12:27:57 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 23 Jun 2016 12:27:48 -0400 Message-Id: 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 5/6] events: Add explicit lookup 'key' value 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 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 | 11 +++++++++-- src/conf/network_event.c | 4 +++- src/conf/object_event.c | 23 +++++++++++------------ src/conf/object_event_private.h | 6 ++++-- src/conf/storage_event.c | 4 +++- 5 files changed, 30 insertions(+), 18 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 7ad6d2c..63ae9e1 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -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 */ diff --git a/src/conf/network_event.c b/src/conf/network_event.c index 21f6db1..e0d1a3d 100644 --- a/src/conf/network_event.c +++ b/src/conf/network_event.c @@ -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; diff --git a/src/conf/object_event.c b/src/conf/object_event.c index 8fd182d..5734230 100644 --- a/src/conf/object_event.c +++ b/src/conf/object_event.c @@ -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; } diff --git a/src/conf/object_event_private.h b/src/conf/object_event_private.h index cae74ef..95b2120 100644 --- a/src/conf/object_event_private.h +++ b/src/conf/object_event_private.h @@ -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 diff --git a/src/conf/storage_event.c b/src/conf/storage_event.c index de4f1ea..cb97c90 100644 --- a/src/conf/storage_event.c +++ b/src/conf/storage_event.c @@ -228,14 +228,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;