From: Yuri Schaeffer Date: Wed, 16 Oct 2013 14:42:23 +0000 (+0000) Subject: always do an insert on change of data. Else lruhash size is X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e98f60be8c42af62b635211235efa8aa0c5c255d;p=thirdparty%2Funbound.git always do an insert on change of data. Else lruhash size is not calculated or managed. lruhash now supports updating with the same data and the same key. git-svn-id: file:///svn/unbound/branches/edns-subnet@2986 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/edns-subnet/addrtree.c b/edns-subnet/addrtree.c index 7a62acc9e..7e47f9ac1 100644 --- a/edns-subnet/addrtree.c +++ b/edns-subnet/addrtree.c @@ -448,7 +448,6 @@ addrtree_find(struct addrtree *tree, const addrkey_t *addr, parent_node = node; depth = edge->len; node = edge->node; - } } diff --git a/edns-subnet/subnetmod.c b/edns-subnet/subnetmod.c index 7954338ca..ddc0fa103 100644 --- a/edns-subnet/subnetmod.c +++ b/edns-subnet/subnetmod.c @@ -178,7 +178,6 @@ void update_cache(struct module_qstate *qstate, int id) log_err("malloc failed"); return; } - slabhash_insert(subnet_msg_cache, h, lru_entry, lru_entry->data, NULL); } /** Step 2, find the correct tree */ if (!(tree = get_tree(lru_entry->data, edns, qstate->env))) { @@ -193,7 +192,9 @@ void update_cache(struct module_qstate *qstate, int id) edns->subnet_source_mask, qstate->edns_server_in.subnet_scope_mask, rep, rep->ttl + *qstate->env->now, *qstate->env->now); - if (acquired_lock) lock_rw_unlock(&lru_entry->lock); + if (acquired_lock) + lock_rw_unlock(&lru_entry->lock); + slabhash_insert(subnet_msg_cache, h, lru_entry, lru_entry->data, NULL); } diff --git a/util/storage/lruhash.c b/util/storage/lruhash.c index c22278dda..560cf9015 100644 --- a/util/storage/lruhash.c +++ b/util/storage/lruhash.c @@ -327,11 +327,15 @@ lruhash_insert(struct lruhash* table, hashvalue_t hash, /* if so: update data - needs a writelock */ table->space_used += need_size - (*table->sizefunc)(found->key, found->data); - (*table->delkeyfunc)(entry->key, cb_arg); + if (found->key != entry->key) { + (*table->delkeyfunc)(entry->key, cb_arg); + } lru_touch(table, found); lock_rw_wrlock(&found->lock); - (*table->deldatafunc)(found->data, cb_arg); - found->data = data; + if (found->data != data) { + (*table->deldatafunc)(found->data, cb_arg); + found->data = data; + } lock_rw_unlock(&found->lock); } lock_quick_unlock(&bin->lock);