From nobody Mon Feb 9 00:20:33 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 1491480706690427.298640960282; Thu, 6 Apr 2017 05:11:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D461C04B941; Thu, 6 Apr 2017 12:11:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 135129A592; Thu, 6 Apr 2017 12:11:45 +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 B6AB718523CC; Thu, 6 Apr 2017 12:11:44 +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 v36CAwKs002299 for ; Thu, 6 Apr 2017 08:10:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C838171D0; 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 F0ADB1719F for ; Thu, 6 Apr 2017 12:10:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3D461C04B941 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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 3D461C04B941 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 6 Apr 2017 08:10:49 -0400 Message-Id: <20170406121052.5815-6-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 5/8] util: Introduce 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 06 Apr 2017 12:11:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add the initial infrastructure to define a new object which will be a child of the virObjectLockable class that can be used to create an object that has two hash tables for object consumers to be able to utilize to store elements in one or two hash tables depending on the need to have more than one lookup mechanism for the same object TODO: Remove VIR_DEBUG's or add separately Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 72 ++++++++++++++++++++++++++++++++++++++++++++= +++- src/util/virobject.h | 29 +++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 92083e5..6861155 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2223,6 +2223,7 @@ virNumaSetupMemoryPolicy; # util/virobject.h virClassForObject; virClassForObjectLockable; +virClassForObjectPoolableHashTable; virClassIsDerivedFrom; virClassName; virClassNew; @@ -2234,6 +2235,7 @@ virObjectListFreeCount; virObjectLock; virObjectLockableNew; virObjectNew; +virObjectPoolableHashTableNew; virObjectRef; virObjectUnlock; virObjectUnref; diff --git a/src/util/virobject.c b/src/util/virobject.c index aea8a6d..d284dde 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -61,8 +61,11 @@ struct _virClass { =20 static virClassPtr virObjectClass; static virClassPtr virObjectLockableClass; +static virClassPtr virObjectPoolableHashTableClass; =20 static void virObjectLockableDispose(void *anyobj); +static void virObjectPoolableHashTableDispose(void *anyobj); + =20 static int virObjectOnceInit(void) @@ -79,6 +82,13 @@ virObjectOnceInit(void) virObjectLockableDispose))) return -1; =20 + if (!(virObjectPoolableHashTableClass =3D + virClassNew(virObjectLockableClass, + "virObjectPoolableHashTable", + sizeof(virObjectPoolableHashTable), + virObjectPoolableHashTableDispose))) + return -1; + return 0; } =20 @@ -96,6 +106,7 @@ virClassForObject(void) if (virObjectInitialize() < 0) return NULL; =20 + VIR_DEBUG("virObjectClass=3D%p", virObjectClass); return virObjectClass; } =20 @@ -111,11 +122,29 @@ virClassForObjectLockable(void) if (virObjectInitialize() < 0) return NULL; =20 + VIR_DEBUG("virObjectLockableClass=3D%p", virObjectLockableClass); return virObjectLockableClass; } =20 =20 /** + * virClassForObjectPoolableHashTable: + * + * Returns the class instance for the virObjectPoolableHashTable type + */ +virClassPtr +virClassForObjectPoolableHashTable(void) +{ + if (virObjectInitialize() < 0) + return NULL; + + VIR_DEBUG("virObjectPoolableHashTableClass=3D%p", + virObjectPoolableHashTableClass); + return virObjectPoolableHashTableClass; +} + + +/** * virClassNew: * @parent: the parent class * @name: the class name @@ -139,6 +168,9 @@ virClassNew(virClassPtr parent, { virClassPtr klass; =20 + VIR_DEBUG("parent=3D%p, name=3D%s, objectSize=3D%zu, dispose=3D%p", + parent, name, objectSize, dispose); + if (parent =3D=3D NULL && STRNEQ(name, "virObject")) { virReportInvalidNonNullArg(parent); @@ -246,6 +278,7 @@ virObjectLockableNew(virClassPtr klass) return NULL; } =20 + VIR_DEBUG("lockable new obj=3D%p", obj); return obj; } =20 @@ -255,10 +288,46 @@ virObjectLockableDispose(void *anyobj) { virObjectLockablePtr obj =3D anyobj; =20 + VIR_DEBUG("lockable dispose obj=3D%p", obj); virMutexDestroy(&obj->lock); } =20 =20 +void * +virObjectPoolableHashTableNew(virClassPtr klass, + virObjectPoolableHashTableObjType objtype) +{ + virObjectPoolableHashTablePtr obj; + + if (!virClassIsDerivedFrom(klass, virClassForObjectPoolableHashTable()= )) { + virReportInvalidArg(klass, + _("Class %s must derive from " + "virObjectPoolableHashTable"), + virClassName(klass)); + return NULL; + } + + if (!(obj =3D virObjectLockableNew(klass))) + return NULL; + + obj->objtype =3D objtype; + + VIR_DEBUG("poolable new obj=3D%p, type=3D%d", + obj, objtype); + + return obj; + +} + +static void +virObjectPoolableHashTableDispose(void *anyobj) +{ + virObjectPoolableHashTablePtr obj =3D anyobj; + + VIR_DEBUG("poolable dispose obj=3D%p", obj); +} + + /** * virObjectUnref: * @anyobj: any instance of virObjectPtr @@ -326,7 +395,8 @@ virObjectRef(void *anyobj) static virObjectLockablePtr virObjectGetLockableObj(void *anyobj) { - if (virObjectIsClass(anyobj, virObjectLockableClass)) + if (virObjectIsClass(anyobj, virObjectLockableClass) || + virObjectIsClass(anyobj, virObjectPoolableHashTableClass)) return anyobj; =20 VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLockableClass); diff --git a/src/util/virobject.h b/src/util/virobject.h index 89f8050..30ce6a1 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -23,6 +23,7 @@ # define __VIR_OBJECT_H__ =20 # include "internal.h" +# include "virhash.h" # include "virthread.h" =20 typedef struct _virClass virClass; @@ -34,6 +35,9 @@ typedef virObject *virObjectPtr; typedef struct _virObjectLockable virObjectLockable; typedef virObjectLockable *virObjectLockablePtr; =20 +typedef struct _virObjectPoolableHashTable virObjectPoolableHashTable; +typedef virObjectPoolableHashTable *virObjectPoolableHashTablePtr; + typedef void (*virObjectDisposeCallback)(void *obj); =20 /* Most code should not play with the contents of this struct; however, @@ -60,9 +64,29 @@ struct _virObjectLockable { virMutex lock; }; =20 +typedef enum { + VIR_OBJECTPOOLABLE_NODEDEVICE, + VIR_OBJECTPOOLABLE_INTERFACE, + VIR_OBJECTPOOLABLE_NWFILTER, + VIR_OBJECTPOOLABLE_VOLUME, + VIR_OBJECTPOOLABLE_BLOCK_STORAGE, + VIR_OBJECTPOOLABLE_SECRET, + VIR_OBJECTPOOLABLE_NETWORK, + VIR_OBJECTPOOLABLE_SNAPSHOT, + VIR_OBJECTPOOLABLE_DOMAIN, + + VIR_OBJECTPOOLABLE_LAST +} virObjectPoolableHashTableObjType; + +struct _virObjectPoolableHashTable { + virObjectLockable parent; + virObjectPoolableHashTableObjType objtype; +}; + =20 virClassPtr virClassForObject(void); virClassPtr virClassForObjectLockable(void); +virClassPtr virClassForObjectPoolableHashTable(void); =20 # ifndef VIR_PARENT_REQUIRED # define VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(1) @@ -109,6 +133,11 @@ void * virObjectLockableNew(virClassPtr klass) ATTRIBUTE_NONNULL(1); =20 +void * +virObjectPoolableHashTableNew(virClassPtr klass, + virObjectPoolableHashTableObjType objtype) + ATTRIBUTE_NONNULL(1); + void virObjectLock(void *lockableobj) ATTRIBUTE_NONNULL(1); --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list