From nobody Sat Feb 7 09:36:36 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 1498140188517123.33442013942806; Thu, 22 Jun 2017 07:03:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD6C81E305; Thu, 22 Jun 2017 14:03:05 +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 824554D72B; Thu, 22 Jun 2017 14:03:05 +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 24B694E98A; Thu, 22 Jun 2017 14:03:05 +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 v5ME2ut2004512 for ; Thu, 22 Jun 2017 10:02:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0665B5D967; Thu, 22 Jun 2017 14:02:56 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-36.phx2.redhat.com [10.3.116.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAC795D960 for ; Thu, 22 Jun 2017 14:02:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AD6C81E305 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.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 AD6C81E305 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 10:02:40 -0400 Message-Id: <20170622140246.31777-11-jferlan@redhat.com> In-Reply-To: <20170622140246.31777-1-jferlan@redhat.com> References: <20170622140246.31777-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 10/16] util: Introduce virObjectLookupHash{Add|Remove} 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 22 Jun 2017 14:03:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a pair of API's to add/remove the LookupKeys object to/from the LookupHash object. The caller must check return status and handle failure properly for the Add. The Remove API callers are all void functions, so only report the problem and ignore the attempt to remove if for some reason the passed @tableobj is not as expected. Signed-off-by: John Ferlan --- src/libvirt_private.syms | 2 ++ src/util/virobject.c | 80 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virobject.h | 8 +++++ 3 files changed, 90 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 28244ab..de986e5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2286,9 +2286,11 @@ virObjectListFree; virObjectListFreeCount; virObjectLock; virObjectLockableNew; +virObjectLookupHashAdd; virObjectLookupHashGetName; virObjectLookupHashGetUUID; virObjectLookupHashNew; +virObjectLookupHashRemove; virObjectLookupKeysGetName; virObjectLookupKeysGetUUID; virObjectLookupKeysIsActive; diff --git a/src/util/virobject.c b/src/util/virobject.c index 949a93d..9443dda 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -755,6 +755,86 @@ virObjectLookupKeysGetName(void *anyobj) =20 =20 /** + * virObjectLookupHashAdd: + * @tableobj: LookupHash object with objsUUID/objsName + * @obj: The LookupKeys object to insert in the hash table(s) + * + * Insert @obj into the hash tables found in @tableobj. + * + * Returns 0 on success, -1 on failure. + */ +int +virObjectLookupHashAdd(void *tableobj, + virObjectLookupKeysPtr obj) +{ + virObjectLookupHashPtr hashObj =3D virObjectGetLookupHashObj(tableobj); + + if (!hashObj) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("tableobj=3D%p is not a lookup hash object"), tab= leobj); + return -1; + } + + if (obj->uuid) { + if (virHashAddEntry(hashObj->objsUUID, obj->uuid, obj) < 0) + return -1; + virObjectRef(obj); + } + + if (obj->name) { + if (virHashAddEntry(hashObj->objsName, obj->name, obj) < 0) { + virHashRemoveEntry(hashObj->objsUUID, obj->uuid); + return -1; + } + virObjectRef(obj); + } + + return 0; +} + + +/** + * virObjectLookupHashRemove: + * @tableobj: LookupHash object with objsUUID/objsName + * @obj: The LookupKeys object to remove from the hash table(s) + * + * Remove @obj from the hash tables found in @tableobj. The common + * function to remove an object from a hash table will also cause + * the virObjectUnref to be called via virObjectFreeHashData since + * the virHashCreate used that as the Free object element argument. + * + * Even though this is a void, report the error for a bad @tableobj. + */ +void +virObjectLookupHashRemove(void *tableobj, + virObjectLookupKeysPtr obj) +{ + virObjectLookupHashPtr hashObj; + + if (!obj) + return; + + if (!(hashObj =3D virObjectGetLookupHashObj(tableobj))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("tableobj=3D%p is not a lookup hash object"), tab= leobj); + return; + } + + virObjectRef(obj); + virObjectUnlock(obj); + virObjectLock(tableobj); + virObjectLock(obj); + if (obj->uuid) + virHashRemoveEntry(hashObj->objsUUID, obj->uuid); + if (obj->name) + virHashRemoveEntry(hashObj->objsName, obj->name); + virObjectUnlock(obj); + virObjectUnref(obj); + virObjectUnlock(tableobj); +} + + +/** * virObjectLookupHashGetUUID * @anyobj: Pointer to a LookupHash object * diff --git a/src/util/virobject.h b/src/util/virobject.h index 7da680a..422c81e 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -179,6 +179,14 @@ virObjectLookupKeysGetUUID(void *anyobj); const char * virObjectLookupKeysGetName(void *anyobj); =20 +int +virObjectLookupHashAdd(void *tableobj, + virObjectLookupKeysPtr obj); + +void +virObjectLookupHashRemove(void *tableobj, + virObjectLookupKeysPtr obj); + virHashTablePtr virObjectLookupHashGetUUID(void *anyobj); =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list