]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
tools/xenstore: modify interface of create_hashtable()
authorJuergen Gross <jgross@suse.com>
Tue, 30 May 2023 08:54:05 +0000 (10:54 +0200)
committerJulien Grall <jgrall@amazon.com>
Fri, 9 Jun 2023 18:16:46 +0000 (19:16 +0100)
The minsize parameter of create_hashtable() doesn't have any real use
case for Xenstore, so drop it.

For better talloc_report_full() diagnostic output add a name parameter
to create_hashtable().

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

index dc209158fa88d71d249d77b5f772c07685e9b2a3..3d2d3a0e22ca65a266271399571343071d608c13 100644 (file)
@@ -55,39 +55,28 @@ static unsigned int loadlimit(unsigned int pindex)
     return ((uint64_t)primes[pindex] * MAX_LOAD_PERCENT) / 100;
 }
 
-struct hashtable *create_hashtable(const void *ctx, unsigned int minsize,
+struct hashtable *create_hashtable(const void *ctx, const char *name,
                                    unsigned int (*hashf) (const void *),
                                    int (*eqf) (const void *, const void *),
                                    unsigned int flags)
 {
     struct hashtable *h;
-    unsigned int pindex, size = primes[0];
-
-    /* Check requested hashtable isn't too large */
-    if (minsize > (1u << 30)) return NULL;
-
-    /* Enforce size as prime */
-    for (pindex = 0; pindex < PRIME_TABLE_LEN; pindex++) {
-        if (primes[pindex] > minsize) {
-            size = primes[pindex];
-            break;
-        }
-    }
 
     h = talloc_zero(ctx, struct hashtable);
     if (NULL == h)
         goto err0;
-    h->table = talloc_zero_array(h, struct entry *, size);
+    talloc_set_name_const(h, name);
+    h->table = talloc_zero_array(h, struct entry *, primes[0]);
     if (NULL == h->table)
         goto err1;
 
-    h->tablelength  = size;
+    h->primeindex   = 0;
+    h->tablelength  = primes[h->primeindex];
     h->flags        = flags;
-    h->primeindex   = pindex;
     h->entrycount   = 0;
     h->hashfn       = hashf;
     h->eqfn         = eqf;
-    h->loadlimit    = loadlimit(pindex);
+    h->loadlimit    = loadlimit(h->primeindex);
     return h;
 
 err1:
index 04310783b640042799f73615283e6466800294ff..0e1a6f61c29ddc396da65f33fa210d20ec79e712 100644 (file)
@@ -10,7 +10,7 @@ struct hashtable;
    
  * @name                    create_hashtable
  * @param   ctx             talloc context to use for allocations
- * @param   minsize         minimum initial size of hashtable
+ * @param   name            talloc name of the hashtable
  * @param   hashfunction    function for hashing keys
  * @param   key_eq_fn       function for determining key equality
  * @param   flags           flags HASHTABLE_*
@@ -23,7 +23,7 @@ struct hashtable;
 #define HASHTABLE_FREE_KEY   (1U << 1)
 
 struct hashtable *
-create_hashtable(const void *ctx, unsigned int minsize,
+create_hashtable(const void *ctx, const char *name,
                  unsigned int (*hashfunction) (const void *),
                  int (*key_eq_fn) (const void *, const void *),
                  unsigned int flags
index 22df395aacb754ac153413dad2442fae4f114781..418790d8d76229a02c49c5f203a027361aa2b7b6 100644 (file)
@@ -2521,7 +2521,7 @@ void check_store(void)
        struct check_store_data data;
 
        /* Don't free values (they are all void *1) */
-       data.reachable = create_hashtable(NULL, 16, hash_from_key_fn,
+       data.reachable = create_hashtable(NULL, "checkstore", hash_from_key_fn,
                                          keys_equal_fn, HASHTABLE_FREE_KEY);
        if (!data.reachable) {
                log("check_store: ENOMEM");
index e284cf1cf1aefe93f5c01b299ec5fe02f0ad008a..d67d67fae31a4cfd135395f2021f67b68a17a54e 100644 (file)
@@ -1014,7 +1014,7 @@ void domain_init(int evtfd)
        int rc;
 
        /* Start with a random rather low domain count for the hashtable. */
-       domhash = create_hashtable(NULL, 8, domhash_fn, domeq_fn, 0);
+       domhash = create_hashtable(NULL, "domains", domhash_fn, domeq_fn, 0);
        if (!domhash)
                barf_perror("Failed to allocate domain hashtable");
 
@@ -1806,7 +1806,7 @@ struct hashtable *domain_check_acc_init(void)
 {
        struct hashtable *domains;
 
-       domains = create_hashtable(NULL, 8, domhash_fn, domeq_fn,
+       domains = create_hashtable(NULL, "domain_check", domhash_fn, domeq_fn,
                                   HASHTABLE_FREE_VALUE);
        if (!domains)
                return NULL;