]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Convert dns_dtenv_t reference counting to standard macors
authorAram Sargsyan <aram@isc.org>
Tue, 17 Mar 2026 11:22:04 +0000 (11:22 +0000)
committerArаm Sаrgsyаn <aram@isc.org>
Wed, 18 Mar 2026 16:10:07 +0000 (16:10 +0000)
Use standard reference counting macros for dns_dtenv_t instead of
custom attach/detach functions.

bin/named/server.c
lib/dns/dnstap.c
lib/dns/include/dns/dnstap.h
lib/dns/view.c
tests/dns/dnstap_test.c

index 0408cfc92f839b0b9ed9bd18ff39bfae5ac8284c..78176773b2ea2b760f2afe808e7e0545fda25cd9 100644 (file)
@@ -3507,7 +3507,7 @@ configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) {
                                   cfg_obj_asstring(obj));
        }
 
-       dns_dt_attach(named_g_server->dtenv, &view->dtenv);
+       dns_dtenv_attach(named_g_server->dtenv, &view->dtenv);
        view->dttypes = dttypes;
 
        result = ISC_R_SUCCESS;
@@ -9461,7 +9461,7 @@ named_server_destroy(named_server_t **serverp) {
 
 #ifdef HAVE_DNSTAP
        if (server->dtenv != NULL) {
-               dns_dt_detach(&server->dtenv);
+               dns_dtenv_detach(&server->dtenv);
        }
 #endif /* HAVE_DNSTAP */
 
index 80290c54adbe1e3e19bca5cf0d67dd5dae5bada1..00f073d0a95e1bd969482a8ed7b01579773fe9bc 100644 (file)
@@ -99,7 +99,7 @@ struct dns_dthandle {
 
 struct dns_dtenv {
        unsigned int magic;
-       isc_refcount_t refcount;
+       isc_refcount_t references;
 
        isc_mem_t *mctx;
        isc_loop_t *loop;
@@ -125,10 +125,19 @@ typedef struct ioq {
        struct fstrm_iothr_queue *ioq;
 } dt__ioq_t;
 
+static void
+destroy(dns_dtenv_t *env);
+
 static thread_local dt__ioq_t dt_ioq = { 0 };
 
 static atomic_uint_fast32_t global_generation;
 
+#if DNS_DTENV_TRACE
+ISC_REFCOUNT_TRACE_IMPL(dns_dtenv, destroy);
+#else
+ISC_REFCOUNT_IMPL(dns_dtenv, destroy);
+#endif /* DNS_DTENV_TRACE */
+
 isc_result_t
 dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path,
              struct fstrm_iothr_options **foptp, isc_loop_t *loop,
@@ -159,7 +168,7 @@ dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path,
        isc_mem_attach(mctx, &env->mctx);
        isc_mutex_init(&env->reopen_lock);
        env->path = isc_mem_strdup(env->mctx, path);
-       isc_refcount_init(&env->refcount, 1);
+       isc_refcount_init(&env->references, 1);
        isc_stats_create(env->mctx, &env->stats, dns_dnstapcounter_max);
 
        fwopt = fstrm_writer_options_init();
@@ -441,15 +450,6 @@ dt_queue(dns_dtenv_t *env) {
        return dt_ioq.ioq;
 }
 
-void
-dns_dt_attach(dns_dtenv_t *source, dns_dtenv_t **destp) {
-       REQUIRE(VALID_DTENV(source));
-       REQUIRE(destp != NULL && *destp == NULL);
-
-       isc_refcount_increment(&source->refcount);
-       *destp = source;
-}
-
 isc_result_t
 dns_dt_getstats(dns_dtenv_t *env, isc_stats_t **statsp) {
        REQUIRE(VALID_DTENV(env));
@@ -495,18 +495,6 @@ destroy(dns_dtenv_t *env) {
        isc_mem_putanddetach(&env->mctx, env, sizeof(*env));
 }
 
-void
-dns_dt_detach(dns_dtenv_t **envp) {
-       REQUIRE(envp != NULL && VALID_DTENV(*envp));
-       dns_dtenv_t *env = *envp;
-       *envp = NULL;
-
-       if (isc_refcount_decrement(&env->refcount) == 1) {
-               isc_refcount_destroy(&env->refcount);
-               destroy(env);
-       }
-}
-
 static isc_result_t
 pack_dt(const Dnstap__Dnstap *d, void **buf, size_t *sz) {
        ProtobufCBufferSimple sbuf;
index 3f83e96d228360c5eb8dfbdaf9633eea94febffb..191d9641583294a42bc502b1b28f3ad72d39b5da 100644 (file)
@@ -118,6 +118,21 @@ struct dns_dtdata {
 };
 #endif /* HAVE_DNSTAP */
 
+#if DNS_DTENV_TRACE
+#define dns_dtenv_ref(ptr)   dns_dtenv__ref(ptr, __func__, __FILE__, __LINE__)
+#define dns_dtenv_unref(ptr) dns_dtenv__unref(ptr, __func__, __FILE__, __LINE__)
+#define dns_dtenv_attach(ptr, ptrp) \
+       dns_dtenv__attach(ptr, ptrp, __func__, __FILE__, __LINE__)
+#define dns_dtenv_detach(ptrp) \
+       dns_dtenv__detach(ptrp, __func__, __FILE__, __LINE__)
+ISC_REFCOUNT_TRACE_DECL(dns_dtenv);
+#else
+ISC_REFCOUNT_DECL(dns_dtenv);
+#endif /* DNS_DTENV_TRACE */
+/*%
+ * Reference counting for dns_dtenv
+ */
+
 isc_result_t
 dns_dt_create(isc_mem_t *mctx, dns_dtmode_t mode, const char *path,
              struct fstrm_iothr_options **foptp, isc_loop_t *loop,
@@ -215,36 +230,6 @@ dns_dt_setversion(dns_dtenv_t *env, const char *version);
  *\li  'env' is a valid dnstap environment.
  */
 
-void
-dns_dt_attach(dns_dtenv_t *source, dns_dtenv_t **destp);
-/*%<
- * Attach '*destp' to 'source', incrementing the reference counter.
- *
- * Requires:
- *
- *\li  'source' is a valid dnstap environment.
- *
- *\li  'destp' is not NULL and '*destp' is NULL.
- *
- *\li  *destp is attached to source.
- */
-
-void
-dns_dt_detach(dns_dtenv_t **envp);
-/*%<
- * Detach '*envp', decrementing the reference counter.
- *
- * Requires:
- *
- *\li  '*envp' is a valid dnstap environment.
- *
- * Ensures:
- *
- *\li  '*envp' will be destroyed when the number of references reaches zero.
- *
- *\li  '*envp' is NULL.
- */
-
 isc_result_t
 dns_dt_getstats(dns_dtenv_t *env, isc_stats_t **statsp);
 /*%<
index 906c5bb54912b26ec47b9227d53916e5b4c9d3af..d31d17161ad0b57d00d92e364d814660a4cc6200 100644 (file)
@@ -332,7 +332,7 @@ destroy(dns_view_t *view) {
        }
 #ifdef HAVE_DNSTAP
        if (view->dtenv != NULL) {
-               dns_dt_detach(&view->dtenv);
+               dns_dtenv_detach(&view->dtenv);
        }
 #endif /* HAVE_DNSTAP */
        if (view->newzone.cleanup != NULL) {
index e39725f55eef66368f0ef1b2939856b55cefff18..4a1c941bb0d80fc7228b1a283bc5209a9a5129b0 100644 (file)
@@ -92,7 +92,7 @@ ISC_LOOP_TEST_IMPL(dns_dt_create) {
                               NULL, &dtenv);
        assert_int_equal(result, ISC_R_SUCCESS);
        if (dtenv != NULL) {
-               dns_dt_detach(&dtenv);
+               dns_dtenv_detach(&dtenv);
        }
        if (fopt != NULL) {
                fstrm_iothr_options_destroy(&fopt);
@@ -108,7 +108,7 @@ ISC_LOOP_TEST_IMPL(dns_dt_create) {
                               NULL, &dtenv);
        assert_int_equal(result, ISC_R_SUCCESS);
        if (dtenv != NULL) {
-               dns_dt_detach(&dtenv);
+               dns_dtenv_detach(&dtenv);
        }
        if (fopt != NULL) {
                fstrm_iothr_options_destroy(&fopt);
@@ -125,7 +125,7 @@ ISC_LOOP_TEST_IMPL(dns_dt_create) {
        assert_int_equal(result, ISC_R_FAILURE);
        assert_null(dtenv);
        if (dtenv != NULL) {
-               dns_dt_detach(&dtenv);
+               dns_dtenv_detach(&dtenv);
        }
        if (fopt != NULL) {
                fstrm_iothr_options_destroy(&fopt);
@@ -171,7 +171,7 @@ ISC_LOOP_TEST_IMPL(dns_dt_send) {
                               NULL, &dtenv);
        assert_int_equal(result, ISC_R_SUCCESS);
 
-       dns_dt_attach(dtenv, &view->dtenv);
+       dns_dtenv_attach(dtenv, &view->dtenv);
        view->dttypes = DNS_DTTYPE_ALL;
 
        /*
@@ -260,8 +260,8 @@ ISC_LOOP_TEST_IMPL(dns_dt_send) {
                            m);
        }
 
-       dns_dt_detach(&view->dtenv);
-       dns_dt_detach(&dtenv);
+       dns_dtenv_detach(&view->dtenv);
+       dns_dtenv_detach(&dtenv);
        dns_view_detach(&view);
 
        result = dns_dt_open(TAPFILE, dns_dtmode_file, isc_g_mctx, &handle);