diff --git a/lib/dns/db.c b/lib/dns/db.c index be9492fcfd..8a25990bee 100644 --- a/lib/dns/db.c +++ b/lib/dns/db.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -118,6 +119,15 @@ dns_db_detach(dns_db_t **dbp) { ENSURE(*dbp == NULL); } +isc_result_t +dns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp) +{ + REQUIRE(DNS_DB_VALID(db)); + + return (isc_ondestroy_register(&db->ondest, task, eventp)); +} + + isc_boolean_t dns_db_iscache(dns_db_t *db) { diff --git a/lib/dns/include/dns/db.h b/lib/dns/include/dns/db.h index bc7a9aa1e7..fd7e481d8e 100644 --- a/lib/dns/include/dns/db.h +++ b/lib/dns/include/dns/db.h @@ -164,6 +164,7 @@ struct dns_db { isc_uint16_t attributes; dns_rdataclass_t rdclass; dns_name_t origin; + isc_ondestroy_t ondest; isc_mem_t * mctx; }; @@ -267,6 +268,17 @@ dns_db_detach(dns_db_t **dbp); * All resources used by the database will be freed */ +isc_result_t +dns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp); +/* + * Causes 'eventp' to be sent to be sent to 'task' when the database is + * destroyed. + * + * Note; ownrship of the eventp is taken from the caller (and *eventp is + * set to NULL). The sender field of the event is set to 'db' before it is + * sent to the task. + */ + isc_boolean_t dns_db_iscache(dns_db_t *db); /* diff --git a/lib/dns/include/dns/events.h b/lib/dns/include/dns/events.h index 92b85c74a1..c3e0f05070 100644 --- a/lib/dns/include/dns/events.h +++ b/lib/dns/include/dns/events.h @@ -45,6 +45,7 @@ ISC_LANG_BEGINDECLS #define DNS_EVENT_CACHECLEAN (ISC_EVENTCLASS_DNS + 15) #define DNS_EVENT_BYADDRDONE (ISC_EVENTCLASS_DNS + 16) #define DNS_EVENT_ZONECONTROL (ISC_EVENTCLASS_DNS + 17) +#define DNS_EVENT_DBDESTROYED (ISC_EVENTCLASS_DNS + 18) #define DNS_EVENT_FIRSTEVENT (ISC_EVENTCLASS_DNS + 0) #define DNS_EVENT_LASTEVENT (ISC_EVENTCLASS_DNS + 65535) diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index 5984ee61b7..b31c793364 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -313,6 +313,7 @@ static void free_rbtdb(dns_rbtdb_t *rbtdb) { unsigned int i; isc_region_t r; + isc_ondestroy_t ondest; REQUIRE(EMPTY(rbtdb->open_versions)); REQUIRE(rbtdb->future_version == NULL); @@ -332,7 +333,9 @@ free_rbtdb(dns_rbtdb_t *rbtdb) { isc_mutex_destroy(&rbtdb->lock); rbtdb->common.magic = 0; rbtdb->common.impmagic = 0; + ondest = rbtdb->common.ondest; isc_mem_put(rbtdb->common.mctx, rbtdb, sizeof *rbtdb); + isc_ondestroy_notify(&ondest, rbtdb); } static inline void @@ -3924,6 +3927,8 @@ dns_rbtdb_create rbtdb->future_version = NULL; ISC_LIST_INIT(rbtdb->open_versions); + isc_ondestroy_init(&rbtdb->common.ondest); + rbtdb->common.magic = DNS_DB_MAGIC; rbtdb->common.impmagic = RBTDB_MAGIC;