[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 04/10] tools/xenstore: let hashtable_insert() return 0 on success



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.

Even if not used today, do the same switch for the return value of
hashtable_expand().

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 tools/xenstore/hashtable.c             | 15 ++++++++++-----
 tools/xenstore/hashtable.h             |  2 +-
 tools/xenstore/xenstored_core.c        |  4 ++--
 tools/xenstore/xenstored_domain.c      |  4 ++--
 tools/xenstore/xenstored_transaction.c |  4 ++--
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/tools/xenstore/hashtable.c b/tools/xenstore/hashtable.c
index 43a8caab82..1bed5ad384 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,7 +137,7 @@ 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)
@@ -153,14 +154,18 @@ 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;
     e->v = v;
     e->next = h->table[index];
     h->table[index] = e;
-    return -1;
+    return 0;
 }
 
 void *hashtable_search(struct hashtable *h, void *k)
diff --git a/tools/xenstore/hashtable.h b/tools/xenstore/hashtable.h
index 5575f6c1dd..99a8331bec 100644
--- a/tools/xenstore/hashtable.h
+++ b/tools/xenstore/hashtable.h
@@ -36,7 +36,7 @@ create_hashtable(const void *ctx, const char *name,
  * @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.
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index c4d9d275be..5d35925ed8 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -2385,7 +2385,7 @@ int remember_string(struct hashtable *hash, const char 
*str)
        char *k = talloc_strdup(NULL, str);
 
        if (!k)
-               return 0;
+               return ENOMEM;
        return hashtable_insert(hash, k, (void *)1);
 }
 
@@ -2419,7 +2419,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 b3c288bf40..f871bdf04a 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -542,7 +542,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_insert(domhash, &domain->domid, domain)) {
                talloc_free(domain);
                errno = ENOMEM;
                return NULL;
@@ -1786,7 +1786,7 @@ static int domain_check_acc_init_sub(void *k, void *v, 
void *arg)
         */
        dom->nodes = -d->acc[ACC_NODES].val;
 
-       if (!hashtable_insert(domains, &dom->domid, dom)) {
+       if (hashtable_insert(domains, &dom->domid, dom)) {
                talloc_free(dom);
                return -1;
        }
diff --git a/tools/xenstore/xenstored_transaction.c 
b/tools/xenstore/xenstored_transaction.c
index 13fabe030d..7b2e78f104 100644
--- a/tools/xenstore/xenstored_transaction.c
+++ b/tools/xenstore/xenstored_transaction.c
@@ -588,13 +588,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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.