diff options
author | David Teigland <teigland@redhat.com> | 2015-11-13 16:54:22 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2015-11-13 16:54:22 -0600 |
commit | d9295410e98e32636d3bf03ee375c5739bd44b23 (patch) | |
tree | 34d7bddeda5760ad2b0fe2cc68a0cf394e1e1569 /libdm/datastruct | |
parent | e425bce28132e4bad940fae5bfb1499d6a15391d (diff) | |
download | lvm2-d9295410e98e32636d3bf03ee375c5739bd44b23.tar.gz |
lvmetad: change the new hash to take data len
If the data len is passed into the hash table
and saved there, then the hash table internals
do not need to assume that the data value is
a string at any point.
Diffstat (limited to 'libdm/datastruct')
-rw-r--r-- | libdm/datastruct/hash.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/libdm/datastruct/hash.c b/libdm/datastruct/hash.c index cf1822624..406f5fdf9 100644 --- a/libdm/datastruct/hash.c +++ b/libdm/datastruct/hash.c @@ -18,6 +18,7 @@ struct dm_hash_node { struct dm_hash_node *next; void *data; + unsigned data_len; unsigned keylen; char key[0]; }; @@ -222,10 +223,8 @@ static struct dm_hash_node **_find_str_withval(struct dm_hash_table *t, continue; if (!memcmp(key, (*c)->key, len) && (*c)->data) { - char *str = (char *)((*c)->data); - - if (((strlen(str) + 1) == val_len) && - !memcmp(val, str, val_len)) + if (((*c)->data_len == val_len) && + !memcmp(val, (*c)->data, val_len)) return c; } } @@ -233,7 +232,8 @@ static struct dm_hash_node **_find_str_withval(struct dm_hash_table *t, return NULL; } -int dm_hash_insert_str_multival(struct dm_hash_table *t, const char *key, const char *val) +int dm_hash_insert_multival(struct dm_hash_table *t, const char *key, + const void *val, uint32_t val_len) { struct dm_hash_node *n; struct dm_hash_node *first; @@ -245,6 +245,7 @@ int dm_hash_insert_str_multival(struct dm_hash_table *t, const char *key, const return 0; n->data = (void *)val; + n->data_len = val_len; h = _hash(key, len) & (t->num_slots - 1); @@ -264,11 +265,12 @@ int dm_hash_insert_str_multival(struct dm_hash_table *t, const char *key, const * Look through multiple entries with the same key for one that has a * matching val and return that. If none have maching val, return NULL. */ -void *dm_hash_lookup_str_withval(struct dm_hash_table *t, const char *key, const char *val) +void *dm_hash_lookup_withval(struct dm_hash_table *t, const char *key, + const void *val, uint32_t val_len) { struct dm_hash_node **c; - c = _find_str_withval(t, key, val, strlen(key) + 1, strlen(val) + 1); + c = _find_str_withval(t, key, val, strlen(key) + 1, val_len); return (c && *c) ? (*c)->data : 0; } @@ -277,11 +279,12 @@ void *dm_hash_lookup_str_withval(struct dm_hash_table *t, const char *key, const * Look through multiple entries with the same key for one that has a * matching val and remove that. */ -void dm_hash_remove_str_withval(struct dm_hash_table *t, const char *key, const char *val) +void dm_hash_remove_withval(struct dm_hash_table *t, const char *key, + const void *val, uint32_t val_len) { struct dm_hash_node **c; - c = _find_str_withval(t, key, val, strlen(key) + 1, strlen(val) + 1); + c = _find_str_withval(t, key, val, strlen(key) + 1, val_len); if (c && *c) { struct dm_hash_node *old = *c; @@ -306,7 +309,7 @@ void dm_hash_remove_str_withval(struct dm_hash_table *t, const char *key, const * If more than two entries have the key, the function looks * at only the first two. */ -void *dm_hash_lookup_str_multival(struct dm_hash_table *t, const char *key, const char **val2) +void *dm_hash_lookup_multival(struct dm_hash_table *t, const char *key, const void **val2) { struct dm_hash_node **c; struct dm_hash_node **c1 = NULL; |