From nobody Thu May 15 23:14:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1503093062518687.8436174502541; Fri, 18 Aug 2017 14:51:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74BEF81DE3; Fri, 18 Aug 2017 21:50:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEFC260BF2; Fri, 18 Aug 2017 21:50:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3781E3FC72; Fri, 18 Aug 2017 21:50:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7ILojv1004981 for ; Fri, 18 Aug 2017 17:50:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4667D5D962; Fri, 18 Aug 2017 21:50:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-120-47.rdu2.redhat.com [10.10.120.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1525B5D961 for ; Fri, 18 Aug 2017 21:50:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 74BEF81DE3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 18 Aug 2017 17:50:26 -0400 Message-Id: <20170818215041.8118-3-jferlan@redhat.com> In-Reply-To: <20170818215041.8118-1-jferlan@redhat.com> References: <20170818215041.8118-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 02/17] util: Introduce virObjectLookupKeys 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 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 18 Aug 2017 21:51:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a new virObjectLockable child virObjectLookupKeys that can be used by various driver/vir*obj consumers as the means to define the lookup keys for an object. The API requires that at least the @key1 argument is provided as non-NULL thus ensuring that there's at least one key. The keys will be used as input to a soon to be introduced hash table object that will support one or two hash tables and manage the various add, search, and remove functionality using the keys. The initial consumer will be the driver/vir*obj.c APIs which will make use of the keys via the @UUID or @Name that is used to uniquely describe the object. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 88 ++++++++++++++++++++++++++++++++++++++++++++= +++- src/util/virobject.h | 18 ++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2149b11..082a0ba 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2318,6 +2318,7 @@ virNumaSetupMemoryPolicy; # util/virobject.h virClassForObject; virClassForObjectLockable; +virClassForObjectLookupKeys; virClassForObjectRWLockable; virClassIsDerivedFrom; virClassName; @@ -2329,6 +2330,7 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLookupKeysNew; virObjectNew; virObjectRef; virObjectRWLockableNew; diff --git a/src/util/virobject.c b/src/util/virobject.c index 38db692..aec10eb 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -68,9 +68,11 @@ struct _virClass { static virClassPtr virObjectClass; static virClassPtr virObjectLockableClass; static virClassPtr virObjectRWLockableClass; +static virClassPtr virObjectLookupKeysClass; =20 static void virObjectLockableDispose(void *anyobj); static void virObjectRWLockableDispose(void *anyobj); +static void virObjectLookupKeysDispose(void *anyobj); =20 static int virObjectOnceInit(void) @@ -93,6 +95,12 @@ virObjectOnceInit(void) virObjectRWLockableDispos= e))) return -1; =20 + if (!(virObjectLookupKeysClass =3D virClassNew(virObjectLockableClass, + "virObjectLookupKeys", + sizeof(virObjectLookupKey= s), + virObjectLookupKeysDispos= e))) + return -1; + return 0; } =20 @@ -145,6 +153,21 @@ virClassForObjectRWLockable(void) =20 =20 /** + * virClassForObjectLookupKeys: + * + * Returns the class instance for the virObjectLookupKeys type + */ +virClassPtr +virClassForObjectLookupKeys(void) +{ + if (virObjectInitialize() < 0) + return NULL; + + return virObjectLookupKeysClass; +} + + +/** * virClassNew: * @parent: the parent class * @name: the class name @@ -328,6 +351,68 @@ virObjectRWLockableDispose(void *anyobj) =20 =20 /** + * virObjectLookupKeysNew: + * @klass: the klass to check + * @key1: key to be used for unique identifier (required) + * @key2: second key to be used as secondary unique identifier + * + * Create an object with at least @key1 as a means to provide input + * of an input object to add the object into a hash table. If @key2 is + * provided, then the object will exist into two hash tables for faster + * lookups by key for the table; otherwise, hash table searches would + * need to be used to find data from an object that matches some specific + * search the caller performs. + * + * Returns: New object on success, NULL on failure w/ error message set + */ +void * +virObjectLookupKeysNew(virClassPtr klass, + const char *key1, + const char *key2) +{ + virObjectLookupKeysPtr obj; + + if (!virClassIsDerivedFrom(klass, virClassForObjectLookupKeys())) { + virReportInvalidArg(klass, + _("Class %s must derive from virObjectLookupKe= ys"), + virClassName(klass)); + return NULL; + } + + if (!key1) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("key1 must be provided")); + return NULL; + } + + if (!(obj =3D virObjectLockableNew(klass))) + return NULL; + + if (VIR_STRDUP(obj->key1, key1) < 0) + goto error; + + if (VIR_STRDUP(obj->key2, key2) < 0) + goto error; + + return obj; + + error: + virObjectUnref(obj); + return NULL; +} + + +static void +virObjectLookupKeysDispose(void *anyobj) +{ + virObjectLookupKeysPtr obj =3D anyobj; + + VIR_FREE(obj->key1); + VIR_FREE(obj->key2); +} + + +/** * virObjectUnref: * @anyobj: any instance of virObjectPtr * @@ -393,7 +478,8 @@ virObjectRef(void *anyobj) static virObjectLockablePtr virObjectGetLockableObj(void *anyobj) { - if (virObjectIsClass(anyobj, virObjectLockableClass)) + if (virObjectIsClass(anyobj, virObjectLockableClass) || + virObjectIsClass(anyobj, virObjectLookupKeysClass)) return anyobj; =20 VIR_OBJECT_USAGE_PRINT_ERROR(anyobj, virObjectLockable); diff --git a/src/util/virobject.h b/src/util/virobject.h index ac6cf22..0f7d5ca 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -37,6 +37,9 @@ typedef virObjectLockable *virObjectLockablePtr; typedef struct _virObjectRWLockable virObjectRWLockable; typedef virObjectRWLockable *virObjectRWLockablePtr; =20 +typedef struct _virObjectLookupKeys virObjectLookupKeys; +typedef virObjectLookupKeys *virObjectLookupKeysPtr; + typedef void (*virObjectDisposeCallback)(void *obj); =20 /* Most code should not play with the contents of this struct; however, @@ -67,9 +70,18 @@ struct _virObjectRWLockable { virRWLock lock; }; =20 +struct _virObjectLookupKeys { + virObjectLockable parent; + + char *key1; + char *key2; +}; + + virClassPtr virClassForObject(void); virClassPtr virClassForObjectLockable(void); virClassPtr virClassForObjectRWLockable(void); +virClassPtr virClassForObjectLookupKeys(void); =20 # ifndef VIR_PARENT_REQUIRED # define VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(1) @@ -120,6 +132,12 @@ void * virObjectRWLockableNew(virClassPtr klass) ATTRIBUTE_NONNULL(1); =20 +void * +virObjectLookupKeysNew(virClassPtr klass, + const char *key1, + const char *key2) + ATTRIBUTE_NONNULL(1); + void virObjectLock(void *lockableobj) ATTRIBUTE_NONNULL(1); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list