mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
Pass a memory context in to dns_cache_create
(cherry picked from commit 87e3b9dbf3)
This commit is contained in:
parent
26ad166a05
commit
13be6cd991
3 changed files with 16 additions and 21 deletions
|
|
@ -4740,18 +4740,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
|
|||
* view but is not yet configured. If it is not the
|
||||
* view name but not a forward reference either, then it
|
||||
* is simply a named cache that is not shared.
|
||||
*
|
||||
* We use two separate memory contexts for the
|
||||
* cache, for the main cache memory and the heap
|
||||
* memory.
|
||||
*/
|
||||
isc_mem_create(&cmctx);
|
||||
isc_mem_setname(cmctx, "cache");
|
||||
CHECK(dns_cache_create(cmctx, named_g_taskmgr,
|
||||
CHECK(dns_cache_create(mctx, named_g_taskmgr,
|
||||
named_g_timermgr, view->rdclass,
|
||||
cachename, "rbt", 0, NULL,
|
||||
&cache));
|
||||
isc_mem_detach(&cmctx);
|
||||
}
|
||||
nsc = isc_mem_get(mctx, sizeof(*nsc));
|
||||
nsc->cache = NULL;
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ struct dns_cache {
|
|||
/* Unlocked. */
|
||||
unsigned int magic;
|
||||
isc_mutex_t lock;
|
||||
isc_mem_t *mctx; /* Main cache memory */
|
||||
isc_mem_t *mctx; /* Memory context for the dns_cache object */
|
||||
isc_mem_t *hmctx; /* Heap memory */
|
||||
isc_mem_t *tmctx; /* Tree memory */
|
||||
isc_taskmgr_t *taskmgr;
|
||||
|
|
@ -331,7 +331,7 @@ cache_free(dns_cache_t *cache) {
|
|||
}
|
||||
|
||||
isc_result_t
|
||||
dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
|
||||
dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
|
||||
const char *cachename, const char *db_type,
|
||||
unsigned int db_argc, char **db_argv, dns_cache_t **cachep) {
|
||||
|
|
@ -341,31 +341,31 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
|
|||
|
||||
REQUIRE(cachep != NULL);
|
||||
REQUIRE(*cachep == NULL);
|
||||
REQUIRE(cmctx != NULL);
|
||||
REQUIRE(mctx != NULL);
|
||||
REQUIRE(taskmgr != NULL || strcmp(db_type, "rbt") != 0);
|
||||
REQUIRE(cachename != NULL);
|
||||
|
||||
cache = isc_mem_get(cmctx, sizeof(*cache));
|
||||
cache = isc_mem_get(mctx, sizeof(*cache));
|
||||
*cache = (dns_cache_t){
|
||||
.db_type = isc_mem_strdup(cmctx, db_type),
|
||||
.db_type = isc_mem_strdup(mctx, db_type),
|
||||
.rdclass = rdclass,
|
||||
.db_argc = db_argc,
|
||||
.name = cachename == NULL ? NULL
|
||||
: isc_mem_strdup(cmctx, cachename),
|
||||
: isc_mem_strdup(mctx, cachename),
|
||||
.magic = CACHE_MAGIC,
|
||||
};
|
||||
|
||||
isc_mem_attach(cmctx, &cache->mctx);
|
||||
isc_mutex_init(&cache->lock);
|
||||
isc_mem_attach(mctx, &cache->mctx);
|
||||
|
||||
if (taskmgr != NULL) {
|
||||
isc_taskmgr_attach(taskmgr, &cache->taskmgr);
|
||||
}
|
||||
|
||||
isc_mutex_init(&cache->lock);
|
||||
isc_refcount_init(&cache->references, 1);
|
||||
isc_refcount_init(&cache->live_tasks, 1);
|
||||
|
||||
result = isc_stats_create(cmctx, &cache->stats,
|
||||
result = isc_stats_create(mctx, &cache->stats,
|
||||
dns_cachestatscounter_max);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
|
|
@ -382,7 +382,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
|
|||
}
|
||||
|
||||
if (cache->db_argc != 0) {
|
||||
cache->db_argv = isc_mem_get(cmctx,
|
||||
cache->db_argv = isc_mem_get(mctx,
|
||||
cache->db_argc * sizeof(char *));
|
||||
|
||||
for (i = 0; i < cache->db_argc; i++) {
|
||||
|
|
@ -390,7 +390,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
|
|||
}
|
||||
|
||||
for (i = extra; i < cache->db_argc; i++) {
|
||||
cache->db_argv[i] = isc_mem_strdup(cmctx,
|
||||
cache->db_argv[i] = isc_mem_strdup(mctx,
|
||||
db_argv[i - extra]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ ISC_LANG_BEGINDECLS
|
|||
*** Functions
|
||||
***/
|
||||
isc_result_t
|
||||
dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
|
||||
dns_cache_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
|
||||
const char *cachename, const char *db_type,
|
||||
unsigned int db_argc, char **db_argv, dns_cache_t **cachep);
|
||||
|
|
@ -68,7 +68,7 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
|
|||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'cmctx' are valid memory contexts.
|
||||
*\li 'mctx' is a valid memory context.
|
||||
*
|
||||
*\li 'taskmgr' is a valid task manager (if 'db_type' is "rbt").
|
||||
*
|
||||
|
|
@ -77,6 +77,8 @@ dns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
|
|||
* periodic cleaning of the cache will take place.
|
||||
*
|
||||
*\li 'cachename' is a valid string. This must not be NULL.
|
||||
|
||||
*\li 'mctx' is a valid memory context.
|
||||
*
|
||||
*\li 'cachep' is a valid pointer, and *cachep == NULL
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue