From nobody Wed May 14 22:09:45 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 1515528467485840.085273026209; Tue, 9 Jan 2018 12:07:47 -0800 (PST) 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 20E3F61BB2; Tue, 9 Jan 2018 20:07:46 +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 687D85D9C6; Tue, 9 Jan 2018 20:07: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 77F94410B5; Tue, 9 Jan 2018 20:07:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w09K644M030566 for ; Tue, 9 Jan 2018 15:06:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id 510D77F7F7; Tue, 9 Jan 2018 20:06:04 +0000 (UTC) Received: from unknown4ceb42c824f4.attlocal.net.com (ovpn-116-205.phx2.redhat.com [10.3.116.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EE1760FB9 for ; Tue, 9 Jan 2018 20:06:03 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 9 Jan 2018 15:05:52 -0500 Message-Id: <20180109200553.22516-4-jferlan@redhat.com> In-Reply-To: <20180109200553.22516-1-jferlan@redhat.com> References: <20180109200553.22516-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] storage: Introduce _virStorageVolObj[List] 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.39]); Tue, 09 Jan 2018 20:07:46 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Prepare for hash table volume lists by creating the object infrastructure for a Volume Object and Volume Object List The _virStorageVolObj will contain just a pointer to the "current" (and live) volume definition. The _virStorageVolObjList will contain three hash tables, one for each of the lookup options allowed for a volume. Signed-off-by: John Ferlan --- src/conf/virstorageobj.c | 130 +++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 130 insertions(+) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 1eaa53423..8a1c6f782 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -39,11 +39,18 @@ VIR_LOG_INIT("conf.virstorageobj"); =20 static virClassPtr virStoragePoolObjClass; static virClassPtr virStoragePoolObjListClass; +static virClassPtr virStorageVolObjClass; +static virClassPtr virStorageVolObjListClass; =20 static void virStoragePoolObjDispose(void *opaque); static void virStoragePoolObjListDispose(void *opaque); +static void +virStorageVolObjDispose(void *opaque); +static void +virStorageVolObjListDispose(void *opaque); + =20 =20 struct _virStorageVolDefList { @@ -51,6 +58,32 @@ struct _virStorageVolDefList { virStorageVolDefPtr *objs; }; =20 +typedef struct _virStorageVolObj virStorageVolObj; +typedef virStorageVolObj *virStorageVolObjPtr; +struct _virStorageVolObj { + virObjectLockable parent; + + virStorageVolDefPtr voldef; +}; + +typedef struct _virStorageVolObjList virStorageVolObjList; +typedef virStorageVolObjList *virStorageVolObjListPtr; +struct _virStorageVolObjList { + virObjectRWLockable parent; + + /* key string -> virStorageVolObj mapping + * for (1), lockless lookup-by-key */ + virHashTable *objsKey; + + /* name string -> virStorageVolObj mapping + * for (1), lockless lookup-by-name */ + virHashTable *objsName; + + /* path string -> virStorageVolObj mapping + * for (1), lockless lookup-by-path */ + virHashTable *objsPath; +}; + struct _virStoragePoolObj { virObjectLockable parent; =20 @@ -80,6 +113,103 @@ struct _virStoragePoolObjList { =20 =20 static int +virStorageVolObjOnceInit(void) +{ + if (!(virStorageVolObjClass =3D virClassNew(virClassForObjectLockable(= ), + "virStorageVolObj", + sizeof(virStorageVolObj), + virStorageVolObjDispose))) + return -1; + + if (!(virStorageVolObjListClass =3D virClassNew(virClassForObjectRWLoc= kable(), + "virStorageVolObjList", + sizeof(virStorageVolObjL= ist), + virStorageVolObjListDisp= ose))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virStorageVolObj) + + +static virStorageVolObjPtr ATTRIBUTE_UNUSED +virStorageVolObjNew(void) +{ + virStorageVolObjPtr obj; + + if (virStorageVolObjInitialize() < 0) + return NULL; + + if (!(obj =3D virObjectLockableNew(virStorageVolObjClass))) + return NULL; + + virObjectLock(obj); + return obj; +} + + +static void ATTRIBUTE_UNUSED +virStorageVolObjEndAPI(virStorageVolObjPtr *obj) +{ + if (!*obj) + return; + + virObjectUnlock(*obj); + virObjectUnref(*obj); + *obj =3D NULL; +} + + +static void +virStorageVolObjDispose(void *opaque) +{ + virStorageVolObjPtr obj =3D opaque; + + if (!obj) + return; + + virStorageVolDefFree(obj->voldef); +} + + +static virStorageVolObjListPtr ATTRIBUTE_UNUSED +virStorageVolObjListNew(void) +{ + virStorageVolObjListPtr vols; + + if (virStorageVolObjInitialize() < 0) + return NULL; + + if (!(vols =3D virObjectRWLockableNew(virStorageVolObjListClass))) + return NULL; + + if (!(vols->objsKey =3D virHashCreate(10, virObjectFreeHashData)) || + !(vols->objsName =3D virHashCreate(10, virObjectFreeHashData)) || + !(vols->objsPath =3D virHashCreate(10, virObjectFreeHashData))) { + virObjectUnref(vols); + return NULL; + } + + return vols; +} + + +static void +virStorageVolObjListDispose(void *opaque) +{ + virStorageVolObjListPtr vols =3D opaque; + + if (!vols) + return; + + virHashFree(vols->objsKey); + virHashFree(vols->objsName); + virHashFree(vols->objsPath); +} + + +static int virStoragePoolObjOnceInit(void) { if (!(virStoragePoolObjClass =3D virClassNew(virClassForObjectLockable= (), --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list