]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
refactor dns_master_dump*async() to use loop callbacks
authorEvan Hunt <each@isc.org>
Wed, 26 Oct 2022 18:12:36 +0000 (11:12 -0700)
committerOndřej Surý <ondrej@isc.org>
Mon, 31 Oct 2022 10:30:27 +0000 (10:30 +0000)
Asynchronous zone dumping now uses loop callbacks instead of
task events.

bin/named/server.c
lib/dns/include/dns/masterdump.h
lib/dns/masterdump.c
lib/dns/zone.c

index e988d2c8d4aea933912f5a6a94df6756d8cd3737..a1e61713d7184e5d853d1356a789553aeecea3fa 100644 (file)
@@ -265,7 +265,7 @@ struct dumpcontext {
        dns_dumpctx_t *mdctx;
        dns_db_t *db;
        dns_db_t *cache;
-       isc_task_t *task;
+       isc_loop_t *loop;
        dns_dbversion_t *version;
 };
 
@@ -11555,9 +11555,6 @@ dumpcontext_destroy(struct dumpcontext *dctx) {
        if (dctx->cache != NULL) {
                dns_db_detach(&dctx->cache);
        }
-       if (dctx->task != NULL) {
-               isc_task_detach(&dctx->task);
-       }
        if (dctx->fp != NULL) {
                (void)isc_stdio_close(dctx->fp);
        }
@@ -11613,7 +11610,7 @@ resume:
                                dns_cache_getname(dctx->view->view->cache));
                        result = dns_master_dumptostreamasync(
                                dctx->mctx, dctx->cache, NULL, style, dctx->fp,
-                               dctx->task, dumpdone, dctx, &dctx->mdctx);
+                               named_g_mainloop, dumpdone, dctx, &dctx->mdctx);
                        if (result == DNS_R_CONTINUE) {
                                return;
                        }
@@ -11673,7 +11670,7 @@ resume:
                        dns_db_currentversion(dctx->db, &dctx->version);
                        result = dns_master_dumptostreamasync(
                                dctx->mctx, dctx->db, dctx->version, style,
-                               dctx->fp, dctx->task, dumpdone, dctx,
+                               dctx->fp, named_g_mainloop, dumpdone, dctx,
                                &dctx->mdctx);
                        if (result == DNS_R_CONTINUE) {
                                return;
@@ -11732,25 +11729,14 @@ named_server_dumpdb(named_server_t *server, isc_lex_t *lex,
        }
 
        dctx = isc_mem_get(server->mctx, sizeof(*dctx));
-
-       dctx->mctx = server->mctx;
-       dctx->dumpcache = true;
-       dctx->dumpadb = true;
-       dctx->dumpbad = true;
-       dctx->dumpexpired = false;
-       dctx->dumpfail = true;
-       dctx->dumpzones = false;
-       dctx->fp = NULL;
-       ISC_LIST_INIT(dctx->viewlist);
-       dctx->view = NULL;
-       dctx->zone = NULL;
-       dctx->cache = NULL;
-       dctx->mdctx = NULL;
-       dctx->db = NULL;
-       dctx->cache = NULL;
-       dctx->task = NULL;
-       dctx->version = NULL;
-       isc_task_attach(server->task, &dctx->task);
+       *dctx = (struct dumpcontext){
+               .mctx = server->mctx,
+               .dumpcache = true,
+               .dumpadb = true,
+               .dumpbad = true,
+               .dumpfail = true,
+               .viewlist = ISC_LIST_INITIALIZER,
+       };
 
        CHECKMF(isc_stdio_open(server->dumpfile, "w", &dctx->fp),
                "could not open dump file", server->dumpfile);
index 056780ba84e1f884997a17e4dae35ccb954398c0..e20816e87d7970ff813f20247f7858e1d00601ef 100644 (file)
@@ -245,7 +245,7 @@ isc_result_t
 dns_master_dumptostreamasync(isc_mem_t *mctx, dns_db_t *db,
                             dns_dbversion_t          *version,
                             const dns_master_style_t *style, FILE *f,
-                            isc_task_t *task, dns_dumpdonefunc_t done,
+                            isc_loop_t *loop, dns_dumpdonefunc_t done,
                             void *done_arg, dns_dumpctx_t **dctxp);
 
 isc_result_t
@@ -264,7 +264,6 @@ dns_master_dumptostream(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
  * Temporary dynamic memory may be allocated from 'mctx'.
  *
  * Require:
- *\li  'task' to be valid.
  *\li  'done' to be non NULL.
  *\li  'dctxp' to be non NULL && '*dctxp' to be NULL.
  *
@@ -281,7 +280,7 @@ dns_master_dumptostream(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
 isc_result_t
 dns_master_dumpasync(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
                     const dns_master_style_t *style, const char *filename,
-                    isc_task_t *task, dns_dumpdonefunc_t done, void *done_arg,
+                    isc_loop_t *loop, dns_dumpdonefunc_t done, void *done_arg,
                     dns_dumpctx_t **dctxp, dns_masterformat_t format,
                     dns_masterrawheader_t *header);
 
index 7ab6021acaf2044dcfcf7c77311d8b0fe51eee46..981668450f81c1b707dbe2291f6ae056bfebb6eb 100644 (file)
 #include <stdbool.h>
 #include <stdlib.h>
 
+#include <isc/async.h>
 #include <isc/atomic.h>
 #include <isc/buffer.h>
 #include <isc/event.h>
 #include <isc/file.h>
+#include <isc/loop.h>
 #include <isc/magic.h>
 #include <isc/mem.h>
 #include <isc/print.h>
@@ -28,7 +30,6 @@
 #include <isc/result.h>
 #include <isc/stdio.h>
 #include <isc/string.h>
-#include <isc/task.h>
 #include <isc/time.h>
 #include <isc/types.h>
 #include <isc/util.h>
@@ -261,7 +262,7 @@ struct dns_dumpctx {
        dns_dbversion_t *version;
        dns_dbiterator_t *dbiter;
        dns_totext_ctx_t tctx;
-       isc_task_t *task;
+       isc_loop_t *loop;
        dns_dumpdonefunc_t done;
        void *done_arg;
        /* dns_master_dumpasync() */
@@ -1334,8 +1335,8 @@ dumpctx_destroy(dns_dumpctx_t *dctx) {
                dns_db_closeversion(dctx->db, &dctx->version, false);
        }
        dns_db_detach(&dctx->db);
-       if (dctx->task != NULL) {
-               isc_task_detach(&dctx->task);
+       if (dctx->loop != NULL) {
+               isc_loop_detach(&dctx->loop);
        }
        if (dctx->file != NULL) {
                isc_mem_free(dctx->mctx, dctx->file);
@@ -1496,7 +1497,7 @@ master_dump_cb(void *data) {
 }
 
 /*
- * This will run in a network/task manager thread when the dump is complete.
+ * This will run in a loop manager thread when the dump is complete.
  */
 static void
 master_dump_done_cb(void *data) {
@@ -1507,33 +1508,15 @@ master_dump_done_cb(void *data) {
 }
 
 /*
- * This must be run from a network/task manager thread.
+ * This must be run from a loop manager thread.
  */
 static void
-setup_dump(isc_task_t *task, isc_event_t *event) {
-       dns_dumpctx_t *dctx = NULL;
-       isc_loopmgr_t *loopmgr = isc_task_getloopmgr(task);
-       isc_loop_t *loop = isc_loop_current(loopmgr);
-
-       REQUIRE(event != NULL);
-
-       dctx = event->ev_arg;
+setup_dump(void *arg) {
+       dns_dumpctx_t *dctx = (dns_dumpctx_t *)arg;
 
        REQUIRE(DNS_DCTX_VALID(dctx));
 
-       isc_work_enqueue(loop, master_dump_cb, master_dump_done_cb, dctx);
-
-       isc_event_free(&event);
-}
-
-static isc_result_t
-task_send(dns_dumpctx_t *dctx) {
-       isc_event_t *event;
-
-       event = isc_event_allocate(dctx->mctx, NULL, DNS_EVENT_DUMPQUANTUM,
-                                  setup_dump, dctx, sizeof(*event));
-       isc_task_send(dctx->task, &event);
-       return (ISC_R_SUCCESS);
+       isc_work_enqueue(dctx->loop, master_dump_cb, master_dump_done_cb, dctx);
 }
 
 static isc_result_t
@@ -1545,19 +1528,11 @@ dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
        unsigned int options;
 
        dctx = isc_mem_get(mctx, sizeof(*dctx));
+       *dctx = (dns_dumpctx_t){
+               .f = f,
+               .format = format,
+       };
 
-       dctx->mctx = NULL;
-       dctx->f = f;
-       dctx->dbiter = NULL;
-       dctx->db = NULL;
-       dctx->version = NULL;
-       dctx->done = NULL;
-       dctx->done_arg = NULL;
-       dctx->task = NULL;
-       atomic_init(&dctx->canceled, false);
-       dctx->file = NULL;
-       dctx->tmpfile = NULL;
-       dctx->format = format;
        if (header == NULL) {
                dns_master_initrawheader(&dctx->header);
        } else {
@@ -1772,12 +1747,12 @@ isc_result_t
 dns_master_dumptostreamasync(isc_mem_t *mctx, dns_db_t *db,
                             dns_dbversion_t *version,
                             const dns_master_style_t *style, FILE *f,
-                            isc_task_t *task, dns_dumpdonefunc_t done,
+                            isc_loop_t *loop, dns_dumpdonefunc_t done,
                             void *done_arg, dns_dumpctx_t **dctxp) {
        dns_dumpctx_t *dctx = NULL;
        isc_result_t result;
 
-       REQUIRE(task != NULL);
+       REQUIRE(loop != NULL);
        REQUIRE(f != NULL);
        REQUIRE(done != NULL);
 
@@ -1786,18 +1761,13 @@ dns_master_dumptostreamasync(isc_mem_t *mctx, dns_db_t *db,
        if (result != ISC_R_SUCCESS) {
                return (result);
        }
-       isc_task_attach(task, &dctx->task);
+       isc_loop_attach(loop, &dctx->loop);
        dctx->done = done;
        dctx->done_arg = done_arg;
 
-       result = task_send(dctx);
-       if (result == ISC_R_SUCCESS) {
-               dns_dumpctx_attach(dctx, dctxp);
-               return (DNS_R_CONTINUE);
-       }
-
-       dns_dumpctx_detach(&dctx);
-       return (result);
+       isc_async_run(dctx->loop, setup_dump, dctx);
+       dns_dumpctx_attach(dctx, dctxp);
+       return (DNS_R_CONTINUE);
 }
 
 isc_result_t
@@ -1867,7 +1837,7 @@ cleanup:
 isc_result_t
 dns_master_dumpasync(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
                     const dns_master_style_t *style, const char *filename,
-                    isc_task_t *task, dns_dumpdonefunc_t done, void *done_arg,
+                    isc_loop_t *loop, dns_dumpdonefunc_t done, void *done_arg,
                     dns_dumpctx_t **dctxp, dns_masterformat_t format,
                     dns_masterrawheader_t *header) {
        FILE *f = NULL;
@@ -1891,7 +1861,7 @@ dns_master_dumpasync(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
                goto cleanup;
        }
 
-       isc_task_attach(task, &dctx->task);
+       isc_loop_attach(loop, &dctx->loop);
        dctx->done = done;
        dctx->done_arg = done_arg;
        dctx->file = file;
@@ -1899,11 +1869,9 @@ dns_master_dumpasync(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
        dctx->tmpfile = tempname;
        tempname = NULL;
 
-       result = task_send(dctx);
-       if (result == ISC_R_SUCCESS) {
-               dns_dumpctx_attach(dctx, dctxp);
-               return (DNS_R_CONTINUE);
-       }
+       isc_async_run(dctx->loop, setup_dump, dctx);
+       dns_dumpctx_attach(dctx, dctxp);
+       return (DNS_R_CONTINUE);
 
 cleanup:
        if (dctx != NULL) {
index 632a8f641ca4c53d91ea3b07aa13977008425beb..5f488ca441aa4d4c80d5d2048457030cd0a04fbe 100644 (file)
@@ -2691,7 +2691,7 @@ zone_gotwritehandle(isc_task_t *task, isc_event_t *event) {
                }
                result = dns_master_dumpasync(
                        zone->mctx, db, version, output_style, zone->masterfile,
-                       zone->task, dump_done, zone, &zone->dctx,
+                       zone->loop, dump_done, zone, &zone->dctx,
                        zone->masterformat, &rawdata);
                dns_db_closeversion(db, &version, false);
        } else {