]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
tools/xenstore: rename hashtable_insert() and let it return 0 on success
authorJuergen Gross <jgross@suse.com>
Tue, 30 May 2023 08:54:06 +0000 (10:54 +0200)
committerJulien Grall <jgrall@amazon.com>
Fri, 9 Jun 2023 18:16:46 +0000 (19:16 +0100)
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>
Reviewed-by: Julien Grall <jgrall@amazon.com>
tools/xenstore/hashtable.c
tools/xenstore/hashtable.h
tools/xenstore/xenstored_core.c
tools/xenstore/xenstored_domain.c
tools/xenstore/xenstored_transaction.c

index 3d2d3a0e22ca65a266271399571343071d608c13..11f6bf8f15c014a4be6b0f9ff1f2db50956f5b39 100644 (file)
@@ -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)
index 0e1a6f61c29ddc396da65f33fa210d20ec79e712..5a2cc4a4be10ba625eadfec66165873e4f53f552 100644 (file)
@@ -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
index 418790d8d76229a02c49c5f203a027361aa2b7b6..c467a704a1a87c6986bc86c7b35484e97308fc31 100644 (file)
@@ -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);
index d67d67fae31a4cfd135395f2021f67b68a17a54e..af8db0d4a2ee3be66b3c2629438419d08dc19c91 100644 (file)
@@ -537,7 +537,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;
@@ -1794,7 +1794,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;
        }
index db06d0e7f10a0dbedd3818199db6ffd46088987c..334f1609f19c2ec99a700022e81bd76399ebb692 100644 (file)
@@ -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;
                        }