* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: rbtdb.c,v 1.196.18.22 2005/10/13 01:22:56 marka Exp $ */
+/* $Id: rbtdb.c,v 1.196.18.23 2005/10/13 01:26:06 marka Exp $ */
/*! \file */
(((header)->attributes & RDATASET_ATTR_NXDOMAIN) != 0)
#define DEFAULT_NODE_LOCK_COUNT 7 /*%< Should be prime. */
-#define DEFAULT_CACHE_NODE_LOCK_COUNT 7 /*1009*/ /*%< Should be prime. */
+#define DEFAULT_CACHE_NODE_LOCK_COUNT 1009 /*%< Should be prime. */
typedef struct {
nodelock_t lock;
isc_boolean_t secure;
/* Unlocked */
- isc_mem_t ** nodemctxs;
unsigned int quantum;
} dns_rbtdb_t;
for (i = 0; i < rbtdb->node_lock_count; i++) {
isc_refcount_destroy(&rbtdb->node_locks[i].references);
NODE_DESTROYLOCK(&rbtdb->node_locks[i].lock);
-
- if (rbtdb->nodemctxs != NULL)
- isc_mem_detach(&rbtdb->nodemctxs[i]);
}
- if (rbtdb->nodemctxs != NULL)
- isc_mem_put(rbtdb->common.mctx, rbtdb->nodemctxs,
- sizeof(isc_mem_t *) * rbtdb->node_lock_count);
isc_mem_put(rbtdb->common.mctx, rbtdb->node_locks,
rbtdb->node_lock_count * sizeof(rbtdb_nodelock_t));
isc_rwlock_destroy(&rbtdb->tree_lock);
static inline void
clean_cache_node(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node) {
rdatasetheader_t *current, *dcurrent, *top_prev, *top_next, *down_next;
- isc_mem_t *mctx;
+ isc_mem_t *mctx = rbtdb->common.mctx;
/*
* Caller must be holding the node lock.
*/
- REQUIRE(rbtdb->nodemctxs != NULL);
- mctx = rbtdb->nodemctxs[node->locknum];
top_prev = NULL;
for (current = node->data; current != NULL; current = top_next) {
locktype = isc_rwlocktype_write;
if (dns_rbtnode_refcurrent(node) == 0) {
- isc_mem_t *mctx;
-
INSIST(header->down == NULL);
if (header_prev != NULL)
header_prev->next =
header->next;
else
node->data = header->next;
- INSIST(search->rbtdb->nodemctxs
- != NULL);
- mctx = search->rbtdb->nodemctxs[node->locknum];
- free_rdataset(mctx,
+ free_rdataset(search->rbtdb->common.mctx,
header);
} else {
header->attributes |=
if (dns_rbtnode_refcurrent(node)
== 0) {
- isc_mem_t *mctx;
-
INSIST(header->down == NULL);
if (header_prev != NULL)
header_prev->next =
else
node->data =
header->next;
-
- if (search->rbtdb->nodemctxs !=
- NULL)
- mctx = search->rbtdb->nodemctxs[node->locknum];
- else
- mctx = search->rbtdb->common.mctx;
- free_rdataset(mctx,
+ free_rdataset(search->rbtdb->common.mctx,
header);
} else {
header->attributes |=
if (dns_rbtnode_refcurrent(node)
== 0) {
- isc_mem_t *mctx;
-
INSIST(header->down == NULL);
if (header_prev != NULL)
header_prev->next =
header->next;
else
node->data = header->next;
- if (search->rbtdb->nodemctxs !=
- NULL)
- mctx = search->rbtdb->nodemctxs[node->locknum];
- else
- mctx = search->rbtdb->common.mctx;
- free_rdataset(mctx,
+ free_rdataset(search->rbtdb->common.mctx,
header);
} else {
header->attributes |=
locktype = isc_rwlocktype_write;
if (dns_rbtnode_refcurrent(node) == 0) {
- isc_mem_t *mctx;
-
INSIST(header->down == NULL);
if (header_prev != NULL)
header_prev->next =
header->next;
else
node->data = header->next;
- INSIST(search.rbtdb->nodemctxs != NULL);
- mctx = search.rbtdb->nodemctxs[node->locknum];
- free_rdataset(mctx,
+ free_rdataset(search.rbtdb->common.mctx,
header);
} else {
header->attributes |=
locktype = isc_rwlocktype_write;
if (dns_rbtnode_refcurrent(node) == 0) {
- isc_mem_t *mctx;
-
INSIST(header->down == NULL);
if (header_prev != NULL)
header_prev->next =
header->next;
else
node->data = header->next;
- INSIST(search.rbtdb->nodemctxs != NULL);
- mctx = search.rbtdb->nodemctxs[node->locknum];
- free_rdataset(mctx,
+ free_rdataset(search.rbtdb->common.mctx,
header);
} else {
header->attributes |=
isc_boolean_t merge;
dns_rdatatype_t nsectype, rdtype, covers;
dns_trust_t trust;
- isc_mem_t *mctx;
/*
* Add an rdatasetheader_t to a node.
else
trust = newheader->trust;
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[rbtnode->locknum];
- else
- mctx = rbtdb->common.mctx;
-
if (rbtversion != NULL && !loading) {
/*
* We always add a changed record, even if no changes end up
*/
changed = add_changed(rbtdb, rbtversion, rbtnode);
if (changed == NULL) {
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
return (ISC_R_NOMEMORY);
}
}
* The NXDOMAIN is more trusted.
*/
- free_rdataset(mctx,
+ free_rdataset(rbtdb->common.mctx,
newheader);
if (addedrdataset != NULL)
bind_rdataset(rbtdb, rbtnode,
* Deleting an already non-existent rdataset has no effect.
*/
if (header_nx && newheader_nx) {
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
return (DNS_R_UNCHANGED);
}
*/
if (rbtversion == NULL && trust < header->trust &&
(header->ttl > now || header_nx)) {
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
if (addedrdataset != NULL)
bind_rdataset(rbtdb, rbtnode, header, now,
addedrdataset);
(unsigned char *)header,
(unsigned char *)newheader,
(unsigned int)(sizeof(*newheader)),
- mctx,
+ rbtdb->common.mctx,
rbtdb->common.rdclass,
(dns_rdatatype_t)header->type,
flags, &merged);
* alone. It will get cleaned up when
* clean_zone_node() runs.
*/
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
newheader = (rdatasetheader_t *)merged;
} else {
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
return (result);
}
}
header->noqname = newheader->noqname;
newheader->noqname = NULL;
}
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
if (addedrdataset != NULL)
bind_rdataset(rbtdb, rbtnode, header, now,
addedrdataset);
header->noqname = newheader->noqname;
newheader->noqname = NULL;
}
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
if (addedrdataset != NULL)
bind_rdataset(rbtdb, rbtnode, header, now,
addedrdataset);
* loading, we MUST clean up 'header' now.
*/
newheader->down = NULL;
- free_rdataset(mctx, header);
+ free_rdataset(rbtdb->common.mctx, header);
} else {
newheader->down = topheader;
topheader->next = newheader;
* If we're trying to delete the type, don't bother.
*/
if (newheader_nx) {
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
return (DNS_R_UNCHANGED);
}
rdatasetheader_t *newheader;
isc_result_t result;
isc_boolean_t delegating;
- isc_mem_t *mctx;
REQUIRE(VALID_RBTDB(rbtdb));
} else
now = 0;
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[rbtnode->locknum];
- else
- mctx = rbtdb->common.mctx;
-
- result = dns_rdataslab_fromrdataset(rdataset, mctx,
+ result = dns_rdataslab_fromrdataset(rdataset, rbtdb->common.mctx,
®ion,
sizeof(rdatasetheader_t));
if (result != ISC_R_SUCCESS)
if ((rdataset->attributes & DNS_RDATASETATTR_NOQNAME) != 0) {
result = addnoqname(rbtdb, newheader, rdataset);
if (result != ISC_R_SUCCESS) {
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
return (result);
}
}
isc_region_t region;
isc_result_t result;
rbtdb_changed_t *changed;
- isc_mem_t *mctx;
REQUIRE(VALID_RBTDB(rbtdb));
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[rbtnode->locknum];
- else
- mctx = rbtdb->common.mctx;
-
- result = dns_rdataslab_fromrdataset(rdataset, mctx,
+ result = dns_rdataslab_fromrdataset(rdataset, rbtdb->common.mctx,
®ion,
sizeof(rdatasetheader_t));
if (result != ISC_R_SUCCESS)
(unsigned char *)header,
(unsigned char *)newheader,
(unsigned int)(sizeof(*newheader)),
- mctx,
+ rbtdb->common.mctx,
rbtdb->common.rdclass,
(dns_rdatatype_t)header->type,
flags, &subresult);
if (result == ISC_R_SUCCESS) {
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
newheader = (rdatasetheader_t *)subresult;
/*
* We have to set the serial since the rdataslab
* This subtraction would remove all of the rdata;
* add a nonexistent header instead.
*/
- free_rdataset(mctx, newheader);
- newheader = isc_mem_get(mctx,
+ free_rdataset(rbtdb->common.mctx, newheader);
+ newheader = isc_mem_get(rbtdb->common.mctx,
sizeof(*newheader));
if (newheader == NULL) {
result = ISC_R_NOMEMORY;
newheader->additional_auth = NULL;
newheader->additional_glue = NULL;
} else {
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
goto unlock;
}
* The rdataset doesn't exist, so we don't need to do anything
* to satisfy the deletion request.
*/
- free_rdataset(mctx, newheader);
+ free_rdataset(rbtdb->common.mctx, newheader);
if ((options & DNS_DBSUB_EXACT) != 0)
result = DNS_R_NOTEXACT;
else
rbtdb_version_t *rbtversion = version;
isc_result_t result;
rdatasetheader_t *newheader;
- isc_mem_t *mctx;
REQUIRE(VALID_RBTDB(rbtdb));
if (type == dns_rdatatype_rrsig && covers == 0)
return (ISC_R_NOTIMPLEMENTED);
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[rbtnode->locknum];
- else
- mctx = rbtdb->common.mctx;
-
- newheader = isc_mem_get(mctx, sizeof(*newheader));
+ newheader = isc_mem_get(rbtdb->common.mctx, sizeof(*newheader));
if (newheader == NULL)
return (ISC_R_NOMEMORY);
newheader->ttl = 0;
isc_result_t result;
isc_region_t region;
rdatasetheader_t *newheader;
- isc_mem_t *mctx;
/*
* This routine does no node locking. See comments in
#endif
}
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[node->locknum];
- else
- mctx = rbtdb->common.mctx;
- result = dns_rdataslab_fromrdataset(rdataset, mctx,
+ result = dns_rdataslab_fromrdataset(rdataset, rbtdb->common.mctx,
®ion,
sizeof(rdatasetheader_t));
if (result != ISC_R_SUCCESS)
static void
delete_callback(void *data, void *arg) {
dns_rbtdb_t *rbtdb = arg;
- dns_rbtnode_t *rbtnode = data;
rdatasetheader_t *current, *next;
- isc_mem_t *mctx;
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[rbtnode->locknum];
- else
- mctx = rbtdb->common.mctx;
- for (current = rbtnode->data; current != NULL; current = next) {
+ for (current = data; current != NULL; current = next) {
next = current->next;
- free_rdataset(mctx, current);
+ free_rdataset(rbtdb->common.mctx, current);
}
}
rbtdb->common.methods = &zone_methods;
rbtdb->common.rdclass = rdclass;
rbtdb->common.mctx = NULL;
- rbtdb->nodemctxs = NULL;
result = RBTDB_INITLOCK(&rbtdb->lock);
if (result != ISC_R_SUCCESS)
rbtdb->active = rbtdb->node_lock_count;
- if (IS_CACHE(rbtdb)) {
- rbtdb->nodemctxs = isc_mem_get(mctx,
- sizeof(isc_mem_t *) *
- rbtdb->node_lock_count);
- if (rbtdb->nodemctxs == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup_node_locks;
- }
- for (i = 0; i < (int)(rbtdb->node_lock_count); i++) {
- rbtdb->nodemctxs[i] = NULL;
- result = isc_mem_create(0, 0, &rbtdb->nodemctxs[i]);
- if (result != ISC_R_SUCCESS) {
- while (i-- > 0)
- isc_mem_detach(&rbtdb->nodemctxs[i]);
- isc_mem_put(mctx, rbtdb->nodemctxs,
- sizeof(isc_mem_t *) *
- rbtdb->node_lock_count);
- goto cleanup_node_locks;
- }
- }
- } else
- rbtdb->nodemctxs = NULL;
-
for (i = 0; i < (int)(rbtdb->node_lock_count); i++) {
result = NODE_INITLOCK(&rbtdb->node_locks[i].lock);
if (result == ISC_R_SUCCESS) {
isc_refcount_decrement(&rbtdb->node_locks[i].references, NULL);
isc_refcount_destroy(&rbtdb->node_locks[i].references);
}
- goto cleanup_nodemctxs;
+ goto cleanup_node_locks;
}
rbtdb->node_locks[i].exiting = ISC_FALSE;
}
/*
* Make the Red-Black Tree.
*/
- result = dns_rbt_create2(mctx, NULL, delete_callback, rbtdb,
- &rbtdb->tree);
+ result = dns_rbt_create(mctx, delete_callback, rbtdb, &rbtdb->tree);
if (result != ISC_R_SUCCESS) {
free_rbtdb(rbtdb, ISC_FALSE, NULL);
return (result);
return (ISC_R_SUCCESS);
- cleanup_nodemctxs:
- if (rbtdb->nodemctxs != NULL) {
- for (i = 0; i < (int)(rbtdb->node_lock_count); i++)
- isc_mem_detach(&rbtdb->nodemctxs[i]);
- isc_mem_put(mctx, rbtdb->nodemctxs,
- sizeof(isc_mem_t *) * rbtdb->node_lock_count);
- }
-
cleanup_node_locks:
isc_mem_put(mctx, rbtdb->node_locks,
rbtdb->node_lock_count * sizeof(rbtdb_nodelock_t));
acachectl_t *acarray = NULL;
acache_cbarg_t *cbarg;
unsigned int count;
- isc_mem_t *mctx;
REQUIRE(arg != NULL);
cbarg = *arg;
if (acarray[count].entry == entry)
acarray[count].entry = NULL;
INSIST(acarray[count].cbarg != NULL);
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[rbtnode->locknum];
- else
- mctx = rbtdb->common.mctx;
- isc_mem_put(mctx, acarray[count].cbarg,
+ isc_mem_put(rbtdb->common.mctx, acarray[count].cbarg,
sizeof(acache_cbarg_t));
acarray[count].cbarg = NULL;
rdatasetheader_t *header;
unsigned int total_count, count;
nodelock_t *nodelock;
- isc_mem_t *mctx;
isc_result_t result;
acachectl_t *acarray;
dns_acacheentry_t *newentry, *oldentry = NULL;
INSIST(total_count > current_count);
count = total_count - current_count - 1; /* should be private data */
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[rbtnode->locknum];
- else
- mctx = rbtdb->common.mctx;
-
- newcbarg = isc_mem_get(mctx, sizeof(*newcbarg));
+ newcbarg = isc_mem_get(rbtdb->common.mctx, sizeof(*newcbarg));
if (newcbarg == NULL)
return (ISC_R_NOMEMORY);
newcbarg->type = type;
if (acarray == NULL) {
unsigned int i;
- acarray = isc_mem_get(mctx, total_count *
+ acarray = isc_mem_get(rbtdb->common.mctx, total_count *
sizeof(acachectl_t));
if (acarray == NULL) {
if (oldentry != NULL) {
if (oldcbarg != NULL)
- acache_cancelentry(mctx, oldentry, &oldcbarg);
+ acache_cancelentry(rbtdb->common.mctx, oldentry,
+ &oldcbarg);
dns_acache_detachentry(&oldentry);
}
fail:
if (newentry != NULL) {
if (newcbarg != NULL)
- acache_cancelentry(mctx, newentry, &newcbarg);
+ acache_cancelentry(rbtdb->common.mctx, newentry,
+ &newcbarg);
dns_acache_detachentry(&newentry);
}
NODE_UNLOCK(nodelock, isc_rwlocktype_write);
if (entry != NULL) {
- if(cbarg != NULL) {
- isc_mem_t *mctx;
-
- if (rbtdb->nodemctxs != NULL)
- mctx = rbtdb->nodemctxs[rbtnode->locknum];
- else
- mctx = rbtdb->common.mctx;
-
- acache_cancelentry(mctx, entry, &cbarg);
- }
+ if(cbarg != NULL)
+ acache_cancelentry(rbtdb->common.mctx, entry, &cbarg);
dns_acache_detachentry(&entry);
}