Merge branch '2979-lock-view-while-accessing-its-zone-table' into 'main'

Lock view while accessing its zone table

Closes #2979

See merge request isc-projects/bind9!5676
This commit is contained in:
Ondřej Surý
2022-01-05 15:58:02 +00:00
3 changed files with 27 additions and 24 deletions

View File

@@ -117,14 +117,13 @@ dns_zt_detach(dns_zt_t **ztp);
*/
void
dns_zt_flushanddetach(dns_zt_t **ztp);
dns_zt_flush(dns_zt_t *ztp);
/*%<
* Detach the given zonetable, if the reference count goes to zero the
* zonetable will be flushed and then freed. In either case 'ztp' is
* set to NULL.
* Schedule flushing of the given zonetable, when reference count goes
* to zero.
*
* Requires:
* \li '*ztp' to be valid
* \li 'ztp' to be valid
*/
void

View File

@@ -632,6 +632,7 @@ view_flushanddetach(dns_view_t **viewp, bool flush) {
if (isc_refcount_decrement(&view->references) == 1) {
dns_zone_t *mkzone = NULL, *rdzone = NULL;
dns_zt_t *zt = NULL;
isc_refcount_destroy(&view->references);
@@ -645,13 +646,16 @@ view_flushanddetach(dns_view_t **viewp, bool flush) {
dns_requestmgr_shutdown(view->requestmgr);
}
if (view->zonetable != NULL && view->flush) {
dns_zt_flushanddetach(&view->zonetable);
} else if (view->zonetable != NULL) {
dns_zt_detach(&view->zonetable);
LOCK(&view->lock);
if (view->zonetable != NULL) {
zt = view->zonetable;
view->zonetable = NULL;
if (view->flush) {
dns_zt_flush(zt);
}
}
LOCK(&view->lock);
if (view->managed_keys != NULL) {
mkzone = view->managed_keys;
view->managed_keys = NULL;
@@ -674,7 +678,11 @@ view_flushanddetach(dns_view_t **viewp, bool flush) {
}
UNLOCK(&view->lock);
/* Need to detach zones outside view lock */
/* Need to detach zt and zones outside view lock */
if (zt != NULL) {
dns_zt_detach(&zt);
}
if (mkzone != NULL) {
dns_zone_detach(&mkzone);
}

View File

@@ -222,17 +222,21 @@ flush(dns_zone_t *zone, void *uap) {
static void
zt_destroy(dns_zt_t *zt) {
isc_refcount_destroy(&zt->references);
isc_refcount_destroy(&zt->loads_pending);
if (atomic_load_acquire(&zt->flush)) {
(void)dns_zt_apply(zt, false, NULL, flush, NULL);
}
dns_rbt_destroy(&zt->table);
isc_rwlock_destroy(&zt->rwlock);
zt->magic = 0;
isc_mem_putanddetach(&zt->mctx, zt, sizeof(*zt));
}
static void
zt_flushanddetach(dns_zt_t **ztp, bool need_flush) {
void
dns_zt_detach(dns_zt_t **ztp) {
dns_zt_t *zt;
REQUIRE(ztp != NULL && VALID_ZT(*ztp));
@@ -240,23 +244,15 @@ zt_flushanddetach(dns_zt_t **ztp, bool need_flush) {
zt = *ztp;
*ztp = NULL;
if (need_flush) {
atomic_store_release(&zt->flush, true);
}
if (isc_refcount_decrement(&zt->references) == 1) {
zt_destroy(zt);
}
}
void
dns_zt_flushanddetach(dns_zt_t **ztp) {
zt_flushanddetach(ztp, true);
}
void
dns_zt_detach(dns_zt_t **ztp) {
zt_flushanddetach(ztp, false);
dns_zt_flush(dns_zt_t *zt) {
REQUIRE(VALID_ZT(zt));
atomic_store_release(&zt->flush, true);
}
isc_result_t