From nobody Mon Feb 9 05:40:01 2026 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.zoho.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 1491480710007305.0595034654061; Thu, 6 Apr 2017 05:11:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3E6D7E9E6; Thu, 6 Apr 2017 12:11:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A6D5A863F; Thu, 6 Apr 2017 12:11:48 +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 361AE5ED65; Thu, 6 Apr 2017 12:11:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v36CAwju002309 for ; Thu, 6 Apr 2017 08:10:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id A4BB41719F; Thu, 6 Apr 2017 12:10:58 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-19.phx2.redhat.com [10.3.116.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64403171D7 for ; Thu, 6 Apr 2017 12:10:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A3E6D7E9E6 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A3E6D7E9E6 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 08:10:50 -0400 Message-Id: <20170406121052.5815-7-jferlan@redhat.com> In-Reply-To: <20170406121052.5815-1-jferlan@redhat.com> References: <20170406121052.5815-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 6/8] util: Add the hash tables to virObjectPoolableHashTable 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 06 Apr 2017 12:11:49 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a pair of hash tables to the object - a primary and a secondary one. If the consumer requested only a primary, then only it will be created. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 78 ++++++++++++++++++++++++++++++++++++++++++++= +--- src/util/virobject.h | 22 +++++++++++++- 3 files changed, 97 insertions(+), 5 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6861155..9b3345a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2235,6 +2235,8 @@ virObjectListFreeCount; virObjectLock; virObjectLockableNew; virObjectNew; +virObjectPoolableHashTableGetPrimary; +virObjectPoolableHashTableGetSecondary; virObjectPoolableHashTableNew; virObjectRef; virObjectUnlock; diff --git a/src/util/virobject.c b/src/util/virobject.c index d284dde..625bf90 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -295,7 +295,9 @@ virObjectLockableDispose(void *anyobj) =20 void * virObjectPoolableHashTableNew(virClassPtr klass, - virObjectPoolableHashTableObjType objtype) + virObjectPoolableHashTableObjType objtype, + int tableElemsStart, + bool primaryOnly) { virObjectPoolableHashTablePtr obj; =20 @@ -311,20 +313,39 @@ virObjectPoolableHashTableNew(virClassPtr klass, return NULL; =20 obj->objtype =3D objtype; + obj->tableElemsStart =3D tableElemsStart; =20 - VIR_DEBUG("poolable new obj=3D%p, type=3D%d", - obj, objtype); + if (!(obj->objsPrimary =3D virHashCreate(tableElemsStart, + virObjectFreeHashData))) + goto error; + + if (!primaryOnly && + !(obj->objsSecondary =3D virHashCreate(tableElemsStart, + virObjectFreeHashData))) + goto error; + + + VIR_DEBUG("obj=3D%p, type=3D%d, elems=3D%d objsPrimary=3D%p objsSecond= ary=3D%p", + obj, objtype, tableElemsStart, + obj->objsPrimary, obj->objsSecondary); =20 return obj; =20 + error: + virObjectUnref(obj); + return NULL; } =20 + static void virObjectPoolableHashTableDispose(void *anyobj) { virObjectPoolableHashTablePtr obj =3D anyobj; =20 VIR_DEBUG("poolable dispose obj=3D%p", obj); + + virHashFree(obj->objsPrimary); + virHashFree(obj->objsSecondary); } =20 =20 @@ -402,7 +423,6 @@ virObjectGetLockableObj(void *anyobj) VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLockableClass); =20 return NULL; - } =20 =20 @@ -557,3 +577,53 @@ virObjectListFreeCount(void *list, =20 VIR_FREE(list); } + + +static virObjectPoolableHashTablePtr +virObjectGetPoolableHashTableObj(void *anyobj) +{ + if (virObjectIsClass(anyobj, virObjectPoolableHashTableClass)) + return anyobj; + + VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectPoolableHashTableClass= ); + + return NULL; +} + + +/** + * virObjectPoolableHashTableGetPrimary + * @anyobj: Pointer to a PoolableHashTable object + * + * Returns: Pointer to the Primary Hash Table or NULL on failure + */ +virHashTablePtr +virObjectPoolableHashTableGetPrimary(void *anyobj) +{ + virObjectPoolableHashTablePtr obj =3D + virObjectGetPoolableHashTableObj(anyobj); + + if (!obj) + return NULL; + + return obj->objsPrimary; +} + + +/** + * virObjectPoolableHashTableGetSecondary + * @anyobj: Pointer to a PoolableHashTable object + * + * Returns: Pointer to the Secondary Hash Table or NULL on failure + */ +virHashTablePtr +virObjectPoolableHashTableGetSecondary(void *anyobj) +{ + virObjectPoolableHashTablePtr obj =3D + virObjectGetPoolableHashTableObj(anyobj); + + if (!obj) + return NULL; + + return obj->objsSecondary; +} diff --git a/src/util/virobject.h b/src/util/virobject.h index 30ce6a1..ac21190 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -81,6 +81,18 @@ typedef enum { struct _virObjectPoolableHashTable { virObjectLockable parent; virObjectPoolableHashTableObjType objtype; + + int tableElemsStart; + + /* primary key -> object mapping for O(1), + * lockless lookup-by-primary */ + virHashTable *objsPrimary; + + /* uuid string -> virPoolObj mapping + * for O(1), lockless lookup-by-uuid */ + /* secondary key -> object mapping for O(1), + * lockless lookup-by-secondary */ + virHashTable *objsSecondary; }; =20 =20 @@ -135,7 +147,9 @@ virObjectLockableNew(virClassPtr klass) =20 void * virObjectPoolableHashTableNew(virClassPtr klass, - virObjectPoolableHashTableObjType objtype) + virObjectPoolableHashTableObjType objtype, + int tableElemsStart, + bool primaryOnly) ATTRIBUTE_NONNULL(1); =20 void @@ -153,4 +167,10 @@ void virObjectListFreeCount(void *list, size_t count); =20 +virHashTablePtr +virObjectPoolableHashTableGetPrimary(void *anyobj); + +virHashTablePtr +virObjectPoolableHashTableGetSecondary(void *anyobj); + #endif /* __VIR_OBJECT_H */ --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list