aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/rbtdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dns/rbtdb.c')
-rw-r--r--lib/dns/rbtdb.c54
1 files changed, 34 insertions, 20 deletions
diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c
index 87b70e376e05..66ef0277d1cb 100644
--- a/lib/dns/rbtdb.c
+++ b/lib/dns/rbtdb.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004-2011 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1999-2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: rbtdb.c,v 1.270.12.26.4.1 2011-06-21 20:13:23 each Exp $ */
+/* $Id: rbtdb.c,v 1.270.12.32 2011-06-09 00:16:35 each Exp $ */
/*! \file */
@@ -435,8 +435,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. */
@@ -957,9 +961,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)
@@ -976,6 +979,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);
}
@@ -2641,10 +2645,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) {
@@ -3926,6 +3935,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);
@@ -4226,6 +4236,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,
@@ -4536,15 +4547,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) {
@@ -4690,6 +4695,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);
@@ -4707,6 +4713,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);
@@ -4872,6 +4879,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);
@@ -6970,16 +6978,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;
@@ -7044,7 +7057,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;
@@ -7054,7 +7067,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;
@@ -7098,6 +7111,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.