2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

Refactor dns_master_dump*async() to use offloaded work

The dns_master_dump*async() functions were using isc_async_run() to
schedule work on the active loop; use isc_work_enqueue() instead.
This commit is contained in:
Ondřej Surý 2022-10-26 20:01:29 +02:00 committed by Ondřej Surý
parent b54c721894
commit 04670889bc
4 changed files with 37 additions and 47 deletions

View File

@ -11611,7 +11611,7 @@ resume:
result = dns_master_dumptostreamasync(
dctx->mctx, dctx->cache, NULL, style, dctx->fp,
named_g_mainloop, dumpdone, dctx, &dctx->mdctx);
if (result == DNS_R_CONTINUE) {
if (result == ISC_R_SUCCESS) {
return;
}
if (result == ISC_R_NOTIMPLEMENTED) {
@ -11670,9 +11670,9 @@ resume:
dns_db_currentversion(dctx->db, &dctx->version);
result = dns_master_dumptostreamasync(
dctx->mctx, dctx->db, dctx->version, style,
dctx->fp, named_g_mainloop, dumpdone, dctx,
&dctx->mdctx);
if (result == DNS_R_CONTINUE) {
dctx->fp, dns_zone_getloop(dctx->zone->zone),
dumpdone, dctx, &dctx->mdctx);
if (result == ISC_R_SUCCESS) {
return;
}
if (result == ISC_R_NOTIMPLEMENTED) {

View File

@ -2753,6 +2753,16 @@ dns_zone_gettid(dns_zone_t *zone);
* \return thread id associated with the zone
*/
isc_loop_t *
dns_zone_getloop(dns_zone_t *zone);
/**<
* \brief Return loop associated with the zone.
*
* \param valid dns_zone_t object
*
* \return loop associated with the zone
*/
bool
dns_zone_check_dnskey_nsec3(dns_zone_t *zone, dns_db_t *db,
dns_dbversion_t *ver, dns_diff_t *diff,

View File

@ -262,7 +262,6 @@ struct dns_dumpctx {
dns_dbversion_t *version;
dns_dbiterator_t *dbiter;
dns_totext_ctx_t tctx;
isc_loop_t *loop;
dns_dumpdonefunc_t done;
void *done_arg;
/* dns_master_dumpasync() */
@ -1072,7 +1071,6 @@ again:
sorted[i] = &rdatasets[i];
}
n = i;
INSIST(n <= MAXSORT);
qsort(sorted, n, sizeof(sorted[0]), dump_order_compare);
@ -1335,9 +1333,6 @@ dumpctx_destroy(dns_dumpctx_t *dctx) {
dns_db_closeversion(dctx->db, &dctx->version, false);
}
dns_db_detach(&dctx->db);
if (dctx->loop != NULL) {
isc_loop_detach(&dctx->loop);
}
if (dctx->file != NULL) {
isc_mem_free(dctx->mctx, dctx->file);
}
@ -1507,18 +1502,6 @@ master_dump_done_cb(void *data) {
dns_dumpctx_detach(&dctx);
}
/*
* This must be run from a loop manager thread.
*/
static void
setup_dump(void *arg) {
dns_dumpctx_t *dctx = (dns_dumpctx_t *)arg;
REQUIRE(DNS_DCTX_VALID(dctx));
isc_work_enqueue(dctx->loop, master_dump_cb, master_dump_done_cb, dctx);
}
static isc_result_t
dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
const dns_master_style_t *style, FILE *f, dns_dumpctx_t **dctxp,
@ -1761,13 +1744,13 @@ dns_master_dumptostreamasync(isc_mem_t *mctx, dns_db_t *db,
if (result != ISC_R_SUCCESS) {
return (result);
}
isc_loop_attach(loop, &dctx->loop);
dctx->done = done;
dctx->done_arg = done_arg;
isc_async_run(dctx->loop, setup_dump, dctx);
dns_dumpctx_attach(dctx, dctxp);
return (DNS_R_CONTINUE);
isc_work_enqueue(loop, master_dump_cb, master_dump_done_cb, dctx);
return (ISC_R_SUCCESS);
}
isc_result_t
@ -1850,39 +1833,33 @@ dns_master_dumpasync(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
result = opentmp(mctx, format, filename, &tempname, &f);
if (result != ISC_R_SUCCESS) {
goto cleanup;
goto cleanup_file;
}
result = dumpctx_create(mctx, db, version, style, f, &dctx, format,
header);
if (result != ISC_R_SUCCESS) {
(void)isc_stdio_close(f);
(void)isc_file_remove(tempname);
goto cleanup;
goto cleanup_tempname;
}
isc_loop_attach(loop, &dctx->loop);
dctx->done = done;
dctx->done_arg = done_arg;
dctx->file = file;
file = NULL;
dctx->tmpfile = tempname;
tempname = NULL;
isc_async_run(dctx->loop, setup_dump, dctx);
dns_dumpctx_attach(dctx, dctxp);
return (DNS_R_CONTINUE);
isc_work_enqueue(loop, master_dump_cb, master_dump_done_cb, dctx);
cleanup:
if (dctx != NULL) {
dns_dumpctx_detach(&dctx);
}
if (file != NULL) {
isc_mem_free(mctx, file);
}
if (tempname != NULL) {
return (ISC_R_SUCCESS);
cleanup_tempname:
(void)isc_stdio_close(f);
(void)isc_file_remove(tempname);
isc_mem_free(mctx, tempname);
}
cleanup_file:
isc_mem_free(mctx, file);
return (result);
}

View File

@ -2701,7 +2701,7 @@ zone_gotwritehandle(isc_task_t *task, isc_event_t *event) {
dns_db_detach(&db);
}
UNLOCK_ZONE(zone);
if (result != DNS_R_CONTINUE) {
if (result != ISC_R_SUCCESS) {
goto fail;
}
return;
@ -12174,8 +12174,6 @@ redo:
&zone->writeio);
if (result != ISC_R_SUCCESS) {
zone_idetach(&dummy);
} else {
result = DNS_R_CONTINUE;
}
UNLOCK_ZONE(zone);
} else {
@ -12205,7 +12203,7 @@ fail:
}
masterfile = NULL;
if (result == DNS_R_CONTINUE) {
if (result == ISC_R_SUCCESS) {
return (ISC_R_SUCCESS); /* XXXMPA */
}
@ -23674,3 +23672,8 @@ unsigned int
dns_zone_gettid(dns_zone_t *zone) {
return (zone->tid);
}
isc_loop_t *
dns_zone_getloop(dns_zone_t *zone) {
return (zone->loop);
}