From: Wouter Wijngaards Date: Tue, 4 Dec 2007 21:34:53 +0000 (+0000) Subject: fptrwlist and remove oldhack with islocked param. X-Git-Tag: release-0.9~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f187e1da7ea131000fe74c689bed39a69ca910ce;p=thirdparty%2Funbound.git fptrwlist and remove oldhack with islocked param. git-svn-id: file:///svn/unbound/trunk@805 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index d093aa8c8..1b06a0702 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -18,6 +18,8 @@ - check return value of evtimer_add(). - fixup lockorder in lruhash_reclaim(), building up a list of locked entries one at a time. Instead they are removed and unlocked. + - fptr_wlist for markdelfunc. + - removed is_locked param from lruhash delkeyfunc. 3 December 2007: Wouter - changed checkconf/ to smallapp/ to make room for more support tools. diff --git a/services/cache/infra.c b/services/cache/infra.c index d95568bf0..b2b6ada26 100644 --- a/services/cache/infra.c +++ b/services/cache/infra.c @@ -64,12 +64,11 @@ infra_host_compfunc(void* key1, void* key2) } void -infra_host_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il) +infra_host_delkeyfunc(void* k, void* ATTR_UNUSED(arg)) { struct infra_host_key* key = (struct infra_host_key*)k; if(!key) return; - if(il) { lock_rw_unlock(&key->entry.lock); } lock_rw_destroy(&key->entry.lock); free(key); } @@ -309,12 +308,11 @@ infra_lame_compfunc(void* key1, void* key2) } void -infra_lame_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il) +infra_lame_delkeyfunc(void* k, void* ATTR_UNUSED(arg)) { struct infra_lame_key* key = (struct infra_lame_key*)k; if(!key) return; - if(il) { lock_rw_unlock(&key->entry.lock); } lock_rw_destroy(&key->entry.lock); free(key->zonename); free(key); diff --git a/services/cache/infra.h b/services/cache/infra.h index 9934b696f..fd5261b74 100644 --- a/services/cache/infra.h +++ b/services/cache/infra.h @@ -267,7 +267,7 @@ size_t infra_host_sizefunc(void* k, void* d); int infra_host_compfunc(void* key1, void* key2); /** delete key, and destroy the lock */ -void infra_host_delkeyfunc(void* k, void* arg, int il); +void infra_host_delkeyfunc(void* k, void* arg); /** delete data and destroy the lameness hashtable */ void infra_host_deldatafunc(void* d, void* arg); @@ -280,7 +280,7 @@ size_t infra_lame_sizefunc(void* k, void* d); int infra_lame_compfunc(void* key1, void* key2); /** free key, lock and zonename */ -void infra_lame_delkeyfunc(void* k, void* arg, int il); +void infra_lame_delkeyfunc(void* k, void* arg); /** free the lameness data */ void infra_lame_deldatafunc(void* d, void* arg); diff --git a/services/cache/rrset.c b/services/cache/rrset.c index 14399ad72..20c97330a 100644 --- a/services/cache/rrset.c +++ b/services/cache/rrset.c @@ -47,8 +47,7 @@ #include "util/regional.h" #include "util/alloc.h" -/** mark rrset to be deleted */ -static void +void rrset_markdel(void* key) { struct ub_packed_rrset_key* r = (struct ub_packed_rrset_key*)key; diff --git a/services/cache/rrset.h b/services/cache/rrset.h index 46239e065..ff3832fae 100644 --- a/services/cache/rrset.h +++ b/services/cache/rrset.h @@ -207,4 +207,7 @@ void rrset_update_sec_status(struct rrset_cache* r, void rrset_check_sec_status(struct rrset_cache* r, struct ub_packed_rrset_key* rrset); +/** mark rrset to be deleted, set id=0 */ +void rrset_markdel(void* key); + #endif /* SERVICES_CACHE_RRSET_H */ diff --git a/util/data/msgreply.c b/util/data/msgreply.c index 87c94a496..7c4dab060 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -543,12 +543,9 @@ msgreply_sizefunc(void* k, void* d) } void -query_entry_delete(void *k, void* ATTR_UNUSED(arg), int is_locked) +query_entry_delete(void *k, void* ATTR_UNUSED(arg)) { struct msgreply_entry* q = (struct msgreply_entry*)k; - if(is_locked) { - lock_rw_unlock(&q->entry.lock); - } lock_rw_destroy(&q->entry.lock); query_info_clear(&q->key); free(q); diff --git a/util/data/msgreply.h b/util/data/msgreply.h index bf0ce473e..23e35e131 100644 --- a/util/data/msgreply.h +++ b/util/data/msgreply.h @@ -268,7 +268,7 @@ void query_info_clear(struct query_info* m); size_t msgreply_sizefunc(void* k, void* d); /** delete msgreply_entry key structure */ -void query_entry_delete(void *q, void* arg, int is_locked); +void query_entry_delete(void *q, void* arg); /** delete reply_info data structure */ void reply_info_delete(void* d, void* arg); diff --git a/util/data/packed_rrset.c b/util/data/packed_rrset.c index a010fe895..52ab2567e 100644 --- a/util/data/packed_rrset.c +++ b/util/data/packed_rrset.c @@ -121,14 +121,11 @@ ub_rrset_compare(void* k1, void* k2) } void -ub_rrset_key_delete(void* key, void* userdata, int is_locked) +ub_rrset_key_delete(void* key, void* userdata) { struct ub_packed_rrset_key* k = (struct ub_packed_rrset_key*)key; struct alloc_cache* a = (struct alloc_cache*)userdata; k->id = 0; - if(is_locked) { - lock_rw_unlock(&k->entry.lock); - } free(k->rk.dname); k->rk.dname = NULL; alloc_special_release(a, k); diff --git a/util/data/packed_rrset.h b/util/data/packed_rrset.h index f00052779..0a796c04a 100644 --- a/util/data/packed_rrset.h +++ b/util/data/packed_rrset.h @@ -300,13 +300,12 @@ int rrsetdata_equal(struct packed_rrset_data* d1, struct packed_rrset_data* d2); /** * Old key to be deleted. RRset keys are recycled via alloc. + * The id is set to 0. So that other threads, after acquiring a lock always + * get the correct value, in this case the 0 deleted-special value. * @param key: struct ub_packed_rrset_key*. * @param userdata: alloc structure to use for recycling. - * @param is_locked: if the key is locked, the id is set to 0 while it is - * still locked. So that other threads, after acquiring a lock always - * get the correct value, in this case the 0 deleted-special value. */ -void ub_rrset_key_delete(void* key, void* userdata, int is_locked); +void ub_rrset_key_delete(void* key, void* userdata); /** * Old data to be deleted. diff --git a/util/fptr_wlist.c b/util/fptr_wlist.c index 162868592..abb7e29a9 100644 --- a/util/fptr_wlist.c +++ b/util/fptr_wlist.c @@ -51,6 +51,7 @@ #include "services/mesh.h" #include "services/localzone.h" #include "services/cache/infra.h" +#include "services/cache/rrset.h" #include "iterator/iterator.h" #include "iterator/iter_donotq.h" #include "iterator/iter_fwd.h" @@ -197,6 +198,14 @@ fptr_whitelist_hash_deldatafunc(lruhash_deldatafunc_t fptr) return 0; } +int +fptr_whitelist_hash_markdelfunc(lruhash_markdelfunc_t fptr) +{ + if(fptr == NULL) return 1; + else if(fptr == &rrset_markdel) return 1; + return 0; +} + int fptr_whitelist_modenv_send_packet(int (*fptr)(ldns_buffer* pkt, struct sockaddr_storage* addr, socklen_t addrlen, int timeout, diff --git a/util/fptr_wlist.h b/util/fptr_wlist.h index b3cebef68..9f114399a 100644 --- a/util/fptr_wlist.h +++ b/util/fptr_wlist.h @@ -155,6 +155,14 @@ int fptr_whitelist_hash_delkeyfunc(lruhash_delkeyfunc_t fptr); */ int fptr_whitelist_hash_deldatafunc(lruhash_deldatafunc_t fptr); +/** + * Check function pointer whitelist for lruhash markdel callback values. + * + * @param fptr: function pointer to check. + * @return false if not in whitelist. + */ +int fptr_whitelist_hash_markdelfunc(lruhash_markdelfunc_t fptr); + /** * Check function pointer whitelist for module_env send_packet callback values. * diff --git a/util/storage/lruhash.c b/util/storage/lruhash.c index ff16aca4e..c1fe6e58c 100644 --- a/util/storage/lruhash.c +++ b/util/storage/lruhash.c @@ -106,7 +106,7 @@ bin_delete(struct lruhash* table, struct lruhash_bin* bin) while(p) { np = p->overflow_next; d = p->data; - (*table->delkeyfunc)(p->key, table->cb_arg, 0); + (*table->delkeyfunc)(p->key, table->cb_arg); (*table->deldatafunc)(d, table->cb_arg); p = np; } @@ -206,7 +206,6 @@ reclaim_space(struct lruhash* table, struct lruhash_entry** list) lock_rw_wrlock(&d->lock); table->space_used -= table->sizefunc(d->key, d->data); if(table->markdelfunc) - /* TODO fptr_wlist it */ (*table->markdelfunc)(d->key); lock_rw_unlock(&d->lock); lock_quick_unlock(&bin->lock); @@ -307,6 +306,7 @@ lruhash_insert(struct lruhash* table, hashvalue_t hash, log_assert(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc)); log_assert(fptr_whitelist_hash_deldatafunc(table->deldatafunc)); log_assert(fptr_whitelist_hash_compfunc(table->compfunc)); + log_assert(fptr_whitelist_hash_markdelfunc(table->markdelfunc)); need_size = table->sizefunc(entry->key, data); if(cb_arg == NULL) cb_arg = table->cb_arg; @@ -327,7 +327,7 @@ 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, 0); + (*table->delkeyfunc)(entry->key, cb_arg); lru_touch(table, found); lock_rw_wrlock(&found->lock); (*table->deldatafunc)(found->data, cb_arg); @@ -345,7 +345,7 @@ lruhash_insert(struct lruhash* table, hashvalue_t hash, while(reclaimlist) { struct lruhash_entry* n = reclaimlist->overflow_next; void* d = reclaimlist->data; - (*table->delkeyfunc)(reclaimlist->key, cb_arg, 0); + (*table->delkeyfunc)(reclaimlist->key, cb_arg); (*table->deldatafunc)(d, cb_arg); reclaimlist = n; } @@ -383,6 +383,7 @@ lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key) log_assert(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc)); log_assert(fptr_whitelist_hash_deldatafunc(table->deldatafunc)); log_assert(fptr_whitelist_hash_compfunc(table->compfunc)); + log_assert(fptr_whitelist_hash_markdelfunc(table->markdelfunc)); lock_quick_lock(&table->lock); bin = &table->array[hash & table->size_mask]; @@ -400,13 +401,12 @@ lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key) lock_quick_unlock(&table->lock); lock_rw_wrlock(&entry->lock); if(table->markdelfunc) - /* TODO fptr wlist it */ (*table->markdelfunc)(entry->key); lock_rw_unlock(&entry->lock); lock_quick_unlock(&bin->lock); /* finish removal */ d = entry->data; - (*table->delkeyfunc)(entry->key, table->cb_arg, 0); + (*table->delkeyfunc)(entry->key, table->cb_arg); (*table->deldatafunc)(d, table->cb_arg); } @@ -423,10 +423,9 @@ bin_clear(struct lruhash* table, struct lruhash_bin* bin) np = p->overflow_next; d = p->data; if(table->markdelfunc) - /* TODO fptr wlist it */ (*table->markdelfunc)(p->key); lock_rw_unlock(&p->lock); - (*table->delkeyfunc)(p->key, table->cb_arg, 0); + (*table->delkeyfunc)(p->key, table->cb_arg); (*table->deldatafunc)(d, table->cb_arg); p = np; } @@ -442,6 +441,7 @@ lruhash_clear(struct lruhash* table) return; log_assert(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc)); log_assert(fptr_whitelist_hash_deldatafunc(table->deldatafunc)); + log_assert(fptr_whitelist_hash_markdelfunc(table->markdelfunc)); lock_quick_lock(&table->lock); for(i=0; isize; i++) { diff --git a/util/storage/lruhash.h b/util/storage/lruhash.h index 7a4084a57..8d3ebe448 100644 --- a/util/storage/lruhash.h +++ b/util/storage/lruhash.h @@ -130,13 +130,9 @@ typedef size_t (*lruhash_sizefunc_t)(void*, void*); typedef int (*lruhash_compfunc_t)(void*, void*); /** old keys are deleted. - * If is_locked is set, then the routine must unlock the item before deletion. - * If is_locked is not set, then this item is not locked. This allows the - * routine to perform operations within the critical region of the lock - * of the key. The critical region has been locked before the delete happened. - * The RRset type has to revoke its ID number inside the critical region. - * This function is called: func(key, userarg, is_locked) */ -typedef void (*lruhash_delkeyfunc_t)(void*, void*, int); + * The RRset type has to revoke its ID number, markdel() is used first. + * This function is called: func(key, userarg) */ +typedef void (*lruhash_delkeyfunc_t)(void*, void*); /** old data is deleted. This function is called: func(data, userarg). */ typedef void (*lruhash_deldatafunc_t)(void*, void*); diff --git a/util/storage/slabhash.c b/util/storage/slabhash.c index 71292d495..314763119 100644 --- a/util/storage/slabhash.c +++ b/util/storage/slabhash.c @@ -192,9 +192,8 @@ int test_slabhash_compfunc(void* key1, void* key2) return -1; } -void test_slabhash_delkey(void* key, void* ATTR_UNUSED(arg), int l) +void test_slabhash_delkey(void* key, void* ATTR_UNUSED(arg)) { - if(l) { lock_rw_unlock(&((struct slabhash_testkey*)key)->entry.lock); } delkey((struct slabhash_testkey*)key); } diff --git a/util/storage/slabhash.h b/util/storage/slabhash.h index 6fd4efb81..87e283e62 100644 --- a/util/storage/slabhash.h +++ b/util/storage/slabhash.h @@ -193,7 +193,7 @@ size_t test_slabhash_sizefunc(void*, void*); /** test comparefunc for lruhash */ int test_slabhash_compfunc(void*, void*); /** test delkey for lruhash */ -void test_slabhash_delkey(void*, void*, int); +void test_slabhash_delkey(void*, void*); /** test deldata for lruhash */ void test_slabhash_deldata(void*, void*); /* --- end test representation --- */ diff --git a/validator/val_kentry.c b/validator/val_kentry.c index b4c871fff..de846c12a 100644 --- a/validator/val_kentry.c +++ b/validator/val_kentry.c @@ -72,14 +72,11 @@ key_entry_compfunc(void* k1, void* k2) } void -key_entry_delkeyfunc(void* key, void* ATTR_UNUSED(userarg), int islocked) +key_entry_delkeyfunc(void* key, void* ATTR_UNUSED(userarg)) { struct key_entry_key* kk = (struct key_entry_key*)key; if(!key) return; - if(islocked) { - lock_rw_unlock(&kk->entry.lock); - } free(kk->name); free(kk); } diff --git a/validator/val_kentry.h b/validator/val_kentry.h index bda29113e..2b0a12f5a 100644 --- a/validator/val_kentry.h +++ b/validator/val_kentry.h @@ -91,7 +91,7 @@ size_t key_entry_sizefunc(void* key, void* data); int key_entry_compfunc(void* k1, void* k2); /** function for lruhash operation */ -void key_entry_delkeyfunc(void* key, void* userarg, int islocked); +void key_entry_delkeyfunc(void* key, void* userarg); /** function for lruhash operation */ void key_entry_deldatafunc(void* data, void* userarg);