From nobody Mon Feb 9 09:34:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1688973023; cv=none; d=zohomail.com; s=zohoarc; b=ea7lPf/5igoIHuGWNk+22WfXXUi9BztomqUpcGrjyL+hoh+bRK3Qc2wuPinYoy1gmZah/Do9aQBAhsv88Wj8D0WRgTmxZeY8E4mH51gDLCYDCwdnGnlT2Gsa7XdHdtEbqVyAfqYXMSeiY42WIf0PdQ2IVRBKRKZSFf+L8Pxtt4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688973023; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/yrCEroex0VDLTJaLozI/wdv3DQR1vU/0IqPsVNjH/o=; b=V3fhLB35F47qImIMRyXnNcfieHSoBO0p3h5eQuNb3mH1EptdCw8Gjg4PVh1YDb8aAOusmI6w4/UyRl+XyjPoWsu8crlA7EEtkUGFEskegGYqfB5Bg2lSHkZJ4ZtMPS2KvzExnCzcrVtFMyzzIE9vbegwUgOCpNudcpF5rYZU0WY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1688973023227522.088865457296; Mon, 10 Jul 2023 00:10:23 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.560992.877243 (Exim 4.92) (envelope-from ) id 1qIl1p-0001x1-6P; Mon, 10 Jul 2023 07:09:49 +0000 Received: by outflank-mailman (output) from mailman id 560992.877243; Mon, 10 Jul 2023 07:09:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qIl1o-0001u6-VR; Mon, 10 Jul 2023 07:09:48 +0000 Received: by outflank-mailman (input) for mailman id 560992; Mon, 10 Jul 2023 07:09:47 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qIkt6-0002bQ-M1 for xen-devel@lists.xenproject.org; Mon, 10 Jul 2023 07:00:48 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7edcca85-1eef-11ee-8611-37d641c3527e; Mon, 10 Jul 2023 09:00:47 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D7A701F8BF; Mon, 10 Jul 2023 07:00:46 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A8C6F1361C; Mon, 10 Jul 2023 07:00:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id V8aIJ56sq2QSYwAAMHmgww (envelope-from ); Mon, 10 Jul 2023 07:00:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7edcca85-1eef-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1688972446; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/yrCEroex0VDLTJaLozI/wdv3DQR1vU/0IqPsVNjH/o=; b=BOyRa5SL2Gwy3BOMkd+QiMZB2KdhnkXLwkqhM5TPBXNArSJku6OTyfSgSkX58p4TPbXb4i 0E8APxRrO/gUIu5hmW46j/gWSkMjnZR2xhR32jck5pUuCHwoq9U4ko9KccVNmYDGuxJLE5 S/RtZDstzWzSonwoiolhrmv9arB7B+s= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 10/18] tools/xenstore: add hashtable_replace() function Date: Mon, 10 Jul 2023 08:59:39 +0200 Message-Id: <20230710065947.4201-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230710065947.4201-1-jgross@suse.com> References: <20230710065947.4201-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1688973024356100001 Content-Type: text/plain; charset="utf-8" For an effective way to replace a hashtable entry add a new function hashtable_replace(). While at it let hashtable_add() fail if an entry with the specified key does already exist. This is in preparation to replace TDB with a more simple data storage. Signed-off-by: Juergen Gross --- tools/xenstore/hashtable.c | 20 ++++++++++++++++++++ tools/xenstore/hashtable.h | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 29c247f918..0c26a09567 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -160,6 +160,7 @@ static struct entry *hashtable_search_entry(const struc= t hashtable *h, =20 return NULL; } + int hashtable_add(struct hashtable *h, const void *k, void *v) { unsigned int index; @@ -204,6 +205,25 @@ void *hashtable_search(const struct hashtable *h, cons= t void *k) return e ? e->v : NULL; } =20 +int hashtable_replace(struct hashtable *h, const void *k, void *v) +{ + struct entry *e; + + e =3D hashtable_search_entry(h, k); + if (!e) + return ENOENT; + + if (h->flags & HASHTABLE_FREE_VALUE) + { + talloc_free(e->v); + talloc_steal(e, v); + } + + e->v =3D v; + + return 0; +} + void hashtable_remove(struct hashtable *h, const void *k) { diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index 792f6cda7b..214aea1b3d 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -51,6 +51,22 @@ create_hashtable(const void *ctx, const char *name, int hashtable_add(struct hashtable *h, const void *k, void *v); =20 +/*************************************************************************= **** + * hashtable_replace + + * @name hashtable_nsert + * @param h the hashtable to insert into + * @param k the key - hashtable claims ownership and will free on remo= val + * @param v the value - does not claim ownership + * @return zero for successful insertion + * + * This function does check for an entry being present before replacing it + * with a new value. + */ + +int +hashtable_replace(struct hashtable *h, const void *k, void *v); + /*************************************************************************= **** * hashtable_search =20 --=20 2.35.3