From nobody Mon Feb 9 16:18:26 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=1685436904; cv=none; d=zohomail.com; s=zohoarc; b=A7KRk09VeVo8ySVo+IDxGZ/S2UaDOkW98JAmDG+kJRi3L0fa6rurdxoad5hS4IvTtvMtXynYdMhU7Wcktihots+0AlPZNNTJKf1aRpqCiI/pUh2KMLlSMqADnnyjMMtalnF5IyHh1jSLYp9skufr9szI0QuzSSQ7X3DyDbjhRbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685436904; 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=vPoeTUcM9T4+NNSVnWYJP6NUt2CPkIcsiQEBOk5fFTE=; b=is+aNP5F2iou981qFWGdcTkSp1LbY577ttSCb68w2jsQ1ICH3wDs4Bu5AvoRNPfO/Zmtk3fRZAFEROsC6UvTOFWrfjRe6hL6mt9zpA1N72pT67U1fyMv/A0q834flw3pE/xKiQBHa9hsZ8FC2B8RRqYc9jbJ6yGkCf7b9AG62GY= 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 1685436904666905.8839529614735; Tue, 30 May 2023 01:55:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.540873.842980 (Exim 4.92) (envelope-from ) id 1q3v7u-000338-U8; Tue, 30 May 2023 08:54:46 +0000 Received: by outflank-mailman (output) from mailman id 540873.842980; Tue, 30 May 2023 08:54:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q3v7u-00032z-QE; Tue, 30 May 2023 08:54:46 +0000 Received: by outflank-mailman (input) for mailman id 540873; Tue, 30 May 2023 08:54:45 +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 1q3v7t-00026J-OZ for xen-devel@lists.xenproject.org; Tue, 30 May 2023 08:54:45 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2001:67c:2178:6::1d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9f0b082e-fec7-11ed-8611-37d641c3527e; Tue, 30 May 2023 10:54:44 +0200 (CEST) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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 C10101F889; Tue, 30 May 2023 08:54:43 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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 imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 9748E1341B; Tue, 30 May 2023 08:54:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id 7bKQI9O5dWRcGwAAGKfGzw (envelope-from ); Tue, 30 May 2023 08:54:43 +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: 9f0b082e-fec7-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1685436883; 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=vPoeTUcM9T4+NNSVnWYJP6NUt2CPkIcsiQEBOk5fFTE=; b=NswNjplESYHuW86lZ30UhtlPK3LGYRd+y9vt/onZ9rsOpu7+iTK908uDCmMltQoOxQ+HtN VjVCvbzycNhVl4trNzRWbkos1R6QjDlgB9u6N5ML9kw6esQbnNe6wJSKZUMmMqb+JjooJW WRzohHLqbLXEbLB/pVyLbS81BrRBBcM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v3 04/16] tools/xenstore: rename hashtable_insert() and let it return 0 on success Date: Tue, 30 May 2023 10:54:06 +0200 Message-Id: <20230530085418.5417-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230530085418.5417-1-jgross@suse.com> References: <20230530085418.5417-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1685436906993100001 Content-Type: text/plain; charset="utf-8" Today hashtable_insert() returns 0 in case of an error. Change that to let it return an errno value in the error case and 0 in case of success. In order to avoid any missed return value checks or related future backport errors, rename hashtable_insert() to hashtable_add(). Even if not used today, do the same switch for the return value of hashtable_expand(). Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- V3: - rename to hashtable_add() (triggered by Julien Grall) --- tools/xenstore/hashtable.c | 17 +++++++++++------ tools/xenstore/hashtable.h | 8 ++++---- tools/xenstore/xenstored_core.c | 6 +++--- tools/xenstore/xenstored_domain.c | 4 ++-- tools/xenstore/xenstored_transaction.c | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c index 3d2d3a0e22..11f6bf8f15 100644 --- a/tools/xenstore/hashtable.c +++ b/tools/xenstore/hashtable.c @@ -105,14 +105,15 @@ static int hashtable_expand(struct hashtable *h) struct entry **pE; unsigned int newsize, i, index; /* Check we're not hitting max capacity */ - if (h->primeindex =3D=3D (PRIME_TABLE_LEN - 1)) return 0; + if (h->primeindex =3D=3D (PRIME_TABLE_LEN - 1)) + return ENOSPC; newsize =3D primes[++(h->primeindex)]; =20 newtable =3D talloc_realloc(h, h->table, struct entry *, newsize); if (!newtable) { h->primeindex--; - return 0; + return ENOMEM; } =20 h->table =3D newtable; @@ -136,10 +137,10 @@ static int hashtable_expand(struct hashtable *h) =20 h->tablelength =3D newsize; h->loadlimit =3D loadlimit(h->primeindex); - return -1; + return 0; } =20 -int hashtable_insert(struct hashtable *h, void *k, void *v) +int hashtable_add(struct hashtable *h, void *k, void *v) { /* This method allows duplicate keys - but they shouldn't be used */ unsigned int index; @@ -153,7 +154,11 @@ int hashtable_insert(struct hashtable *h, void *k, voi= d *v) hashtable_expand(h); } e =3D talloc_zero(h, struct entry); - if (NULL =3D=3D e) { --(h->entrycount); return 0; } /*oom*/ + if (NULL =3D=3D e) + { + --h->entrycount; + return ENOMEM; + } e->h =3D hash(h,k); index =3D indexFor(h->tablelength,e->h); e->k =3D k; @@ -164,7 +169,7 @@ int hashtable_insert(struct hashtable *h, void *k, void= *v) talloc_steal(e, v); e->next =3D h->table[index]; h->table[index] =3D e; - return -1; + return 0; } =20 void *hashtable_search(const struct hashtable *h, const void *k) diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h index 0e1a6f61c2..5a2cc4a4be 100644 --- a/tools/xenstore/hashtable.h +++ b/tools/xenstore/hashtable.h @@ -30,13 +30,13 @@ create_hashtable(const void *ctx, const char *name, ); =20 /*************************************************************************= **** - * hashtable_insert + * hashtable_add =20 - * @name hashtable_insert + * @name hashtable_add * @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 non-zero for successful insertion + * @return zero for successful insertion * * This function will cause the table to expand if the insertion would take * the ratio of entries to table size over the maximum load factor. @@ -49,7 +49,7 @@ create_hashtable(const void *ctx, const char *name, */ =20 int=20 -hashtable_insert(struct hashtable *h, void *k, void *v); +hashtable_add(struct hashtable *h, void *k, void *v); =20 /*************************************************************************= **** * hashtable_search diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 418790d8d7..c467a704a1 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2404,8 +2404,8 @@ int remember_string(struct hashtable *hash, const cha= r *str) char *k =3D talloc_strdup(NULL, str); =20 if (!k) - return 0; - return hashtable_insert(hash, k, (void *)1); + return ENOMEM; + return hashtable_add(hash, k, (void *)1); } =20 /** @@ -2438,7 +2438,7 @@ static int check_store_step(const void *ctx, struct c= onnection *conn, : WALK_TREE_SKIP_CHILDREN; } =20 - if (!remember_string(data->reachable, node->name)) + if (remember_string(data->reachable, node->name)) return WALK_TREE_ERROR_STOP; =20 domain_check_acc_add(node, data->domains); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index a1c91ef3f3..815f15cd1d 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -538,7 +538,7 @@ static struct domain *alloc_domain(const void *context,= unsigned int domid) domain->generation =3D generation; domain->introduced =3D false; =20 - if (!hashtable_insert(domhash, &domain->domid, domain)) { + if (hashtable_add(domhash, &domain->domid, domain)) { talloc_free(domain); errno =3D ENOMEM; return NULL; @@ -1795,7 +1795,7 @@ static int domain_check_acc_init_sub(const void *k, v= oid *v, void *arg) */ dom->nodes =3D -d->acc[ACC_NODES].val; =20 - if (!hashtable_insert(domains, &dom->domid, dom)) { + if (hashtable_add(domains, &dom->domid, dom)) { talloc_free(dom); return -1; } diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xensto= red_transaction.c index db06d0e7f1..334f1609f1 100644 --- a/tools/xenstore/xenstored_transaction.c +++ b/tools/xenstore/xenstored_transaction.c @@ -601,13 +601,13 @@ int check_transactions(struct hashtable *hash) list_for_each_entry(trans, &conn->transaction_list, list) { tname =3D talloc_asprintf(trans, "%"PRIu64, trans->generation); - if (!tname || !remember_string(hash, tname)) + if (!tname || remember_string(hash, tname)) goto nomem; =20 list_for_each_entry(i, &trans->accessed, list) { if (!i->ta_node) continue; - if (!remember_string(hash, i->trans_name)) + if (remember_string(hash, i->trans_name)) goto nomem; } =20 --=20 2.35.3