]> 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 (GitLab job 7054787) <aram@isc.org>
Wed, 18 Mar 2026 17:04:56 +0000 (17:04 +0000)
Use standard reference counting macros for dns_dtenv_t instead of
custom attach/detach functions.

(cherry picked from commit 4ac3a6520e1c8b5a19321a87466269235ff406c6)

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

index 37d4ba92e8036adcd586fdb88af4325b067583bb..2cb6ba991b96db29763386bdfd57735ba5ec8914 100644 (file)
@@ -4085,7 +4085,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;
@@ -10613,7 +10613,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 4705f23dbf2ca04d24dc68b2387b0ed4c5118f0a..aaa83d6b4319ec32264115c8d4c003075d09a516 100644 (file)
@@ -100,7 +100,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;
@@ -126,10 +126,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,
@@ -160,7 +169,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();
@@ -444,15 +453,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));
@@ -498,18 +498,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 de6c653d36e08ff39deca97f8ee4b46ac0291af6..ce854ae2a5711abd3e6c344a0b6e9bcf33c4675d 100644 (file)
@@ -377,7 +377,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 */
        dns_view_setnewzones(view, false, NULL, NULL, 0ULL);
index 45bdf2005fdc2c0ce2fc865abaab8200327abf6d..b2d1d01019c10c7a05eb90dd7bf90d6bb7d8f869 100644 (file)
@@ -90,7 +90,7 @@ ISC_LOOP_TEST_IMPL(dns_dt_create) {
                               &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);
@@ -106,7 +106,7 @@ ISC_LOOP_TEST_IMPL(dns_dt_create) {
                               &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);
@@ -123,7 +123,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);
@@ -169,7 +169,7 @@ ISC_LOOP_TEST_IMPL(dns_dt_send) {
                               &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;
 
        /*
@@ -258,8 +258,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, mctx, &handle);