From nobody Fri Dec 19 04:16:59 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571415095; cv=none; d=zoho.com; s=zohoarc; b=b3v+JA5ewG4S3cyey8cZvIYzRFnjzTE9e6LFsBp2Bl6jmTwIMBloTyas+ynXJtrN8WZHxtWGqOUOSYafTC63TTCkuER5DFKomYS2jICfh/w3CORdLZ58ROr4kFp3Sho5EYx/tVDUl6f1GFeB+KLBpzBBDgjri/GR1+e9Pbo8vEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571415095; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=b4oD466FMOh7yKZ6bVmMCAcStHLaPBH6xXaWXbn9Lag=; b=SP/nZCRe2G+Xjy7s1XzLOgCtlgBfURWUGejsSuAa7qfv31BAP3IIS0nl0qTqWBgvx26JudRI6Lgc9cP5sjiEkn1CQwZrLtWgWEaWqtzPcwXkZisDvNIfnglx0+rqmDVP7/SFmVKG+daN9nzIiMIqLFcAczNhvrXgHabgr/E2/kw= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1571415095834171.90440940463543; Fri, 18 Oct 2019 09:11:35 -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 EF8272B87; Fri, 18 Oct 2019 16:11:33 +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 C11B460C4E; Fri, 18 Oct 2019 16:11:33 +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 56AAB4EE68; Fri, 18 Oct 2019 16:11:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9IGBU21004533 for ; Fri, 18 Oct 2019 12:11:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 83AA4601B3; Fri, 18 Oct 2019 16:11:30 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7850600C8; Fri, 18 Oct 2019 16:11:29 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 18 Oct 2019 18:10:46 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH RFC 01/40] util: hash: Add possibility to use simpler data free function in virHash 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: , 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.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 18 Oct 2019 16:11:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce a new type virHashDataFreeSimple which has only a void * as argument for cases when knowing the name of the entry when freeing the hash entry is not required. Signed-off-by: Peter Krempa --- src/conf/domain_addr.c | 4 ++-- src/util/vircgroup.c | 2 +- src/util/virhash.c | 15 ++++++++++++++- src/util/virhash.h | 10 ++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index d0026942aa..dd8e04576a 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1037,14 +1037,14 @@ virDomainPCIAddressSetExtensionAlloc(virDomainPCIAd= dressSetPtr addrs, if (VIR_ALLOC(addrs->zpciIds) < 0) return -1; - if (!(addrs->zpciIds->uids =3D virHashCreateFull(10, NULL, + if (!(addrs->zpciIds->uids =3D virHashCreateFull(10, NULL, NULL, virZPCIAddrKeyCode, virZPCIAddrKeyEqual, virZPCIAddrKeyCopy, virZPCIAddrKeyFree)= )) goto error; - if (!(addrs->zpciIds->fids =3D virHashCreateFull(10, NULL, + if (!(addrs->zpciIds->fids =3D virHashCreateFull(10, NULL, NULL, virZPCIAddrKeyCode, virZPCIAddrKeyEqual, virZPCIAddrKeyCopy, diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index d824aee86d..21c0fe67e3 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2600,7 +2600,7 @@ virCgroupKillRecursive(virCgroupPtr group, int signum) bool backendAvailable =3D false; virCgroupBackendPtr *backends =3D virCgroupBackendGetAll(); virHashTablePtr pids =3D virHashCreateFull(100, - NULL, + NULL, NULL, virCgroupPidCode, virCgroupPidEqual, virCgroupPidCopy, diff --git a/src/util/virhash.c b/src/util/virhash.c index a7fc620567..4d90fa5333 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -56,6 +56,7 @@ struct _virHashTable { size_t size; size_t nbElems; virHashDataFree dataFree; + virHashDataFreeSimple dataFreeSimple; virHashKeyCode keyCode; virHashKeyEqual keyEqual; virHashKeyCopy keyCopy; @@ -133,6 +134,7 @@ virHashComputeKey(const virHashTable *table, const void= *name) */ virHashTablePtr virHashCreateFull(ssize_t size, virHashDataFree dataFree, + virHashDataFreeSimple dataFreeSimple, virHashKeyCode keyCode, virHashKeyEqual keyEqual, virHashKeyCopy keyCopy, @@ -149,7 +151,10 @@ virHashTablePtr virHashCreateFull(ssize_t size, table->seed =3D virRandomBits(32); table->size =3D size; table->nbElems =3D 0; - table->dataFree =3D dataFree; + if (dataFree) + table->dataFree =3D dataFree; + else + table->dataFreeSimple =3D dataFreeSimple; table->keyCode =3D keyCode; table->keyEqual =3D keyEqual; table->keyCopy =3D keyCopy; @@ -177,6 +182,7 @@ virHashTablePtr virHashCreate(ssize_t size, virHashData= Free dataFree) { return virHashCreateFull(size, dataFree, + NULL, virHashStrCode, virHashStrEqual, virHashStrCopy, @@ -298,6 +304,8 @@ virHashFree(virHashTablePtr table) if (table->dataFree) table->dataFree(iter->payload, iter->name); + if (table->dataFreeSimple) + table->dataFreeSimple(iter->payload); if (table->keyFree) table->keyFree(iter->name); VIR_FREE(iter); @@ -330,6 +338,8 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const vo= id *name, if (is_update) { if (table->dataFree) table->dataFree(entry->payload, entry->name); + if (table->dataFreeSimple) + table->dataFreeSimple(entry->payload); entry->payload =3D userdata; return 0; } else { @@ -456,9 +466,12 @@ void *virHashSteal(virHashTablePtr table, const void *= name) void *data =3D virHashLookup(table, name); if (data) { virHashDataFree dataFree =3D table->dataFree; + virHashDataFreeSimple dataFreeSimple =3D table->dataFreeSimple; table->dataFree =3D NULL; + table->dataFreeSimple =3D NULL; virHashRemoveEntry(table, name); table->dataFree =3D dataFree; + table->dataFreeSimple =3D dataFreeSimple; } return data; } diff --git a/src/util/virhash.h b/src/util/virhash.h index b5e7c79260..94fe8e23e4 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -30,6 +30,15 @@ typedef virHashAtomic *virHashAtomicPtr; * Callback to free data from a hash. */ typedef void (*virHashDataFree) (void *payload, const void *name); +/** + * virHashDataFreeSimple: + * @payload: the data in the hash + * @name: the name associated + * + * Callback to free data from a hash. + */ +typedef void (*virHashDataFreeSimple) (void *payload); + /** * virHashIterator: * @payload: the data in the hash @@ -104,6 +113,7 @@ virHashAtomicPtr virHashAtomicNew(ssize_t size, virHashDataFree dataFree); virHashTablePtr virHashCreateFull(ssize_t size, virHashDataFree dataFree, + virHashDataFreeSimple dataFreeSimple, virHashKeyCode keyCode, virHashKeyEqual keyEqual, virHashKeyCopy keyCopy, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list