X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Futil-hashtable.c;h=9ee832bc7b6d04a5975e9cd144d0851492aea4df;hb=471edd59ca70371e97cbad759e1710433f35990d;hp=ebf1d1c3e493e332d27a588095fa2fc8861d37ff;hpb=95908965b5963c53a40e9eae8ad0307a2bc27434;p=palacios.git diff --git a/linux_module/util-hashtable.c b/linux_module/util-hashtable.c index ebf1d1c..9ee832b 100644 --- a/linux_module/util-hashtable.c +++ b/linux_module/util-hashtable.c @@ -37,7 +37,9 @@ #include #include #include - +#include + +#include "palacios.h" #include "util-hashtable.h" @@ -137,18 +139,18 @@ static inline uint_t indexFor(uint_t table_length, uint_t hash_value) { return (hash_value % table_length); }; -#define freekey(X) kfree(X) +#define freekey(X) palacios_free(X) static void * tmp_realloc(void * old_ptr, uint_t old_size, uint_t new_size) { - void * new_buf = kmalloc(new_size, GFP_KERNEL); + void * new_buf = palacios_alloc(new_size); if (new_buf == NULL) { return NULL; } memcpy(new_buf, old_ptr, old_size); - kfree(old_ptr); + palacios_free(old_ptr); return new_buf; } @@ -201,16 +203,21 @@ struct hashtable * palacios_create_htable(uint_t min_size, } } - htable = (struct hashtable *)kmalloc(sizeof(struct hashtable), GFP_KERNEL); + if (prime_index==prime_table_len) { + // cannot build large enough hash table + return NULL; + } + + htable = (struct hashtable *)palacios_alloc(sizeof(struct hashtable)); if (htable == NULL) { return NULL; /*oom*/ } - htable->table = (struct hash_entry **)kmalloc(sizeof(struct hash_entry*) * size, GFP_KERNEL); + htable->table = (struct hash_entry **)palacios_alloc(sizeof(struct hash_entry*) * size); if (htable->table == NULL) { - kfree(htable); + palacios_free(htable); return NULL; /*oom*/ } @@ -243,7 +250,7 @@ static int hashtable_expand(struct hashtable * htable) { new_size = primes[++(htable->prime_index)]; - new_table = (struct hash_entry **)kmalloc(sizeof(struct hash_entry*) * new_size, GFP_KERNEL); + new_table = (struct hash_entry **)palacios_alloc(sizeof(struct hash_entry*) * new_size); if (new_table != NULL) { memset(new_table, 0, new_size * sizeof(struct hash_entry *)); @@ -263,7 +270,7 @@ static int hashtable_expand(struct hashtable * htable) { } } - kfree(htable->table); + palacios_free(htable->table); htable->table = new_table; } else { @@ -325,7 +332,7 @@ int palacios_htable_insert(struct hashtable * htable, addr_t key, addr_t value) hashtable_expand(htable); } - new_entry = (struct hash_entry *)kmalloc(sizeof(struct hash_entry), GFP_KERNEL); + new_entry = (struct hash_entry *)palacios_alloc(sizeof(struct hash_entry)); if (new_entry == NULL) { (htable->entry_count)--; @@ -363,7 +370,7 @@ int palacios_htable_change(struct hashtable * htable, addr_t key, addr_t value, if ((hash_value == tmp_entry->hash) && (htable->eq_fn(key, tmp_entry->key))) { if (free_value) { - kfree((void *)(tmp_entry->value)); + palacios_free((void *)(tmp_entry->value)); } tmp_entry->value = value; @@ -480,7 +487,7 @@ addr_t palacios_htable_remove(struct hashtable * htable, addr_t key, int free_ke if (free_key) { freekey((void *)(cursor->key)); } - kfree(cursor); + palacios_free(cursor); return value; } @@ -510,8 +517,8 @@ void palacios_free_htable(struct hashtable * htable, int free_values, int free_k if (free_keys) { freekey((void *)(tmp->key)); } - kfree((void *)(tmp->value)); - kfree(tmp); + palacios_free((void *)(tmp->value)); + palacios_free(tmp); } } } else { @@ -527,12 +534,12 @@ void palacios_free_htable(struct hashtable * htable, int free_values, int free_k if (free_keys) { freekey((void *)(tmp->key)); } - kfree(tmp); + palacios_free(tmp); } } } - kfree(htable->table); - kfree(htable); + palacios_free(htable->table); + palacios_free(htable); }