From nobody Fri Dec 19 06:39:14 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=1571415096; cv=none; d=zoho.com; s=zohoarc; b=e9pmTVlV6SafF3vcZH0LBJI8TFSymNPK6PxHmeny57D/rcBUaiSbPF7A3E4eXYDVGSyN0+TDaRJmv9iKR8J52itswnNswWRLQIr9TfMSFSGcjtpZ5bOa6boGOw1sKpLbwEjlWdrqmrnjSUaYiePOI4UF2r89wZdVryktICk9qEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571415096; 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=4F6m3Z8D/7QFh+EwMy31vwA4vNoZ12zfHxVSpwcqgoU=; b=PDmOJM5grXpNsvC/BuBPDtIt66oZ1EF+HH7aNpLDgcdrH5f3JS+7RBiuUJ+SSuDQOK4WEXv+l4+FfSWBk0chc3TthSH37gOfVxKMJqePL1aP3NzneZUzeP373OrBqnB5jmTH6xUJ1Crka7iwwfAhAswaS8bCJUka4Djd2dm2ABE= 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 1571415096004639.8753687128981; Fri, 18 Oct 2019 09:11:36 -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 27306ED3C1; Fri, 18 Oct 2019 16:11:34 +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 ED02E5D9DC; 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 9CE4B180B761; Fri, 18 Oct 2019 16:11:33 +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 x9IGBWor004548 for ; Fri, 18 Oct 2019 12:11:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 67632600C8; Fri, 18 Oct 2019 16:11:32 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDF01600C1; Fri, 18 Oct 2019 16:11:31 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 18 Oct 2019 18:10:48 +0200 Message-Id: <52b1e82d0a004dd031dc7fc072ff7fdde2640b09.1571414890.git.pkrempa@redhat.com> 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 03/40] util: hash: Introduce virHashHasEntry 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 18 Oct 2019 16:11:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add a helper that checks whether an entry with given name exists but does not touch the userdata. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virhash.c | 49 ++++++++++++++++++++++++++++++++-------- src/util/virhash.h | 1 + 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c155f51174..588f0a4356 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2065,6 +2065,7 @@ virHashEqual; virHashForEach; virHashFree; virHashGetItems; +virHashHasEntry; virHashLookup; virHashNew; virHashRemoveAll; diff --git a/src/util/virhash.c b/src/util/virhash.c index de03032bf1..df07e37e42 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -445,6 +445,26 @@ virHashAtomicUpdate(virHashAtomicPtr table, } +static virHashEntryPtr +virHashGetEntry(const virHashTable *table, + const void *name) +{ + size_t key; + virHashEntryPtr entry; + + if (!table || !name) + return NULL; + + key =3D virHashComputeKey(table, name); + for (entry =3D table->table[key]; entry; entry =3D entry->next) { + if (table->keyEqual(entry->name, name)) + return entry; + } + + return NULL; +} + + /** * virHashLookup: * @table: the hash table @@ -457,18 +477,29 @@ virHashAtomicUpdate(virHashAtomicPtr table, void * virHashLookup(const virHashTable *table, const void *name) { - size_t key; - virHashEntryPtr entry; + virHashEntryPtr entry =3D virHashGetEntry(table, name); - if (!table || !name) + if (!entry) return NULL; - key =3D virHashComputeKey(table, name); - for (entry =3D table->table[key]; entry; entry =3D entry->next) { - if (table->keyEqual(entry->name, name)) - return entry->payload; - } - return NULL; + return entry->payload; +} + + +/** + * virHashHasEntry: + * @table: the hash table + * @name: the name of the userdata + * + * Find whether entry specified by @name exists. + * + * Returns true if the entry exists and false otherwise + */ +bool +virHashHasEntry(const virHashTable *table, + const void *name) +{ + return !!virHashGetEntry(table, name); } diff --git a/src/util/virhash.h b/src/util/virhash.h index d7de0618cb..8087965ee9 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -150,6 +150,7 @@ ssize_t virHashRemoveAll(virHashTablePtr table); * Retrieve the userdata. */ void *virHashLookup(const virHashTable *table, const void *name); +bool virHashHasEntry(const virHashTable *table, const void *name); /* * Retrieve & remove the userdata. --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list