diff options
Diffstat (limited to 'lib/dns/rbtdb.c')
-rw-r--r-- | lib/dns/rbtdb.c | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index d4415d8..9d66006 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rbtdb.c,v 1.310.8.1.2.1 2011-06-21 20:15:48 each Exp $ */ +/* $Id: rbtdb.c,v 1.310.8.5 2011-06-08 23:02:42 each Exp $ */ /*! \file */ @@ -436,8 +436,12 @@ typedef struct { rbtnodelist_t *deadnodes; /* - * Heaps. Each of these is used for TTL based expiry. + * Heaps. These are used for TTL based expiry in a cache, + * or for zone resigning in a zone DB. hmctx is the memory + * context to use for the heap (which differs from the main + * database memory context in the case of a cache). */ + isc_mem_t * hmctx; isc_heap_t **heaps; /* Locked by tree_lock. */ @@ -955,9 +959,8 @@ free_rbtdb(dns_rbtdb_t *rbtdb, isc_boolean_t log, isc_event_t *event) { if (rbtdb->heaps != NULL) { for (i = 0; i < rbtdb->node_lock_count; i++) isc_heap_destroy(&rbtdb->heaps[i]); - isc_mem_put(rbtdb->common.mctx, rbtdb->heaps, - rbtdb->node_lock_count * - sizeof(isc_heap_t *)); + isc_mem_put(rbtdb->hmctx, rbtdb->heaps, + rbtdb->node_lock_count * sizeof(isc_heap_t *)); } if (rbtdb->rrsetstats != NULL) @@ -979,6 +982,7 @@ free_rbtdb(dns_rbtdb_t *rbtdb, isc_boolean_t log, isc_event_t *event) { rbtdb->common.magic = 0; rbtdb->common.impmagic = 0; ondest = rbtdb->common.ondest; + isc_mem_detach(&rbtdb->hmctx); isc_mem_putanddetach(&rbtdb->common.mctx, rbtdb, sizeof(*rbtdb)); isc_ondestroy_notify(&ondest, rbtdb); } @@ -2691,10 +2695,15 @@ zone_zonecut_callback(dns_rbtnode_t *node, dns_name_t *name, void *arg) { /* * Did we find anything? */ - if (dname_header != NULL) { + if (!IS_CACHE(search->rbtdb) && !IS_STUB(search->rbtdb) && + ns_header != NULL) { /* - * Note that DNAME has precedence over NS if both exist. + * Note that NS has precedence over DNAME if both exist + * in a zone. Otherwise DNAME take precedence over NS. */ + found = ns_header; + search->zonecut_sigrdataset = NULL; + } else if (dname_header != NULL) { found = dname_header; search->zonecut_sigrdataset = sigdname_header; } else if (ns_header != NULL) { @@ -4103,6 +4112,7 @@ zone_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version, */ if (search.need_cleanup) { node = search.zonecut; + INSIST(node != NULL); lock = &(search.rbtdb->node_locks[node->locknum].lock); NODE_LOCK(lock, isc_rwlocktype_read); @@ -4404,6 +4414,7 @@ find_deepest_zonecut(rbtdb_search_t *search, dns_rbtnode_t *node, NODE_UNLOCK(lock, locktype); NODE_LOCK(lock, isc_rwlocktype_write); locktype = isc_rwlocktype_write; + POST(locktype); } if (need_headerupdate(found, search->now)) update_header(search->rbtdb, found, @@ -4908,15 +4919,9 @@ cache_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version, cname_ok && cnamesig != NULL) { /* - * If we've already got the CNAME RRSIG, - * use it, otherwise change sigtype - * so that we find it. + * If we've already got the + * CNAME RRSIG, use it. */ - if (cnamesig != NULL) - foundsig = cnamesig; - else - sigtype = - RBTDB_RDATATYPE_SIGCNAME; foundsig = cnamesig; } } else if (header->type == sigtype) { @@ -5062,6 +5067,7 @@ cache_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version, NODE_UNLOCK(lock, locktype); NODE_LOCK(lock, isc_rwlocktype_write); locktype = isc_rwlocktype_write; + POST(locktype); } if (update != NULL && need_headerupdate(update, search.now)) update_header(search.rbtdb, update, search.now); @@ -5079,6 +5085,7 @@ cache_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version, */ if (search.need_cleanup) { node = search.zonecut; + INSIST(node != NULL); lock = &(search.rbtdb->node_locks[node->locknum].lock); NODE_LOCK(lock, isc_rwlocktype_read); @@ -5244,6 +5251,7 @@ cache_findzonecut(dns_db_t *db, dns_name_t *name, unsigned int options, NODE_UNLOCK(lock, locktype); NODE_LOCK(lock, isc_rwlocktype_write); locktype = isc_rwlocktype_write; + POST(locktype); } if (need_headerupdate(found, search.now)) update_header(search.rbtdb, found, search.now); @@ -7463,16 +7471,21 @@ dns_rbtdb_create int i; dns_name_t name; isc_boolean_t (*sooner)(void *, void *); + isc_mem_t *hmctx = mctx; /* Keep the compiler happy. */ - UNUSED(argc); - UNUSED(argv); UNUSED(driverarg); rbtdb = isc_mem_get(mctx, sizeof(*rbtdb)); if (rbtdb == NULL) return (ISC_R_NOMEMORY); + /* + * If argv[0] exists, it points to a memory context to use for heap + */ + if (argc != 0) + hmctx = (isc_mem_t *) argv[0]; + memset(rbtdb, '\0', sizeof(*rbtdb)); dns_name_init(&rbtdb->common.origin, NULL); rbtdb->common.attributes = 0; @@ -7537,7 +7550,7 @@ dns_rbtdb_create /* * Create the heaps. */ - rbtdb->heaps = isc_mem_get(mctx, rbtdb->node_lock_count * + rbtdb->heaps = isc_mem_get(hmctx, rbtdb->node_lock_count * sizeof(isc_heap_t *)); if (rbtdb->heaps == NULL) { result = ISC_R_NOMEMORY; @@ -7547,7 +7560,7 @@ dns_rbtdb_create rbtdb->heaps[i] = NULL; sooner = IS_CACHE(rbtdb) ? ttl_sooner : resign_sooner; for (i = 0; i < (int)rbtdb->node_lock_count; i++) { - result = isc_heap_create(mctx, sooner, set_index, 0, + result = isc_heap_create(hmctx, sooner, set_index, 0, &rbtdb->heaps[i]); if (result != ISC_R_SUCCESS) goto cleanup_heaps; @@ -7591,6 +7604,7 @@ dns_rbtdb_create * mctx won't disappear out from under us. */ isc_mem_attach(mctx, &rbtdb->common.mctx); + isc_mem_attach(hmctx, &rbtdb->hmctx); /* * Must be initialized before free_rbtdb() is called. |