Lines Matching refs:dbtable
55 #define VALID_DBTABLE(dbtable) ISC_MAGIC_VALID(dbtable, DBTABLE_MAGIC) argument
70 dns_dbtable_t *dbtable; in dns_dbtable_create() local
76 dbtable = (dns_dbtable_t *)isc_mem_get(mctx, sizeof(*dbtable)); in dns_dbtable_create()
77 if (dbtable == NULL) in dns_dbtable_create()
80 dbtable->rbt = NULL; in dns_dbtable_create()
81 result = dns_rbt_create(mctx, dbdetach, NULL, &dbtable->rbt); in dns_dbtable_create()
85 result = isc_mutex_init(&dbtable->lock); in dns_dbtable_create()
89 result = isc_rwlock_init(&dbtable->tree_lock, 0, 0); in dns_dbtable_create()
93 dbtable->default_db = NULL; in dns_dbtable_create()
94 dbtable->mctx = NULL; in dns_dbtable_create()
95 isc_mem_attach(mctx, &dbtable->mctx); in dns_dbtable_create()
96 dbtable->rdclass = rdclass; in dns_dbtable_create()
97 dbtable->magic = DBTABLE_MAGIC; in dns_dbtable_create()
98 dbtable->references = 1; in dns_dbtable_create()
100 *dbtablep = dbtable; in dns_dbtable_create()
105 DESTROYLOCK(&dbtable->lock); in dns_dbtable_create()
108 dns_rbt_destroy(&dbtable->rbt); in dns_dbtable_create()
111 isc_mem_putanddetach(&mctx, dbtable, sizeof(*dbtable)); in dns_dbtable_create()
117 dbtable_free(dns_dbtable_t *dbtable) { in dbtable_free() argument
122 RWLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dbtable_free()
124 if (dbtable->default_db != NULL) in dbtable_free()
125 dns_db_detach(&dbtable->default_db); in dbtable_free()
127 dns_rbt_destroy(&dbtable->rbt); in dbtable_free()
129 RWUNLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dbtable_free()
131 isc_rwlock_destroy(&dbtable->tree_lock); in dbtable_free()
133 dbtable->magic = 0; in dbtable_free()
135 isc_mem_putanddetach(&dbtable->mctx, dbtable, sizeof(*dbtable)); in dbtable_free()
156 dns_dbtable_t *dbtable; in dns_dbtable_detach() local
160 dbtable = *dbtablep; in dns_dbtable_detach()
161 REQUIRE(VALID_DBTABLE(dbtable)); in dns_dbtable_detach()
163 LOCK(&dbtable->lock); in dns_dbtable_detach()
165 INSIST(dbtable->references > 0); in dns_dbtable_detach()
166 dbtable->references--; in dns_dbtable_detach()
167 if (dbtable->references == 0) in dns_dbtable_detach()
170 UNLOCK(&dbtable->lock); in dns_dbtable_detach()
173 dbtable_free(dbtable); in dns_dbtable_detach()
179 dns_dbtable_add(dns_dbtable_t *dbtable, dns_db_t *db) { in dns_dbtable_add() argument
183 REQUIRE(VALID_DBTABLE(dbtable)); in dns_dbtable_add()
184 REQUIRE(dns_db_class(db) == dbtable->rdclass); in dns_dbtable_add()
189 RWLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dns_dbtable_add()
190 result = dns_rbt_addname(dbtable->rbt, dns_db_origin(clone), clone); in dns_dbtable_add()
191 RWUNLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dns_dbtable_add()
197 dns_dbtable_remove(dns_dbtable_t *dbtable, dns_db_t *db) { in dns_dbtable_remove() argument
202 REQUIRE(VALID_DBTABLE(dbtable)); in dns_dbtable_remove()
214 RWLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dns_dbtable_remove()
216 result = dns_rbt_findname(dbtable->rbt, name, 0, NULL, in dns_dbtable_remove()
222 (void)dns_rbt_deletename(dbtable->rbt, name, ISC_FALSE); in dns_dbtable_remove()
225 RWUNLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dns_dbtable_remove()
229 dns_dbtable_adddefault(dns_dbtable_t *dbtable, dns_db_t *db) { in dns_dbtable_adddefault() argument
230 REQUIRE(VALID_DBTABLE(dbtable)); in dns_dbtable_adddefault()
231 REQUIRE(dbtable->default_db == NULL); in dns_dbtable_adddefault()
234 RWLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dns_dbtable_adddefault()
236 dbtable->default_db = NULL; in dns_dbtable_adddefault()
237 dns_db_attach(db, &dbtable->default_db); in dns_dbtable_adddefault()
239 RWUNLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dns_dbtable_adddefault()
243 dns_dbtable_getdefault(dns_dbtable_t *dbtable, dns_db_t **dbp) { in dns_dbtable_getdefault() argument
244 REQUIRE(VALID_DBTABLE(dbtable)); in dns_dbtable_getdefault()
247 RWLOCK(&dbtable->tree_lock, isc_rwlocktype_read); in dns_dbtable_getdefault()
249 dns_db_attach(dbtable->default_db, dbp); in dns_dbtable_getdefault()
251 RWUNLOCK(&dbtable->tree_lock, isc_rwlocktype_read); in dns_dbtable_getdefault()
255 dns_dbtable_removedefault(dns_dbtable_t *dbtable) { in dns_dbtable_removedefault() argument
256 REQUIRE(VALID_DBTABLE(dbtable)); in dns_dbtable_removedefault()
258 RWLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dns_dbtable_removedefault()
260 dns_db_detach(&dbtable->default_db); in dns_dbtable_removedefault()
262 RWUNLOCK(&dbtable->tree_lock, isc_rwlocktype_write); in dns_dbtable_removedefault()
266 dns_dbtable_find(dns_dbtable_t *dbtable, dns_name_t *name, in dns_dbtable_find() argument
278 RWLOCK(&dbtable->tree_lock, isc_rwlocktype_read); in dns_dbtable_find()
280 result = dns_rbt_findname(dbtable->rbt, name, rbtoptions, NULL, in dns_dbtable_find()
285 else if (dbtable->default_db != NULL) { in dns_dbtable_find()
286 dns_db_attach(dbtable->default_db, dbp); in dns_dbtable_find()
291 RWUNLOCK(&dbtable->tree_lock, isc_rwlocktype_read); in dns_dbtable_find()