From nobody Mon Feb 9 15:10:29 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=1690196646; cv=none; d=zohomail.com; s=zohoarc; b=OL6uUEKCwOyKRU+rzWlGujOzLayJDqw6GAX7ZMGZnG4kBOExgqUKoZptJuIxxFXX88tmAh25LqTNDlmkW55eSRTChMHuxWbrapBwfwZf9n/4CpnKxlh73LhO0SeTdXbgObBY+nZkg4mHXoPX1moOWJrErASDdxD1U9N1O5Y7p5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690196646; 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=0xB6oTYH0jaatpxlvCW+IH+bGX/Y8NZRC6aQFlKjAIU=; b=EmK9B+zD2VuANBFUhzV3WrzfMMYgGs5zcIs0Tdhduz16evz12BFmBujx01hZQ2o0HcMR7zP2UXOkGQ3aON0O2G7qyhmAD1iUoXTz1qeJdM6KDG5Jt7Ks1BcW7ZDVGl9AURmK1HWGO4q+F58ejofxBWWvgmlZyC6RX/n85IH8XcA= 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 1690196646313330.068844383208; Mon, 24 Jul 2023 04:04:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.568747.888642 (Exim 4.92) (envelope-from ) id 1qNtLw-0004Yf-NB; Mon, 24 Jul 2023 11:03:48 +0000 Received: by outflank-mailman (output) from mailman id 568747.888642; Mon, 24 Jul 2023 11:03:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qNtLw-0004YU-Kd; Mon, 24 Jul 2023 11:03:48 +0000 Received: by outflank-mailman (input) for mailman id 568747; Mon, 24 Jul 2023 11:03:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qNtLv-0000KR-76 for xen-devel@lists.xenproject.org; Mon, 24 Jul 2023 11:03:47 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c2c02585-2a11-11ee-b23a-6b7b168915f2; Mon, 24 Jul 2023 13:03:46 +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 7385B20694; Mon, 24 Jul 2023 11:03: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 4295A13476; Mon, 24 Jul 2023 11:03:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QU7oDpJavmSyYQAAMHmgww (envelope-from ); Mon, 24 Jul 2023 11:03: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: c2c02585-2a11-11ee-b23a-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1690196626; 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=0xB6oTYH0jaatpxlvCW+IH+bGX/Y8NZRC6aQFlKjAIU=; b=IVp6ZksGh83WYzXRuRC9WvkUdC8TvLXiGMtuhXl2luo1OFl4cnh8CbKidF+Mzb+GoJOANJ n1/iwQOOuJxAO6sKE+EX6k0E0gx7kZOy15Uoh9K2y7NIcTZnWxkcHqE6u39oxZqV3V9ImY mQbSBNcn48EwXpmMBK9sXUt78SndYs0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 10/25] tools/xenstore: add hashtable_replace() function Date: Mon, 24 Jul 2023 13:02:32 +0200 Message-Id: <20230724110247.10520-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230724110247.10520-1-jgross@suse.com> References: <20230724110247.10520-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1690196647800100001 Content-Type: text/plain; charset="utf-8" For an effective way to replace a hashtable entry add a new function hashtable_replace(). This is in preparation to replace TDB with a more simple data storage. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- V3: - fix commit message (Julien Grall) - move unrelated change to previous patch (Julien Grall) - make value parameter const --- tools/xenstore/hashtable.c | 19 +++++++++++++++++++ tools/xenstore/hashtable.h | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 0409725060..f85b5a71f1 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -205,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, const 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 (void *)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 1da3af2648..125de0cfa2 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, const 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, const void *v); + /*************************************************************************= **** * hashtable_search =20 --=20 2.35.3