2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 22:45:39 +00:00

Add detailed ADB and entry attach/detach tracing

To turn on detailed debug tracing of dns_adb and dns_adbentry
reference counting, #define ADB_TRACE at the top of adb.c. This
is off by default.
This commit is contained in:
Evan Hunt
2022-03-24 15:58:26 -07:00
committed by Ondřej Surý
parent d48d8e1cf0
commit 199be183fa
2 changed files with 80 additions and 9 deletions

View File

@@ -47,6 +47,11 @@
#include <dns/resolver.h> #include <dns/resolver.h>
#include <dns/stats.h> #include <dns/stats.h>
/* Detailed logging of attach/detach */
#ifndef ADB_TRACE
#undef ADB_TRACE
#endif
#define DNS_ADB_MAGIC ISC_MAGIC('D', 'a', 'd', 'b') #define DNS_ADB_MAGIC ISC_MAGIC('D', 'a', 'd', 'b')
#define DNS_ADB_VALID(x) ISC_MAGIC_VALID(x, DNS_ADB_MAGIC) #define DNS_ADB_VALID(x) ISC_MAGIC_VALID(x, DNS_ADB_MAGIC)
#define DNS_ADBNAME_MAGIC ISC_MAGIC('a', 'd', 'b', 'N') #define DNS_ADBNAME_MAGIC ISC_MAGIC('a', 'd', 'b', 'N')
@@ -524,17 +529,35 @@ ttlclamp(dns_ttl_t ttl) {
return (ttl); return (ttl);
} }
#define entry_attach(s, t) _entry_attach(s, t, __func__, __FILE__, __LINE__)
static void static void
entry_attach(dns_adbentry_t *source, dns_adbentry_t **targetp) { _entry_attach(dns_adbentry_t *source, dns_adbentry_t **targetp,
const char *func, const char *file, unsigned int line) {
uint_fast32_t refs;
REQUIRE(DNS_ADBENTRY_VALID(source)); REQUIRE(DNS_ADBENTRY_VALID(source));
REQUIRE(targetp != NULL && *targetp == NULL); REQUIRE(targetp != NULL && *targetp == NULL);
isc_refcount_increment(&source->references); refs = isc_refcount_increment(&source->references);
#ifdef ADB_TRACE
fprintf(stderr, "%s:%s:%u:%s(%p, %p) = %" PRIuFAST32 "\n", func, file,
line, __func__, source, targetp, refs + 1);
#else
UNUSED(func);
UNUSED(file);
UNUSED(line);
UNUSED(refs);
#endif /* ADB_TRACE */
*targetp = source; *targetp = source;
} }
#define entry_detach(ep) _entry_detach(ep, __func__, __FILE__, __LINE__)
static void static void
entry_detach(dns_adbentry_t **entryp) { _entry_detach(dns_adbentry_t **entryp, const char *func, const char *file,
unsigned int line) {
dns_adbentry_t *entry = NULL; dns_adbentry_t *entry = NULL;
uint_fast32_t refs; uint_fast32_t refs;
@@ -546,6 +569,16 @@ entry_detach(dns_adbentry_t **entryp) {
REQUIRE(DNS_ADBENTRY_VALID(entry)); REQUIRE(DNS_ADBENTRY_VALID(entry));
refs = isc_refcount_decrement(&entry->references); refs = isc_refcount_decrement(&entry->references);
#ifdef ADB_TRACE
fprintf(stderr, "%s:%s:%u:%s(%p, %p), %" PRIuFAST32 "\n", func, file,
line, __func__, entry, entryp, refs - 1);
#else
UNUSED(func);
UNUSED(file);
UNUSED(line);
#endif /* ADB_TRACE */
if (refs == 1) { if (refs == 1) {
/* /*
* If the entry is linked to a bucket, we need to * If the entry is linked to a bucket, we need to
@@ -848,6 +881,8 @@ link_entry(dns_adbentrybucket_t *ebucket, dns_adbentry_t *entry) {
REQUIRE(entry != NULL && entry->bucket == NULL); REQUIRE(entry != NULL && entry->bucket == NULL);
REQUIRE(!ISC_LINK_LINKED(entry, plink)); REQUIRE(!ISC_LINK_LINKED(entry, plink));
DP(DEF_LEVEL, "link ADB entry %p to bucket %p\n", entry, ebucket);
/* /*
* If we're in the overmem condition, take this opportunity to * If we're in the overmem condition, take this opportunity to
* clean up the least-recently used entries in the bucket. * clean up the least-recently used entries in the bucket.
@@ -902,6 +937,8 @@ unlink_entry(dns_adbentry_t *entry) {
REQUIRE(ebucket != NULL); REQUIRE(ebucket != NULL);
DP(DEF_LEVEL, "unlink ADB entry %p from bucket %p\n", entry, ebucket);
if ((entry->flags & ENTRY_IS_DEAD) != 0) { if ((entry->flags & ENTRY_IS_DEAD) != 0) {
ISC_LIST_UNLINK(ebucket->deadentries, entry, plink); ISC_LIST_UNLINK(ebucket->deadentries, entry, plink);
} else { } else {
@@ -2004,6 +2041,8 @@ destroy(dns_adb_t *adb) {
isc_result_t result; isc_result_t result;
isc_ht_iter_t *it = NULL; isc_ht_iter_t *it = NULL;
DP(DEF_LEVEL, "destroying ADB %p\n", adb);
adb->magic = 0; adb->magic = 0;
isc_task_detach(&adb->task); isc_task_detach(&adb->task);
@@ -2124,25 +2163,50 @@ free_lock:
} }
void void
dns_adb_attach(dns_adb_t *adb, dns_adb_t **adbp) { dns__adb_attach(dns_adb_t *adb, dns_adb_t **adbp, const char *func,
const char *file, unsigned int line) {
uint_fast32_t refs;
REQUIRE(DNS_ADB_VALID(adb)); REQUIRE(DNS_ADB_VALID(adb));
REQUIRE(adbp != NULL && *adbp == NULL); REQUIRE(adbp != NULL && *adbp == NULL);
REQUIRE(!atomic_load_acquire(&adb->exiting)); REQUIRE(!atomic_load_acquire(&adb->exiting));
isc_refcount_increment(&adb->references); refs = isc_refcount_increment(&adb->references);
#ifdef ADB_TRACE
fprintf(stderr, "%s:%s:%u:%s(%p, %p) = %" PRIuFAST32 "\n", func, file,
line, __func__, adb, adbp, refs + 1);
#else
UNUSED(func);
UNUSED(file);
UNUSED(line);
UNUSED(refs);
#endif /* ADB_TRACE */
*adbp = adb; *adbp = adb;
} }
void void
dns_adb_detach(dns_adb_t **adbp) { dns__adb_detach(dns_adb_t **adbp, const char *func, const char *file,
unsigned int line) {
dns_adb_t *adb = NULL; dns_adb_t *adb = NULL;
uint_fast32_t refs;
REQUIRE(adbp != NULL && DNS_ADB_VALID(*adbp)); REQUIRE(adbp != NULL && DNS_ADB_VALID(*adbp));
adb = *adbp; adb = *adbp;
*adbp = NULL; *adbp = NULL;
if (isc_refcount_decrement(&adb->references) == 1) { refs = isc_refcount_decrement(&adb->references);
#ifdef ADB_TRACE
fprintf(stderr, "%s:%s:%u:%s(%p, %p), %" PRIuFAST32 "\n", func, file,
line, __func__, adb, adbp, refs - 1);
#else
UNUSED(func);
UNUSED(file);
UNUSED(line);
#endif /* ADB_TRACE */
if (refs == 1) {
destroy(adb); destroy(adb);
} }
} }
@@ -2185,6 +2249,8 @@ dns_adb_shutdown(dns_adb_t *adb) {
return; return;
} }
DP(DEF_LEVEL, "shutting down ADB %p\n", adb);
isc_mem_clearwater(adb->mctx); isc_mem_clearwater(adb->mctx);
shutdown_names(adb); shutdown_names(adb);

View File

@@ -281,8 +281,11 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_taskmgr_t *taskmgr,
*\li #ISC_R_NOMEMORY after resource allocation failure. *\li #ISC_R_NOMEMORY after resource allocation failure.
*/ */
#define dns_adb_attach(a, ap) \
dns__adb_attach(a, ap, __func__, __FILE__, __LINE__)
void void
dns_adb_attach(dns_adb_t *adb, dns_adb_t **adbp); dns__adb_attach(dns_adb_t *adb, dns_adb_t **adbp, const char *func,
const char *file, unsigned int line);
/*% /*%
* Attach to an 'adb' to 'adbp'. * Attach to an 'adb' to 'adbp'.
* *
@@ -292,8 +295,10 @@ dns_adb_attach(dns_adb_t *adb, dns_adb_t **adbp);
* to NULL. * to NULL.
*/ */
#define dns_adb_detach(ap) dns__adb_detach(ap, __func__, __FILE__, __LINE__)
void void
dns_adb_detach(dns_adb_t **adb); dns__adb_detach(dns_adb_t **adb, const char *func, const char *file,
unsigned int line);
/*% /*%
* Delete the ADB. Sets *ADB to NULL. Cancels any outstanding requests. * Delete the ADB. Sets *ADB to NULL. Cancels any outstanding requests.
* *