From nobody Fri May 16 04:10:27 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 1499690822631544.6230371040265; Mon, 10 Jul 2017 05:47:02 -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 E6A804E4C3; Mon, 10 Jul 2017 12:47:00 +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 A47B361B8B; Mon, 10 Jul 2017 12:47:00 +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 4237A266; Mon, 10 Jul 2017 12:46:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6ACkuEn024828 for ; Mon, 10 Jul 2017 08:46:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6AA041797E; Mon, 10 Jul 2017 12:46:56 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id E46CB17A7B for ; Mon, 10 Jul 2017 12:46:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E6A804E4C3 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 E6A804E4C3 From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 10 Jul 2017 14:46:40 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/11] util/virhash: add name parameter to virHashSearch 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.38]); Mon, 10 Jul 2017 12:47:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" While searching for an element using a function it may be desirable to know the element key for future operation. Signed-off-by: Pavel Hrdina Reviewed-by: Jiri Denemark --- src/conf/virdomainobjlist.c | 2 +- src/conf/virnetworkobj.c | 4 ++-- src/conf/virsecretobj.c | 2 +- src/qemu/qemu_capabilities.c | 5 +++-- src/util/virhash.c | 11 ++++++++--- src/util/virhash.h | 2 +- src/xen/xm_internal.c | 5 +++-- tests/virhashtest.c | 2 +- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index c121382bcb..7bd4cd29b9 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -119,7 +119,7 @@ virDomainObjListFindByIDInternal(virDomainObjListPtr do= ms, { virDomainObjPtr obj; virObjectLock(doms); - obj =3D virHashSearch(doms->objs, virDomainObjListSearchID, &id); + obj =3D virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL); if (ref) { virObjectRef(obj); virObjectUnlock(doms); diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 88e42b5b3e..ccde72e727 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -208,7 +208,7 @@ virNetworkObjFindByNameLocked(virNetworkObjListPtr nets, { virNetworkObjPtr ret =3D NULL; =20 - ret =3D virHashSearch(nets->objs, virNetworkObjSearchName, name); + ret =3D virHashSearch(nets->objs, virNetworkObjSearchName, name, NULL); if (ret) virObjectRef(ret); return ret; @@ -980,7 +980,7 @@ virNetworkObjBridgeInUse(virNetworkObjListPtr nets, struct virNetworkObjBridgeInUseHelperData data =3D {bridge, skipname}; =20 virObjectLock(nets); - obj =3D virHashSearch(nets->objs, virNetworkObjBridgeInUseHelper, &dat= a); + obj =3D virHashSearch(nets->objs, virNetworkObjBridgeInUseHelper, &dat= a, NULL); virObjectUnlock(nets); =20 return obj !=3D NULL; diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 0311335ba3..8ba8784d1e 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -251,7 +251,7 @@ virSecretObjListFindByUsageLocked(virSecretObjListPtr s= ecrets, struct virSecretSearchData data =3D { .usageType =3D usageType, .usageID =3D usageID }; =20 - obj =3D virHashSearch(secrets->objs, virSecretObjSearchName, &data); + obj =3D virHashSearch(secrets->objs, virSecretObjSearchName, &data, NU= LL); if (obj) virObjectRef(obj); return obj; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 61c9a10661..6659744a34 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5504,14 +5504,15 @@ virQEMUCapsCacheLookupByArch(virCapsPtr caps, struct virQEMUCapsSearchData data =3D { .arch =3D arch }; =20 virMutexLock(&cache->lock); - ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data); + ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch, &data, = NULL); if (!ret) { /* If the first attempt at finding capabilities has failed, try * again using the QEMU target as lookup key instead */ target =3D virQEMUCapsFindTarget(virArchFromHost(), data.arch); if (target !=3D data.arch) { data.arch =3D target; - ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch,= &data); + ret =3D virHashSearch(cache->binaries, virQEMUCapsCompareArch, + &data, NULL); } } =20 diff --git a/src/util/virhash.c b/src/util/virhash.c index a8e0edfd3b..7fa2992f18 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -702,15 +702,18 @@ virHashRemoveAll(virHashTablePtr table) * @table: the hash table to search * @iter: an iterator to identify the desired element * @data: extra opaque information passed to the iter + * @name: the name of found user data, pass NULL to ignore * * Iterates over the hash table calling the 'iter' callback * for each element. The first element for which the iter * returns non-zero will be returned by this function. - * The elements are processed in a undefined order + * The elements are processed in a undefined order. Caller is + * responsible for freeing the @name. */ void *virHashSearch(const virHashTable *ctable, virHashSearcher iter, - const void *data) + const void *data, + void **name) { size_t i; =20 @@ -730,6 +733,8 @@ void *virHashSearch(const virHashTable *ctable, for (entry =3D table->table[i]; entry; entry =3D entry->next) { if (iter(entry->payload, entry->name, data)) { table->iterating =3D false; + if (name) + *name =3D table->keyCopy(entry->name); return entry->payload; } } @@ -824,7 +829,7 @@ bool virHashEqual(const virHashTable *table1, virHashSize(table1) !=3D virHashSize(table2)) return false; =20 - virHashSearch(table1, virHashEqualSearcher, &data); + virHashSearch(table1, virHashEqualSearcher, &data, NULL); =20 return data.equal; } diff --git a/src/util/virhash.h b/src/util/virhash.h index 61c172b9e0..00b2550e70 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -194,7 +194,7 @@ bool virHashEqual(const virHashTable *table1, int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data= ); ssize_t virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, cons= t void *data); void *virHashSearch(const virHashTable *table, virHashSearcher iter, - const void *data); + const void *data, void **name); =20 /* Convenience for when VIR_FREE(value) is sufficient as a data freer. */ void virHashValueFree(void *value, const void *name); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index fba814aa19..123f379572 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -880,7 +880,8 @@ xenXMDomainLookupByUUID(virConnectPtr conn, const unsig= ned char *uuid) if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh(conn) < 0) goto cleanup; =20 - if (!(entry =3D virHashSearch(priv->configCache, xenXMDomainSearchForU= UID, (const void *)uuid))) + if (!(entry =3D virHashSearch(priv->configCache, xenXMDomainSearchForU= UID, + (const void *)uuid, NULL))) goto cleanup; =20 ret =3D virDomainDefNewFull(entry->def->name, uuid, -1); @@ -971,7 +972,7 @@ xenXMDomainDefineXML(virConnectPtr conn, virDomainDefPt= r def) * it has the same name */ if ((entry =3D virHashSearch(priv->configCache, xenXMDomainSearchForUU= ID, - (const void *)&(def->uuid))) !=3D NULL) { + (const void *)&(def->uuid), NULL)) !=3D NUL= L) { if ((entry->def !=3D NULL) && (entry->def->name !=3D NULL) && (STRNEQ(def->name, entry->def->name))) { char uuidstr[VIR_UUID_STRING_BUFLEN]; diff --git a/tests/virhashtest.c b/tests/virhashtest.c index dbf07ae7f7..9407f98c4b 100644 --- a/tests/virhashtest.c +++ b/tests/virhashtest.c @@ -436,7 +436,7 @@ testHashSearch(const void *data ATTRIBUTE_UNUSED) if (!(hash =3D testHashInit(0))) return -1; =20 - entry =3D virHashSearch(hash, testHashSearchIter, NULL); + entry =3D virHashSearch(hash, testHashSearchIter, NULL, NULL); =20 if (!entry || STRNEQ(uuids_subset[testSearchIndex], entry)) { VIR_TEST_VERBOSE("\nvirHashSearch didn't find entry '%s'\n", --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list