Commit fd15c8e3 authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

Views now have a 'cache' field. The 'cachedb' field still

exists as a convenience shortcut / backwards compatibility thing.
parent b120e39d
......@@ -35,6 +35,7 @@
#include <isc/app.h>
#include <isc/dir.h>
#include <dns/cache.h>
#include <dns/confparser.h>
#include <dns/types.h>
#include <dns/result.h>
......@@ -77,7 +78,8 @@ create_default_view(isc_mem_t *mctx, dns_rdataclass_t rdclass,
dns_view_t **viewp)
{
dns_view_t *view;
dns_db_t *db;
dns_cache_t *cache;
isc_result_t result;
REQUIRE(viewp != NULL && *viewp == NULL);
......@@ -93,13 +95,13 @@ create_default_view(isc_mem_t *mctx, dns_rdataclass_t rdclass,
/*
* Cache.
*/
db = NULL;
result = dns_db_create(mctx, "rbt", dns_rootname, ISC_TRUE,
rdclass, 0, NULL, &db);
cache = NULL;
result = dns_cache_create(mctx, ns_g_taskmgr, ns_g_timermgr, rdclass,
"rbt", 0, NULL, &cache);
if (result != ISC_R_SUCCESS)
goto cleanup;
dns_view_setcachedb(view, db);
dns_db_detach(&db);
dns_view_setcache(view, cache);
dns_cache_detach(&cache);
/*
* XXXRTH Temporary support for loading cache contents.
......
......@@ -36,6 +36,7 @@
#include <isc/net.h>
#include <dns/adb.h>
#include <dns/cache.h>
#include <dns/db.h>
#include <dns/master.h>
#include <dns/name.h>
......@@ -253,7 +254,7 @@ create_managers(void)
void
create_view(void)
{
dns_db_t *db;
dns_cache_t *cache;
isc_result_t result;
/*
......@@ -266,12 +267,12 @@ create_view(void)
/*
* Cache.
*/
db = NULL;
result = dns_db_create(mctx, "rbt", dns_rootname, ISC_TRUE,
dns_rdataclass_in, 0, NULL, &db);
check_result(result, "dns_view_create");
dns_view_setcachedb(view, db);
dns_db_detach(&db);
cache = NULL;
result = dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in,
"rbt", 0, NULL, &cache);
check_result(result, "dns_cache_create");
dns_view_setcache(view, cache);
dns_cache_detach(&cache);
/*
* Resolver.
......
......@@ -80,6 +80,7 @@ struct dns_view {
dns_zt_t * zonetable;
dns_resolver_t * resolver;
dns_adb_t * adb;
dns_cache_t * cache;
dns_db_t * cachedb;
dns_db_t * hints;
dns_rbt_t * secroots;
......@@ -191,27 +192,22 @@ dns_view_createresolver(dns_view_t *view,
*/
void
dns_view_setcachedb(dns_view_t *view, dns_db_t *cachedb);
dns_view_setcache(dns_view_t *view, dns_cache_t *cache);
/*
* Set the view's cache database.
*
* Note:
*
* WARNING! THIS ROUTINE WILL BE REPLACED WITH dns_view_setcache()
* WHEN WE HAVE INTEGRATED CACHE OBJECT SUPPORT INTO THE LIBRARY.
*
* Requires:
*
* 'view' is a valid, unfrozen view.
*
* 'cachedb' is a valid cache database.
* 'cache' is a valid cache.
*
* Ensures:
*
* The cache database of 'view' is 'cachedb'.
* The cache of 'view' is 'cached.
*
* If this is not the first call to dns_view_setcachedb() for this
* view, then previously set db is detached.
* If this is not the first call to dns_view_setcache() for this
* view, then previously set cache is detached.
*/
void
......
......@@ -27,6 +27,7 @@
#include <dns/types.h>
#include <dns/adb.h>
#include <dns/cache.h>
#include <dns/dbtable.h>
#include <dns/db.h>
#include <dns/events.h>
......@@ -93,6 +94,7 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
goto cleanup_zt;
}
view->cache = NULL;
view->cachedb = NULL;
view->hints = NULL;
view->resolver = NULL;
......@@ -169,6 +171,8 @@ destroy(dns_view_t *view) {
dns_db_detach(&view->hints);
if (view->cachedb != NULL)
dns_db_detach(&view->cachedb);
if (view->cache != NULL)
dns_cache_detach(&view->cache);
dns_zt_detach(&view->zonetable);
dns_rbt_destroy(&view->secroots);
isc_mutex_destroy(&view->lock);
......@@ -310,24 +314,22 @@ dns_view_createresolver(dns_view_t *view,
}
void
dns_view_setcachedb(dns_view_t *view, dns_db_t *cachedb) {
dns_view_setcache(dns_view_t *view, dns_cache_t *cache) {
/*
* Set the view's cache database.
*/
/*
* WARNING! THIS ROUTINE WILL BE REPLACED WITH dns_view_setcache()
* WHEN WE HAVE INTEGRATED CACHE OBJECT SUPPORT INTO THE LIBRARY.
* Set the view's cache.
*/
REQUIRE(DNS_VIEW_VALID(view));
REQUIRE(!view->frozen);
REQUIRE(dns_db_iscache(cachedb));
if (view->cachedb != NULL)
if (view->cache != NULL) {
dns_db_detach(&view->cachedb);
dns_db_attach(cachedb, &view->cachedb);
dns_cache_detach(&view->cache);
}
dns_cache_attach(cache, &view->cache);
dns_cache_attachdb(cache, &view->cachedb);
INSIST(DNS_DB_VALID(view->cachedb));
}
void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment