From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>, Wei Liu <wl@xen.org>,
Julien Grall <julien@xen.org>,
Anthony PERARD <anthony.perard@citrix.com>
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 [thread overview]
Message-ID: <20230530085418.5417-5-jgross@suse.com> (raw)
In-Reply-To: <20230530085418.5417-1-jgross@suse.com>
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 <jgross@suse.com>
---
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 == (PRIME_TABLE_LEN - 1)) return 0;
+ if (h->primeindex == (PRIME_TABLE_LEN - 1))
+ return ENOSPC;
newsize = primes[++(h->primeindex)];
newtable = talloc_realloc(h, h->table, struct entry *, newsize);
if (!newtable)
{
h->primeindex--;
- return 0;
+ return ENOMEM;
}
h->table = newtable;
@@ -136,10 +137,10 @@ static int hashtable_expand(struct hashtable *h)
h->tablelength = newsize;
h->loadlimit = loadlimit(h->primeindex);
- return -1;
+ return 0;
}
-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, void *v)
hashtable_expand(h);
}
e = talloc_zero(h, struct entry);
- if (NULL == e) { --(h->entrycount); return 0; } /*oom*/
+ if (NULL == e)
+ {
+ --h->entrycount;
+ return ENOMEM;
+ }
e->h = hash(h,k);
index = indexFor(h->tablelength,e->h);
e->k = k;
@@ -164,7 +169,7 @@ int hashtable_insert(struct hashtable *h, void *k, void *v)
talloc_steal(e, v);
e->next = h->table[index];
h->table[index] = e;
- return -1;
+ return 0;
}
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,
);
/*****************************************************************************
- * hashtable_insert
+ * hashtable_add
- * @name hashtable_insert
+ * @name hashtable_add
* @param h the hashtable to insert into
* @param k the key - hashtable claims ownership and will free on removal
* @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,
*/
int
-hashtable_insert(struct hashtable *h, void *k, void *v);
+hashtable_add(struct hashtable *h, void *k, void *v);
/*****************************************************************************
* hashtable_search
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.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 char *str)
char *k = talloc_strdup(NULL, str);
if (!k)
- return 0;
- return hashtable_insert(hash, k, (void *)1);
+ return ENOMEM;
+ return hashtable_add(hash, k, (void *)1);
}
/**
@@ -2438,7 +2438,7 @@ static int check_store_step(const void *ctx, struct connection *conn,
: WALK_TREE_SKIP_CHILDREN;
}
- if (!remember_string(data->reachable, node->name))
+ if (remember_string(data->reachable, node->name))
return WALK_TREE_ERROR_STOP;
domain_check_acc_add(node, data->domains);
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.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 = generation;
domain->introduced = false;
- if (!hashtable_insert(domhash, &domain->domid, domain)) {
+ if (hashtable_add(domhash, &domain->domid, domain)) {
talloc_free(domain);
errno = ENOMEM;
return NULL;
@@ -1795,7 +1795,7 @@ static int domain_check_acc_init_sub(const void *k, void *v, void *arg)
*/
dom->nodes = -d->acc[ACC_NODES].val;
- 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/xenstored_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 = talloc_asprintf(trans, "%"PRIu64,
trans->generation);
- if (!tname || !remember_string(hash, tname))
+ if (!tname || remember_string(hash, tname))
goto nomem;
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;
}
--
2.35.3
next prev parent reply other threads:[~2023-05-30 8:54 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 8:54 [PATCH v3 00/16] tools/xenstore: more cleanups Juergen Gross
2023-05-30 8:54 ` [PATCH v3 01/16] tools/xenstore: verify command line parameters better Juergen Gross
2023-05-30 8:54 ` [PATCH v3 02/16] tools/xenstore: do some cleanup of hashtable.c Juergen Gross
2023-05-30 8:54 ` [PATCH v3 03/16] tools/xenstore: modify interface of create_hashtable() Juergen Gross
2023-06-09 17:52 ` Julien Grall
2023-05-30 8:54 ` Juergen Gross [this message]
2023-06-09 17:56 ` [PATCH v3 04/16] tools/xenstore: rename hashtable_insert() and let it return 0 on success Julien Grall
2023-05-30 8:54 ` [PATCH v3 05/16] tools/xenstore: make some write limit functions static Juergen Gross
2023-06-09 18:00 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 06/16] tools/xenstore: switch write limiting to use millisecond time base Juergen Gross
2023-06-09 18:02 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 07/16] tools/xenstore: remove stale TODO file Juergen Gross
2023-05-30 8:54 ` [PATCH v3 08/16] tools/xenstore: remove unused events list Juergen Gross
2023-05-30 8:54 ` [PATCH v3 09/16] tools/xenstore: remove support of file backed data base Juergen Gross
2023-06-09 18:04 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 10/16] tools/libs/store: use xen_list.h instead of xenstore/list.h Juergen Gross
2023-06-09 18:09 ` Julien Grall
2023-06-12 7:02 ` Juergen Gross
2023-06-12 10:34 ` Julien Grall
2023-06-12 10:37 ` Juergen Gross
2023-06-12 10:39 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 11/16] tools/libs/store: make libxenstore independent of utils.h Juergen Gross
2023-06-09 18:10 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 12/16] tools/xenstore: remove no longer needed functions from xs_lib.c Juergen Gross
2023-06-15 21:00 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 13/16] tools/xenstore: replace xs_lib.c with a header Juergen Gross
2023-06-15 21:03 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 14/16] tools/xenstore: split out environment specific live update code Juergen Gross
2023-06-19 17:55 ` Julien Grall
2023-06-20 8:22 ` Juergen Gross
2023-05-30 8:54 ` [PATCH v3 15/16] tools/xenstore: split out rest of live update control code Juergen Gross
2023-06-19 18:03 ` Julien Grall
2023-05-30 8:54 ` [PATCH v3 16/16] tools/xenstore: remove unused stuff from list.h Juergen Gross
2023-06-19 18:04 ` Julien Grall
2023-06-09 18:46 ` [PATCH v3 00/16] tools/xenstore: more cleanups Julien Grall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230530085418.5417-5-jgross@suse.com \
--to=jgross@suse.com \
--cc=anthony.perard@citrix.com \
--cc=julien@xen.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).