mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 05:28:00 +00:00
remove ADB whenshutdown events
weakly attaching and detaching the view when creating or destroying the ADB obviates the need for a whenshutdown callback event to do the detaching. remove the dns_adb_whenshutdown() mechanism, since it is no longer needed.
This commit is contained in:
parent
3027f59f6f
commit
a2d491279a
@ -117,10 +117,7 @@ struct dns_adb {
|
||||
|
||||
isc_stats_t *stats;
|
||||
|
||||
isc_event_t cevent;
|
||||
bool cevent_out;
|
||||
atomic_bool exiting;
|
||||
isc_eventlist_t whenshutdown;
|
||||
|
||||
uint32_t quota;
|
||||
uint32_t atr_freq;
|
||||
@ -1237,7 +1234,9 @@ clean_finds_at_name(dns_adbname_t *name, isc_eventtype_t evtype,
|
||||
ev->ev_destroy = event_freefind;
|
||||
ev->ev_destroy_arg = find;
|
||||
|
||||
DP(DEF_LEVEL, "sending event %p to task %p for find %p",
|
||||
DP(DEF_LEVEL,
|
||||
"cfan: sending event %p "
|
||||
"to task %p for find %p",
|
||||
ev, task, find);
|
||||
|
||||
isc_task_sendanddetach(&task, (isc_event_t **)&ev);
|
||||
@ -2045,8 +2044,7 @@ destroy(dns_adb_t *adb) {
|
||||
|
||||
adb->magic = 0;
|
||||
|
||||
isc_task_detach(&adb->task);
|
||||
|
||||
RWLOCK(&adb->names_lock, isc_rwlocktype_write);
|
||||
isc_ht_iter_create(adb->namebuckets, &it);
|
||||
for (result = isc_ht_iter_first(it); result == ISC_R_SUCCESS;
|
||||
result = isc_ht_iter_delcurrent_next(it))
|
||||
@ -2058,7 +2056,10 @@ destroy(dns_adb_t *adb) {
|
||||
}
|
||||
isc_ht_iter_destroy(&it);
|
||||
isc_ht_destroy(&adb->namebuckets);
|
||||
RWUNLOCK(&adb->names_lock, isc_rwlocktype_write);
|
||||
isc_rwlock_destroy(&adb->names_lock);
|
||||
|
||||
RWLOCK(&adb->entries_lock, isc_rwlocktype_write);
|
||||
isc_ht_iter_create(adb->entrybuckets, &it);
|
||||
for (result = isc_ht_iter_first(it); result == ISC_R_SUCCESS;
|
||||
result = isc_ht_iter_delcurrent_next(it))
|
||||
@ -2070,12 +2071,14 @@ destroy(dns_adb_t *adb) {
|
||||
}
|
||||
isc_ht_iter_destroy(&it);
|
||||
isc_ht_destroy(&adb->entrybuckets);
|
||||
|
||||
isc_rwlock_destroy(&adb->names_lock);
|
||||
RWUNLOCK(&adb->entries_lock, isc_rwlocktype_write);
|
||||
isc_rwlock_destroy(&adb->entries_lock);
|
||||
|
||||
isc_mutex_destroy(&adb->lock);
|
||||
|
||||
isc_task_detach(&adb->task);
|
||||
isc_stats_detach(&adb->stats);
|
||||
dns_view_weakdetach(&adb->view);
|
||||
isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
|
||||
}
|
||||
|
||||
@ -2096,7 +2099,6 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_taskmgr_t *taskmgr,
|
||||
|
||||
adb = isc_mem_get(mem, sizeof(dns_adb_t));
|
||||
*adb = (dns_adb_t){
|
||||
.view = view,
|
||||
.taskmgr = taskmgr,
|
||||
};
|
||||
|
||||
@ -2105,11 +2107,7 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_taskmgr_t *taskmgr,
|
||||
* that must be NULL for the error return to work properly.
|
||||
*/
|
||||
isc_refcount_init(&adb->references, 1);
|
||||
ISC_EVENT_INIT(&adb->cevent, sizeof(adb->cevent), 0, NULL, 0, NULL,
|
||||
NULL, NULL, NULL, NULL);
|
||||
ISC_LIST_INIT(adb->whenshutdown);
|
||||
atomic_init(&adb->exiting, false);
|
||||
|
||||
dns_view_weakattach(view, &adb->view);
|
||||
isc_mem_attach(mem, &adb->mctx);
|
||||
|
||||
isc_ht_init(&adb->namebuckets, adb->mctx, 1, ISC_HT_CASE_INSENSITIVE);
|
||||
@ -2158,6 +2156,7 @@ free_lock:
|
||||
isc_rwlock_destroy(&adb->names_lock);
|
||||
isc_ht_destroy(&adb->namebuckets);
|
||||
|
||||
dns_view_weakdetach(&adb->view);
|
||||
isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
|
||||
|
||||
return (result);
|
||||
@ -2211,39 +2210,8 @@ dns__adb_detach(dns_adb_t **adbp, const char *func, const char *file,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp) {
|
||||
isc_event_t *event = NULL;
|
||||
|
||||
/*
|
||||
* Send '*eventp' to 'task' when 'adb' has shutdown.
|
||||
*/
|
||||
|
||||
REQUIRE(DNS_ADB_VALID(adb));
|
||||
REQUIRE(eventp != NULL);
|
||||
|
||||
event = *eventp;
|
||||
*eventp = NULL;
|
||||
|
||||
if (atomic_load(&adb->exiting)) {
|
||||
/*
|
||||
* We're already shutdown. Send the event.
|
||||
*/
|
||||
event->ev_sender = adb;
|
||||
isc_task_send(task, &event);
|
||||
} else {
|
||||
LOCK(&adb->lock);
|
||||
isc_task_attach(task, &(isc_task_t *){ NULL });
|
||||
event->ev_sender = task;
|
||||
ISC_LIST_APPEND(adb->whenshutdown, event, ev_link);
|
||||
UNLOCK(&adb->lock);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dns_adb_shutdown(dns_adb_t *adb) {
|
||||
isc_event_t *event = NULL;
|
||||
|
||||
if (!atomic_compare_exchange_strong(&adb->exiting, &(bool){ false },
|
||||
true)) {
|
||||
return;
|
||||
@ -2255,17 +2223,6 @@ dns_adb_shutdown(dns_adb_t *adb) {
|
||||
|
||||
shutdown_names(adb);
|
||||
shutdown_entries(adb);
|
||||
|
||||
LOCK(&adb->lock);
|
||||
for (event = ISC_LIST_HEAD(adb->whenshutdown); event != NULL;
|
||||
event = ISC_LIST_HEAD(adb->whenshutdown))
|
||||
{
|
||||
isc_task_t *task = event->ev_sender;
|
||||
event->ev_sender = adb;
|
||||
ISC_LIST_UNLINK(adb->whenshutdown, event, ev_link);
|
||||
isc_task_sendanddetach(&task, &event);
|
||||
}
|
||||
UNLOCK(&adb->lock);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3175,7 +3132,7 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) {
|
||||
name = ev->ev_arg;
|
||||
|
||||
REQUIRE(DNS_ADBNAME_VALID(name));
|
||||
adb = name->adb;
|
||||
dns_adb_attach(name->adb, &adb);
|
||||
|
||||
REQUIRE(DNS_ADB_VALID(adb));
|
||||
|
||||
@ -3199,9 +3156,6 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) {
|
||||
|
||||
INSIST(address_type != 0 && fetch != NULL);
|
||||
|
||||
dns_resolver_destroyfetch(&fetch->fetch);
|
||||
dev->fetch = NULL;
|
||||
|
||||
ev_status = DNS_EVENT_ADBNOMOREADDRESSES;
|
||||
|
||||
/*
|
||||
@ -3219,11 +3173,8 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) {
|
||||
* potentially good data.
|
||||
*/
|
||||
if (NAME_DEAD(name)) {
|
||||
free_adbfetch(adb, &fetch);
|
||||
isc_event_free(&ev);
|
||||
expire_name(&name, DNS_EVENT_ADBCANCELED);
|
||||
UNLOCK(&nbucket->lock);
|
||||
return;
|
||||
ev_status = DNS_EVENT_ADBCANCELED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
isc_stdtime_get(&now);
|
||||
@ -3327,12 +3278,16 @@ check_result:
|
||||
}
|
||||
|
||||
out:
|
||||
dns_resolver_destroyfetch(&fetch->fetch);
|
||||
free_adbfetch(adb, &fetch);
|
||||
isc_event_free(&ev);
|
||||
|
||||
clean_finds_at_name(name, ev_status, address_type);
|
||||
|
||||
if (ev_status == DNS_EVENT_ADBCANCELED) {
|
||||
expire_name(&name, ev_status);
|
||||
} else {
|
||||
clean_finds_at_name(name, ev_status, address_type);
|
||||
}
|
||||
UNLOCK(&nbucket->lock);
|
||||
dns_adb_detach(&adb);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
|
@ -308,25 +308,6 @@ dns__adb_detach(dns_adb_t **adb, const char *func, const char *file,
|
||||
* dns_adb_create().
|
||||
*/
|
||||
|
||||
void
|
||||
dns_adb_whenshutdown(dns_adb_t *adb, isc_task_t *task, isc_event_t **eventp);
|
||||
/*%
|
||||
* Send '*eventp' to 'task' when 'adb' has shutdown.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li '*adb' is a valid dns_adb_t.
|
||||
*
|
||||
*\li eventp != NULL && *eventp is a valid event.
|
||||
*
|
||||
* Ensures:
|
||||
*
|
||||
*\li *eventp == NULL
|
||||
*
|
||||
*\li The event's sender field is set to the value of adb when the event
|
||||
* is sent.
|
||||
*/
|
||||
|
||||
void
|
||||
dns_adb_shutdown(dns_adb_t *adb);
|
||||
/*%<
|
||||
|
@ -20,10 +20,10 @@
|
||||
* Registry of DNS event numbers.
|
||||
*/
|
||||
|
||||
#define DNS_EVENT_FETCHCONTROL (ISC_EVENTCLASS_DNS + 0)
|
||||
#define DNS_EVENT_FETCHDONE (ISC_EVENTCLASS_DNS + 1)
|
||||
#define DNS_EVENT_VIEWRESSHUTDOWN (ISC_EVENTCLASS_DNS + 2)
|
||||
#define DNS_EVENT_VIEWADBSHUTDOWN (ISC_EVENTCLASS_DNS + 3)
|
||||
#define DNS_EVENT_FETCHCONTROL (ISC_EVENTCLASS_DNS + 0)
|
||||
#define DNS_EVENT_FETCHDONE (ISC_EVENTCLASS_DNS + 1)
|
||||
#define DNS_EVENT_VIEWRESSHUTDOWN (ISC_EVENTCLASS_DNS + 2)
|
||||
/* #define DNS_EVENT_VIEWADBSHUTDOWN (ISC_EVENTCLASS_DNS + 3) */
|
||||
#define DNS_EVENT_UPDATE (ISC_EVENTCLASS_DNS + 4)
|
||||
#define DNS_EVENT_UPDATEDONE (ISC_EVENTCLASS_DNS + 5)
|
||||
#define DNS_EVENT_DISPATCH (ISC_EVENTCLASS_DNS + 6)
|
||||
|
@ -105,7 +105,6 @@ struct dns_view {
|
||||
bool frozen;
|
||||
isc_task_t *task;
|
||||
isc_event_t resevent;
|
||||
isc_event_t adbevent;
|
||||
isc_event_t reqevent;
|
||||
bool cacheshared;
|
||||
|
||||
|
@ -78,8 +78,6 @@
|
||||
static void
|
||||
resolver_shutdown(isc_task_t *task, isc_event_t *event);
|
||||
static void
|
||||
adb_shutdown(isc_task_t *task, isc_event_t *event);
|
||||
static void
|
||||
req_shutdown(isc_task_t *task, isc_event_t *event);
|
||||
|
||||
isc_result_t
|
||||
@ -133,9 +131,6 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, const char *name,
|
||||
ISC_EVENT_INIT(&view->resevent, sizeof(view->resevent), 0, NULL,
|
||||
DNS_EVENT_VIEWRESSHUTDOWN, resolver_shutdown, view, NULL,
|
||||
NULL, NULL);
|
||||
ISC_EVENT_INIT(&view->adbevent, sizeof(view->adbevent), 0, NULL,
|
||||
DNS_EVENT_VIEWADBSHUTDOWN, adb_shutdown, view, NULL,
|
||||
NULL, NULL);
|
||||
ISC_EVENT_INIT(&view->reqevent, sizeof(view->reqevent), 0, NULL,
|
||||
DNS_EVENT_VIEWREQSHUTDOWN, req_shutdown, view, NULL,
|
||||
NULL, NULL);
|
||||
@ -525,6 +520,7 @@ dns_view_detach(dns_view_t **viewp) {
|
||||
}
|
||||
if (view->adb != NULL) {
|
||||
dns_adb_shutdown(view->adb);
|
||||
dns_adb_detach(&view->adb);
|
||||
}
|
||||
if (view->requestmgr != NULL) {
|
||||
dns_requestmgr_shutdown(view->requestmgr);
|
||||
@ -635,21 +631,6 @@ resolver_shutdown(isc_task_t *task, isc_event_t *event) {
|
||||
dns_view_weakdetach(&view);
|
||||
}
|
||||
|
||||
static void
|
||||
adb_shutdown(isc_task_t *task, isc_event_t *event) {
|
||||
dns_view_t *view = event->ev_arg;
|
||||
|
||||
REQUIRE(event->ev_type == DNS_EVENT_VIEWADBSHUTDOWN);
|
||||
REQUIRE(DNS_VIEW_VALID(view));
|
||||
REQUIRE(view->task == task);
|
||||
|
||||
UNUSED(task);
|
||||
|
||||
isc_event_free(&event);
|
||||
|
||||
dns_view_weakdetach(&view);
|
||||
}
|
||||
|
||||
static void
|
||||
req_shutdown(isc_task_t *task, isc_event_t *event) {
|
||||
dns_view_t *view = event->ev_arg;
|
||||
@ -702,22 +683,19 @@ dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
||||
isc_task_detach(&view->task);
|
||||
return (result);
|
||||
}
|
||||
|
||||
dns_view_weakattach(view, &(dns_view_t *){ NULL });
|
||||
event = &view->resevent;
|
||||
dns_resolver_whenshutdown(view->resolver, view->task, &event);
|
||||
isc_refcount_increment(&view->weakrefs);
|
||||
|
||||
isc_mem_create(&mctx);
|
||||
isc_mem_setname(mctx, "ADB");
|
||||
|
||||
result = dns_adb_create(mctx, view, taskmgr, &view->adb);
|
||||
isc_mem_detach(&mctx);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
dns_resolver_shutdown(view->resolver);
|
||||
return (result);
|
||||
}
|
||||
event = &view->adbevent;
|
||||
dns_adb_whenshutdown(view->adb, view->task, &event);
|
||||
isc_refcount_increment(&view->weakrefs);
|
||||
|
||||
result = dns_requestmgr_create(
|
||||
view->mctx, dns_resolver_taskmgr(view->resolver),
|
||||
@ -725,12 +703,14 @@ dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
||||
dispatchv6, &view->requestmgr);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
dns_adb_shutdown(view->adb);
|
||||
dns_adb_detach(&view->adb);
|
||||
dns_resolver_shutdown(view->resolver);
|
||||
return (result);
|
||||
}
|
||||
|
||||
dns_view_weakattach(view, &(dns_view_t *){ NULL });
|
||||
event = &view->reqevent;
|
||||
dns_requestmgr_whenshutdown(view->requestmgr, view->task, &event);
|
||||
isc_refcount_increment(&view->weakrefs);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user