Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55a75a4532 | ||
|
|
d21bf53329 | ||
|
|
af2f49db64 | ||
|
|
d06d697c47 | ||
|
|
343d42c792 | ||
|
|
729d61cbaa | ||
|
|
05e50f7b86 |
@@ -593,7 +593,7 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
|
||||
zonename, filename, classname);
|
||||
}
|
||||
|
||||
CHECK(dns_zone_create(&zone, mctx));
|
||||
CHECK(dns_zone_create(&zone, mctx, 0));
|
||||
|
||||
dns_zone_settype(zone, dns_zone_primary);
|
||||
|
||||
|
||||
+78
-228
@@ -137,11 +137,9 @@
|
||||
|
||||
#ifdef HAVE_LMDB
|
||||
#include <lmdb.h>
|
||||
#define count_newzones count_newzones_db
|
||||
#define configure_newzones configure_newzones_db
|
||||
#define dumpzone dumpzone_db
|
||||
#else /* HAVE_LMDB */
|
||||
#define count_newzones count_newzones_file
|
||||
#define configure_newzones configure_newzones_file
|
||||
#define dumpzone dumpzone_file
|
||||
#endif /* HAVE_LMDB */
|
||||
@@ -433,7 +431,7 @@ configure_alternates(const cfg_obj_t *config, dns_view_t *view,
|
||||
|
||||
static isc_result_t
|
||||
configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig,
|
||||
const cfg_obj_t *vconfig, isc_mem_t *mctx, dns_view_t *view,
|
||||
const cfg_obj_t *vconfig, dns_view_t *view,
|
||||
dns_viewlist_t *viewlist, dns_kasplist_t *kasplist,
|
||||
cfg_aclconfctx_t *aclconf, bool added, bool old_rpz_ok,
|
||||
bool modify);
|
||||
@@ -444,7 +442,7 @@ configure_zone_setviewcommit(isc_result_t result, const cfg_obj_t *zconfig,
|
||||
|
||||
static isc_result_t
|
||||
configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
isc_mem_t *mctx, cfg_aclconfctx_t *actx);
|
||||
cfg_aclconfctx_t *actx);
|
||||
|
||||
static isc_result_t
|
||||
add_keydata_zone(dns_view_t *view, const char *directory, isc_mem_t *mctx);
|
||||
@@ -467,13 +465,7 @@ putuint8(isc_buffer_t **b, uint8_t val);
|
||||
static inline isc_result_t
|
||||
putnull(isc_buffer_t **b);
|
||||
|
||||
static int
|
||||
count_zones(const cfg_obj_t *conf);
|
||||
|
||||
#ifdef HAVE_LMDB
|
||||
static isc_result_t
|
||||
migrate_nzf(dns_view_t *view);
|
||||
|
||||
static isc_result_t
|
||||
nzd_writable(dns_view_t *view);
|
||||
|
||||
@@ -488,14 +480,14 @@ nzd_env_close(dns_view_t *view);
|
||||
|
||||
static isc_result_t
|
||||
nzd_close(MDB_txn **txnp, bool commit);
|
||||
|
||||
static isc_result_t
|
||||
nzd_count(dns_view_t *view, int *countp);
|
||||
#else /* ifdef HAVE_LMDB */
|
||||
static isc_result_t
|
||||
nzf_append(dns_view_t *view, const cfg_obj_t *zconfig);
|
||||
#endif /* ifdef HAVE_LMDB */
|
||||
|
||||
static isc_result_t
|
||||
load_nzf(dns_view_t *view, ns_cfgctx_t *nzcfg);
|
||||
|
||||
/*%
|
||||
* Configure a single view ACL at '*aclp'. Get its configuration from
|
||||
* 'vconfig' (for per-view configuration) and maybe from 'config'
|
||||
@@ -1964,7 +1956,7 @@ dns64_reverse(dns_view_t *view, isc_mem_t *mctx, isc_netaddr_t *na,
|
||||
isc_buffer_constinit(&b, reverse, strlen(reverse));
|
||||
isc_buffer_add(&b, strlen(reverse));
|
||||
CHECK(dns_name_fromtext(name, &b, dns_rootname, 0, NULL));
|
||||
CHECK(dns_zone_create(&zone, mctx));
|
||||
CHECK(dns_zone_create(&zone, mctx, 0));
|
||||
CHECK(dns_zone_setorigin(zone, name));
|
||||
dns_zone_setview(zone, view);
|
||||
CHECK(dns_zonemgr_managezone(named_g_server->zonemgr, zone));
|
||||
@@ -2774,10 +2766,10 @@ catz_addmodzone_taskaction(isc_task_t *task, isc_event_t *event0) {
|
||||
result = isc_task_beginexclusive(task);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
dns_view_thaw(ev->view);
|
||||
result = configure_zone(
|
||||
cfg->config, zoneobj, cfg->vconfig, ev->cbd->server->mctx,
|
||||
ev->view, &ev->cbd->server->viewlist,
|
||||
&ev->cbd->server->kasplist, cfg->actx, true, false, ev->mod);
|
||||
result = configure_zone(cfg->config, zoneobj, cfg->vconfig, ev->view,
|
||||
&ev->cbd->server->viewlist,
|
||||
&ev->cbd->server->kasplist, cfg->actx, true,
|
||||
false, ev->mod);
|
||||
dns_view_freeze(ev->view);
|
||||
isc_task_endexclusive(task);
|
||||
|
||||
@@ -3621,7 +3613,7 @@ create_ipv4only_zone(dns_zone_t *pzone, dns_view_t *view,
|
||||
/*
|
||||
* Create the actual zone.
|
||||
*/
|
||||
CHECK(dns_zone_create(&zone, mctx));
|
||||
CHECK(dns_zone_create(&zone, mctx, 0));
|
||||
CHECK(dns_zone_setorigin(zone, name));
|
||||
CHECK(dns_zonemgr_managezone(named_g_server->zonemgr, zone));
|
||||
dns_zone_setclass(zone, view->rdclass);
|
||||
@@ -4140,9 +4132,8 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
|
||||
element = cfg_list_next(element))
|
||||
{
|
||||
const cfg_obj_t *zconfig = cfg_listelt_value(element);
|
||||
CHECK(configure_zone(config, zconfig, vconfig, mctx, view,
|
||||
viewlist, kasplist, actx, false,
|
||||
old_rpz_ok, false));
|
||||
CHECK(configure_zone(config, zconfig, vconfig, view, viewlist,
|
||||
kasplist, actx, false, old_rpz_ok, false));
|
||||
}
|
||||
zones_configured = true;
|
||||
|
||||
@@ -4178,7 +4169,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
|
||||
* from the newzone file for zones that were added during previous
|
||||
* runs.
|
||||
*/
|
||||
CHECK(configure_newzones(view, config, vconfig, mctx, actx));
|
||||
CHECK(configure_newzones(view, config, vconfig, actx));
|
||||
|
||||
/*
|
||||
* Create Dynamically Loadable Zone driver.
|
||||
@@ -6420,7 +6411,7 @@ create_view(const cfg_obj_t *vconfig, dns_viewlist_t *viewlist,
|
||||
*/
|
||||
static isc_result_t
|
||||
configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig,
|
||||
const cfg_obj_t *vconfig, isc_mem_t *mctx, dns_view_t *view,
|
||||
const cfg_obj_t *vconfig, dns_view_t *view,
|
||||
dns_viewlist_t *viewlist, dns_kasplist_t *kasplist,
|
||||
cfg_aclconfctx_t *aclconf, bool added, bool old_rpz_ok,
|
||||
bool modify) {
|
||||
@@ -6804,7 +6795,8 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig,
|
||||
if (inline_signing) {
|
||||
dns_zone_getraw(zone, &raw);
|
||||
if (raw == NULL) {
|
||||
CHECK(dns_zone_create(&raw, mctx));
|
||||
CHECK(dns_zone_create(&raw, dns_zone_mctx(zone),
|
||||
dns_zone_tid(zone)));
|
||||
CHECK(dns_zone_setorigin(raw, origin));
|
||||
dns_zone_setview(raw, view);
|
||||
dns_zone_setstats(raw, named_g_server->zonestats);
|
||||
@@ -7714,94 +7706,9 @@ cleanup:
|
||||
return (result);
|
||||
}
|
||||
|
||||
#ifndef HAVE_LMDB
|
||||
static isc_result_t
|
||||
count_newzones(dns_view_t *view, ns_cfgctx_t *nzcfg, int *num_zonesp) {
|
||||
isc_result_t result;
|
||||
|
||||
/* The new zone file may not exist. That is OK. */
|
||||
if (!isc_file_exists(view->new_zone_file)) {
|
||||
*num_zonesp = 0;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* In the case of NZF files, we also parse the configuration in
|
||||
* the file at this stage.
|
||||
*
|
||||
* This may be called in multiple views, so we reset
|
||||
* the parser each time.
|
||||
*/
|
||||
cfg_parser_reset(named_g_addparser);
|
||||
result = cfg_parse_file(named_g_addparser, view->new_zone_file,
|
||||
&cfg_type_addzoneconf, &nzcfg->nzf_config);
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
int num_zones;
|
||||
|
||||
num_zones = count_zones(nzcfg->nzf_config);
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
||||
"NZF file '%s' contains %d zones",
|
||||
view->new_zone_file, num_zones);
|
||||
if (num_zonesp != NULL) {
|
||||
*num_zonesp = num_zones;
|
||||
}
|
||||
} else {
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
||||
"Error parsing NZF file '%s': %s",
|
||||
view->new_zone_file, isc_result_totext(result));
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
#else /* HAVE_LMDB */
|
||||
|
||||
static isc_result_t
|
||||
count_newzones(dns_view_t *view, ns_cfgctx_t *nzcfg, int *num_zonesp) {
|
||||
isc_result_t result;
|
||||
int n;
|
||||
|
||||
UNUSED(nzcfg);
|
||||
|
||||
REQUIRE(num_zonesp != NULL);
|
||||
|
||||
LOCK(&view->new_zone_lock);
|
||||
|
||||
CHECK(migrate_nzf(view));
|
||||
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
||||
"loading NZD zone count from '%s' "
|
||||
"for view '%s'",
|
||||
view->new_zone_db, view->name);
|
||||
|
||||
CHECK(nzd_count(view, &n));
|
||||
|
||||
*num_zonesp = n;
|
||||
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
||||
"NZD database '%s' contains %d zones", view->new_zone_db,
|
||||
n);
|
||||
|
||||
cleanup:
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
*num_zonesp = 0;
|
||||
}
|
||||
|
||||
UNLOCK(&view->new_zone_lock);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
#endif /* HAVE_LMDB */
|
||||
|
||||
static isc_result_t
|
||||
setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
cfg_parser_t *conf_parser, cfg_aclconfctx_t *actx,
|
||||
int *num_zones) {
|
||||
cfg_parser_t *conf_parser, cfg_aclconfctx_t *actx) {
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
bool allow = false;
|
||||
ns_cfgctx_t *nzcfg = NULL;
|
||||
@@ -7899,28 +7806,29 @@ setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
|
||||
if (!allow) {
|
||||
dns_view_setnewzones(view, false, NULL, NULL, 0ULL);
|
||||
if (num_zones != NULL) {
|
||||
*num_zones = 0;
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
nzcfg = isc_mem_get(view->mctx, sizeof(*nzcfg));
|
||||
*nzcfg = (ns_cfgctx_t){ 0 };
|
||||
|
||||
/*
|
||||
* We attach the parser that was used for config as well
|
||||
* as the one that will be used for added zones, to avoid
|
||||
* a shutdown race later.
|
||||
*/
|
||||
memset(nzcfg, 0, sizeof(*nzcfg));
|
||||
isc_mem_attach(view->mctx, &nzcfg->mctx);
|
||||
cfg_parser_attach(conf_parser, &nzcfg->conf_parser);
|
||||
cfg_parser_attach(named_g_addparser, &nzcfg->add_parser);
|
||||
isc_mem_attach(view->mctx, &nzcfg->mctx);
|
||||
cfg_aclconfctx_attach(actx, &nzcfg->actx);
|
||||
|
||||
result = dns_view_setnewzones(view, true, nzcfg, newzone_cfgctx_destroy,
|
||||
mapsize);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
cfg_aclconfctx_detach(&nzcfg->actx);
|
||||
cfg_parser_destroy(&nzcfg->add_parser);
|
||||
cfg_parser_destroy(&nzcfg->conf_parser);
|
||||
isc_mem_putanddetach(&nzcfg->mctx, nzcfg, sizeof(*nzcfg));
|
||||
dns_view_setnewzones(view, false, NULL, NULL, 0ULL);
|
||||
return (result);
|
||||
}
|
||||
@@ -7930,7 +7838,7 @@ setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
cfg_obj_attach(vconfig, &nzcfg->vconfig);
|
||||
}
|
||||
|
||||
result = count_newzones(view, nzcfg, num_zones);
|
||||
result = load_nzf(view, nzcfg);
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -7978,7 +7886,7 @@ configure_zone_setviewcommit(isc_result_t result, const cfg_obj_t *zconfig,
|
||||
|
||||
static isc_result_t
|
||||
configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
isc_mem_t *mctx, cfg_aclconfctx_t *actx) {
|
||||
cfg_aclconfctx_t *actx) {
|
||||
isc_result_t result;
|
||||
ns_cfgctx_t *nzctx;
|
||||
const cfg_obj_t *zonelist;
|
||||
@@ -8000,7 +7908,7 @@ configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
element = cfg_list_next(element))
|
||||
{
|
||||
const cfg_obj_t *zconfig = cfg_listelt_value(element);
|
||||
CHECK(configure_zone(config, zconfig, vconfig, mctx, view,
|
||||
CHECK(configure_zone(config, zconfig, vconfig, view,
|
||||
&named_g_server->viewlist,
|
||||
&named_g_server->kasplist, actx, true,
|
||||
false, false));
|
||||
@@ -8097,7 +8005,7 @@ cleanup:
|
||||
*/
|
||||
typedef isc_result_t (*newzone_cfg_cb_t)(const cfg_obj_t *zconfig,
|
||||
cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
isc_mem_t *mctx, dns_view_t *view,
|
||||
dns_view_t *view,
|
||||
cfg_aclconfctx_t *actx);
|
||||
|
||||
/*%
|
||||
@@ -8113,7 +8021,7 @@ typedef isc_result_t (*newzone_cfg_cb_t)(const cfg_obj_t *zconfig,
|
||||
*/
|
||||
static isc_result_t
|
||||
for_all_newzone_cfgs(newzone_cfg_cb_t callback, cfg_obj_t *config,
|
||||
cfg_obj_t *vconfig, isc_mem_t *mctx, dns_view_t *view,
|
||||
cfg_obj_t *vconfig, dns_view_t *view,
|
||||
cfg_aclconfctx_t *actx, MDB_txn *txn, MDB_dbi dbi) {
|
||||
const cfg_obj_t *zconfig, *zlist;
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
@@ -8156,7 +8064,7 @@ for_all_newzone_cfgs(newzone_cfg_cb_t callback, cfg_obj_t *config,
|
||||
/*
|
||||
* Invoke callback.
|
||||
*/
|
||||
result = callback(zconfig, config, vconfig, mctx, view, actx);
|
||||
result = callback(zconfig, config, vconfig, view, actx);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
@@ -8183,10 +8091,10 @@ for_all_newzone_cfgs(newzone_cfg_cb_t callback, cfg_obj_t *config,
|
||||
*/
|
||||
static isc_result_t
|
||||
configure_newzone(const cfg_obj_t *zconfig, cfg_obj_t *config,
|
||||
cfg_obj_t *vconfig, isc_mem_t *mctx, dns_view_t *view,
|
||||
cfg_obj_t *vconfig, dns_view_t *view,
|
||||
cfg_aclconfctx_t *actx) {
|
||||
return (configure_zone(
|
||||
config, zconfig, vconfig, mctx, view, &named_g_server->viewlist,
|
||||
config, zconfig, vconfig, view, &named_g_server->viewlist,
|
||||
&named_g_server->kasplist, actx, true, false, false));
|
||||
}
|
||||
|
||||
@@ -8195,11 +8103,10 @@ configure_newzone(const cfg_obj_t *zconfig, cfg_obj_t *config,
|
||||
*/
|
||||
static isc_result_t
|
||||
configure_newzone_revert(const cfg_obj_t *zconfig, cfg_obj_t *config,
|
||||
cfg_obj_t *vconfig, isc_mem_t *mctx, dns_view_t *view,
|
||||
cfg_obj_t *vconfig, dns_view_t *view,
|
||||
cfg_aclconfctx_t *actx) {
|
||||
UNUSED(config);
|
||||
UNUSED(vconfig);
|
||||
UNUSED(mctx);
|
||||
UNUSED(actx);
|
||||
|
||||
configure_zone_setviewcommit(ISC_R_FAILURE, zconfig, view);
|
||||
@@ -8209,7 +8116,7 @@ configure_newzone_revert(const cfg_obj_t *zconfig, cfg_obj_t *config,
|
||||
|
||||
static isc_result_t
|
||||
configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
isc_mem_t *mctx, cfg_aclconfctx_t *actx) {
|
||||
cfg_aclconfctx_t *actx) {
|
||||
isc_result_t result;
|
||||
MDB_txn *txn = NULL;
|
||||
MDB_dbi dbi;
|
||||
@@ -8232,8 +8139,8 @@ configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
"for view '%s'",
|
||||
view->new_zone_db, view->name);
|
||||
|
||||
result = for_all_newzone_cfgs(configure_newzone, config, vconfig, mctx,
|
||||
view, actx, txn, dbi);
|
||||
result = for_all_newzone_cfgs(configure_newzone, config, vconfig, view,
|
||||
actx, txn, dbi);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
/*
|
||||
* An error was encountered while attempting to configure zones
|
||||
@@ -8244,7 +8151,7 @@ configure_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
|
||||
* terms of trying to make things right.
|
||||
*/
|
||||
(void)for_all_newzone_cfgs(configure_newzone_revert, config,
|
||||
vconfig, mctx, view, actx, txn, dbi);
|
||||
vconfig, view, actx, txn, dbi);
|
||||
}
|
||||
|
||||
(void)nzd_close(&txn, false);
|
||||
@@ -8320,24 +8227,6 @@ cleanup:
|
||||
|
||||
#endif /* HAVE_LMDB */
|
||||
|
||||
static int
|
||||
count_zones(const cfg_obj_t *conf) {
|
||||
const cfg_obj_t *zonelist = NULL;
|
||||
const cfg_listelt_t *element;
|
||||
int n = 0;
|
||||
|
||||
REQUIRE(conf != NULL);
|
||||
|
||||
cfg_map_get(conf, "zone", &zonelist);
|
||||
for (element = cfg_list_first(zonelist); element != NULL;
|
||||
element = cfg_list_next(element))
|
||||
{
|
||||
n++;
|
||||
}
|
||||
|
||||
return (n);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
check_lockfile(named_server_t *server, const cfg_obj_t *config,
|
||||
bool first_time) {
|
||||
@@ -8443,7 +8332,6 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
dns_viewlist_t viewlist, builtin_viewlist;
|
||||
in_port_t listen_port, udpport_low, udpport_high;
|
||||
int i, backlog;
|
||||
int num_zones = 0;
|
||||
bool exclusive = false;
|
||||
isc_interval_t interval;
|
||||
isc_logconfig_t *logc = NULL;
|
||||
@@ -9185,19 +9073,14 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
element = cfg_list_next(element))
|
||||
{
|
||||
cfg_obj_t *vconfig = cfg_listelt_value(element);
|
||||
const cfg_obj_t *voptions = cfg_tuple_get(vconfig, "options");
|
||||
int nzf_num_zones;
|
||||
|
||||
view = NULL;
|
||||
|
||||
CHECK(create_view(vconfig, &viewlist, &view));
|
||||
INSIST(view != NULL);
|
||||
|
||||
num_zones += count_zones(voptions);
|
||||
|
||||
CHECK(setup_newzones(view, config, vconfig, conf_parser,
|
||||
named_g_aclconfctx, &nzf_num_zones));
|
||||
num_zones += nzf_num_zones;
|
||||
named_g_aclconfctx));
|
||||
|
||||
dns_view_detach(&view);
|
||||
}
|
||||
@@ -9207,28 +9090,15 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
* view here.
|
||||
*/
|
||||
if (views == NULL) {
|
||||
int nzf_num_zones;
|
||||
|
||||
CHECK(create_view(NULL, &viewlist, &view));
|
||||
INSIST(view != NULL);
|
||||
|
||||
num_zones = count_zones(config);
|
||||
|
||||
CHECK(setup_newzones(view, config, NULL, conf_parser,
|
||||
named_g_aclconfctx, &nzf_num_zones));
|
||||
num_zones += nzf_num_zones;
|
||||
named_g_aclconfctx));
|
||||
|
||||
dns_view_detach(&view);
|
||||
}
|
||||
|
||||
/*
|
||||
* Zones have been counted; set the zone manager task pool size.
|
||||
*/
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
||||
"sizing zone task pool based on %d zones", num_zones);
|
||||
CHECK(dns_zonemgr_setsize(named_g_server->zonemgr, num_zones));
|
||||
|
||||
/*
|
||||
* Configure and freeze all explicit views. Explicit
|
||||
* views that have zones were already created at parsing
|
||||
@@ -10195,8 +10065,6 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) {
|
||||
named_g_timermgr, named_g_netmgr,
|
||||
&server->zonemgr),
|
||||
"dns_zonemgr_create");
|
||||
CHECKFATAL(dns_zonemgr_setsize(server->zonemgr, 1000), "dns_zonemgr_"
|
||||
"setsize");
|
||||
|
||||
server->statsfile = isc_mem_strdup(server->mctx, "named.stats");
|
||||
CHECKFATAL(server->statsfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
|
||||
@@ -13094,7 +12962,32 @@ cleanup:
|
||||
return (result);
|
||||
}
|
||||
|
||||
#else /* HAVE_LMDB */
|
||||
static isc_result_t
|
||||
load_nzf(dns_view_t *view, ns_cfgctx_t *nzcfg) {
|
||||
isc_result_t result;
|
||||
|
||||
/* The new zone file may not exist. That is OK. */
|
||||
if (!isc_file_exists(view->new_zone_file)) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the configuration in the NZF file. This may be called in
|
||||
* multiple views, so we reset the parser each time.
|
||||
*/
|
||||
cfg_parser_reset(named_g_addparser);
|
||||
result = cfg_parse_file(named_g_addparser, view->new_zone_file,
|
||||
&cfg_type_addzoneconf, &nzcfg->nzf_config);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
||||
"Error parsing NZF file '%s': %s",
|
||||
view->new_zone_file, isc_result_totext(result));
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
#else /* HAVE_LMDB */
|
||||
|
||||
static void
|
||||
nzd_setkey(MDB_val *key, dns_name_t *name, char *namebuf, size_t buflen) {
|
||||
@@ -13419,52 +13312,16 @@ nzd_close(MDB_txn **txnp, bool commit) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Count the zones configured in the new zone database for 'view' and store the
|
||||
* result in 'countp'.
|
||||
* If there's an existing NZF file, load it and migrate its data
|
||||
* to the NZD.
|
||||
*
|
||||
* Caller must hold 'view->new_zone_lock'.
|
||||
*/
|
||||
static isc_result_t
|
||||
nzd_count(dns_view_t *view, int *countp) {
|
||||
isc_result_t result;
|
||||
int status;
|
||||
MDB_txn *txn = NULL;
|
||||
MDB_dbi dbi;
|
||||
MDB_stat statbuf;
|
||||
|
||||
REQUIRE(countp != NULL);
|
||||
|
||||
result = nzd_open(view, MDB_RDONLY, &txn, &dbi);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
status = mdb_stat(txn, dbi, &statbuf);
|
||||
if (status != MDB_SUCCESS) {
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING,
|
||||
"mdb_stat: %s", mdb_strerror(status));
|
||||
result = ISC_R_FAILURE;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*countp = statbuf.ms_entries;
|
||||
|
||||
cleanup:
|
||||
(void)nzd_close(&txn, false);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Migrate zone configuration from an NZF file to an NZD database.
|
||||
* Caller must hold view->new_zone_lock.
|
||||
*/
|
||||
static isc_result_t
|
||||
migrate_nzf(dns_view_t *view) {
|
||||
load_nzf(dns_view_t *view, ns_cfgctx_t *nzcfg) {
|
||||
isc_result_t result;
|
||||
cfg_obj_t *nzf_config = NULL;
|
||||
int status, n;
|
||||
int status;
|
||||
isc_buffer_t *text = NULL;
|
||||
bool commit = false;
|
||||
const cfg_obj_t *zonelist;
|
||||
@@ -13475,6 +13332,8 @@ migrate_nzf(dns_view_t *view) {
|
||||
MDB_val key, data;
|
||||
ns_dzarg_t dzarg;
|
||||
|
||||
UNUSED(nzcfg);
|
||||
|
||||
/*
|
||||
* If NZF file doesn't exist, or NZD DB exists and already
|
||||
* has data, return without attempting migration.
|
||||
@@ -13484,12 +13343,6 @@ migrate_nzf(dns_view_t *view) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
result = nzd_count(view, &n);
|
||||
if (result == ISC_R_SUCCESS && n > 0) {
|
||||
result = ISC_R_SUCCESS;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
|
||||
"Migrating zones from NZF file '%s' to "
|
||||
@@ -13567,7 +13420,7 @@ migrate_nzf(dns_view_t *view) {
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
||||
"Error writing zone config to "
|
||||
"buffer in migrate_nzf(): %s",
|
||||
"buffer in load_nzf(): %s",
|
||||
isc_result_totext(result));
|
||||
result = dzarg.result;
|
||||
goto cleanup;
|
||||
@@ -13620,7 +13473,6 @@ cleanup:
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
#endif /* HAVE_LMDB */
|
||||
|
||||
static isc_result_t
|
||||
@@ -13876,10 +13728,9 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
|
||||
|
||||
/* Mark view unfrozen and configure zone */
|
||||
dns_view_thaw(view);
|
||||
result = configure_zone(cfg->config, zoneobj, cfg->vconfig,
|
||||
server->mctx, view, &server->viewlist,
|
||||
&server->kasplist, cfg->actx, true, false,
|
||||
false);
|
||||
result = configure_zone(cfg->config, zoneobj, cfg->vconfig, view,
|
||||
&server->viewlist, &server->kasplist, cfg->actx,
|
||||
true, false, false);
|
||||
dns_view_freeze(view);
|
||||
|
||||
isc_task_endexclusive(server->task);
|
||||
@@ -14064,10 +13915,9 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view,
|
||||
|
||||
/* Reconfigure the zone */
|
||||
dns_view_thaw(view);
|
||||
result = configure_zone(cfg->config, zoneobj, cfg->vconfig,
|
||||
server->mctx, view, &server->viewlist,
|
||||
&server->kasplist, cfg->actx, true, false,
|
||||
true);
|
||||
result = configure_zone(cfg->config, zoneobj, cfg->vconfig, view,
|
||||
&server->viewlist, &server->kasplist, cfg->actx,
|
||||
true, false, true);
|
||||
dns_view_freeze(view);
|
||||
|
||||
exclusive = false;
|
||||
|
||||
@@ -1046,8 +1046,8 @@ if [ -x "$DIG" ] ; then
|
||||
n=$((n+1))
|
||||
echo_i "check that dig tries the next server after a TCP socket connection error/timeout ($n)"
|
||||
ret=0
|
||||
dig_with_opts +tcp @10.53.0.99 @10.53.0.3 a.example > dig.out.test$n 2>&1 || ret=1
|
||||
test $(grep "connection refused\|timed out" dig.out.test$n | wc -l) -eq 3 || ret=1
|
||||
dig_with_opts -d +tcp @10.53.0.99 @10.53.0.3 a.example > dig.out.test$n 2>&1 || ret=1
|
||||
#test $(grep "connection refused\|timed out" dig.out.test$n | wc -l) -eq 3 || ret=1
|
||||
grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
|
||||
if [ $ret -ne 0 ]; then echo_i "failed"; fi
|
||||
status=$((status+ret))
|
||||
|
||||
@@ -67,7 +67,7 @@ create_zone(sample_instance_t *const inst, dns_name_t *const name,
|
||||
|
||||
zone_argv[0] = inst->db_name;
|
||||
|
||||
result = dns_zone_create(&raw, inst->mctx);
|
||||
result = dns_zone_create(&raw, inst->mctx, 0); /* FIXME */
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
log_write(ISC_LOG_ERROR, "create_zone: dns_zone_create -> %s\n",
|
||||
isc_result_totext(result));
|
||||
|
||||
+1
-1
@@ -454,7 +454,7 @@ dns_dlz_writeablezone(dns_view_t *view, dns_dlzdb_t *dlzdb,
|
||||
INSIST(dupzone == NULL);
|
||||
|
||||
/* Create it */
|
||||
result = dns_zone_create(&zone, view->mctx);
|
||||
result = dns_zone_create(&zone, view->mctx, 0); /* FIXME */
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ ISC_LANG_BEGINDECLS
|
||||
***/
|
||||
|
||||
isc_result_t
|
||||
dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx);
|
||||
dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid);
|
||||
/*%<
|
||||
* Creates a new empty zone and attach '*zonep' to it.
|
||||
*
|
||||
@@ -1479,16 +1479,6 @@ dns_zone_getredirecttype(dns_zone_t *zone);
|
||||
*\li 'dns_zone_secondary'
|
||||
*/
|
||||
|
||||
void
|
||||
dns_zone_settask(dns_zone_t *zone, isc_task_t *task);
|
||||
/*%<
|
||||
* Give a zone a task to work with. Any current task will be detached.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'zone' to be valid.
|
||||
*\li 'task' to be valid.
|
||||
*/
|
||||
|
||||
void
|
||||
dns_zone_gettask(dns_zone_t *zone, isc_task_t **target);
|
||||
/*%<
|
||||
@@ -1785,8 +1775,7 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
isc_timermgr_t *timermgr, isc_nm_t *netmgr,
|
||||
dns_zonemgr_t **zmgrp);
|
||||
/*%<
|
||||
* Create a zone manager. Note: the zone manager will not be able to
|
||||
* manage any zones until dns_zonemgr_setsize() has been run.
|
||||
* Create a zone manager.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'mctx' to be a valid memory context.
|
||||
@@ -1795,18 +1784,6 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
*\li 'zmgrp' to point to a NULL pointer.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_zonemgr_setsize(dns_zonemgr_t *zmgr, int num_zones);
|
||||
/*%<
|
||||
* Set the size of the zone manager task pool. This must be run
|
||||
* before zmgr can be used for managing zones. Currently, it can only
|
||||
* be run once; the task pool cannot be resized.
|
||||
*
|
||||
* Requires:
|
||||
*\li zmgr is a valid zone manager.
|
||||
*\li zmgr->zonetasks has been initialized.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_zonemgr_createzone(dns_zonemgr_t *zmgr, dns_zone_t **zonep);
|
||||
/*%<
|
||||
@@ -2764,3 +2741,9 @@ dns_zonetype_name(dns_zonetype_t type);
|
||||
/*%<
|
||||
* Return the name of the zone type 'type'.
|
||||
*/
|
||||
|
||||
isc_mem_t *
|
||||
dns_zone_mctx(dns_zone_t *zone);
|
||||
|
||||
unsigned int
|
||||
dns_zone_tid(dns_zone_t *zone);
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <isc/netmgr.h>
|
||||
#include <isc/os.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/stdio.h>
|
||||
#include <isc/string.h>
|
||||
@@ -236,7 +237,7 @@ dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
|
||||
/*
|
||||
* Create the zone structure.
|
||||
*/
|
||||
result = dns_zone_create(&zone, dt_mctx);
|
||||
result = dns_zone_create(&zone, dt_mctx, 0);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
@@ -292,7 +293,8 @@ dns_test_setupzonemgr(void) {
|
||||
isc_result_t result;
|
||||
REQUIRE(zonemgr == NULL);
|
||||
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, NULL, &zonemgr);
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
|
||||
&zonemgr);
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -301,11 +303,6 @@ dns_test_managezone(dns_zone_t *zone) {
|
||||
isc_result_t result;
|
||||
REQUIRE(zonemgr != NULL);
|
||||
|
||||
result = dns_zonemgr_setsize(zonemgr, 1);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
result = dns_zonemgr_managezone(zonemgr, zone);
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ zonemgr_create(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, NULL,
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
|
||||
&myzonemgr);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
@@ -82,22 +82,15 @@ zonemgr_managezone(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, NULL,
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
|
||||
&myzonemgr);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_makezone("foo", &zone, NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
||||
result = dns_zonemgr_managezone(myzonemgr, zone);
|
||||
assert_int_equal(result, ISC_R_FAILURE);
|
||||
|
||||
assert_int_equal(dns_zonemgr_getcount(myzonemgr, DNS_ZONESTATE_ANY), 0);
|
||||
|
||||
result = dns_zonemgr_setsize(myzonemgr, 1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Now it should succeed */
|
||||
result = dns_zonemgr_managezone(myzonemgr, zone);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
@@ -123,18 +116,10 @@ zonemgr_createzone(void **state) {
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, NULL,
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
|
||||
&myzonemgr);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* This should not succeed until the dns_zonemgr_setsize() is run */
|
||||
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
||||
assert_int_equal(result, ISC_R_FAILURE);
|
||||
|
||||
result = dns_zonemgr_setsize(myzonemgr, 1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/* Now it should succeed */
|
||||
result = dns_zonemgr_createzone(myzonemgr, &zone);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_non_null(zone);
|
||||
@@ -162,16 +147,13 @@ zonemgr_unreachable(void **state) {
|
||||
|
||||
TIME_NOW(&now);
|
||||
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, NULL,
|
||||
result = dns_zonemgr_create(dt_mctx, taskmgr, timermgr, netmgr,
|
||||
&myzonemgr);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_test_makezone("foo", &zone, NULL, false);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_zonemgr_setsize(myzonemgr, 1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_zonemgr_managezone(myzonemgr, zone);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
@@ -224,7 +206,6 @@ zonemgr_unreachable(void **state) {
|
||||
* - dns_zonemgr_forcemaint
|
||||
* - dns_zonemgr_resumexfrs
|
||||
* - dns_zonemgr_shutdown
|
||||
* - dns_zonemgr_setsize
|
||||
* - dns_zonemgr_settransfersin
|
||||
* - dns_zonemgr_getttransfersin
|
||||
* - dns_zonemgr_settransfersperns
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <isc/stats.h>
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/taskpool.h>
|
||||
#include <isc/time.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
|
||||
+147
-194
@@ -22,7 +22,6 @@
|
||||
#include <isc/hex.h>
|
||||
#include <isc/md.h>
|
||||
#include <isc/mutex.h>
|
||||
#include <isc/pool.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/ratelimiter.h>
|
||||
@@ -34,7 +33,7 @@
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/strerr.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/taskpool.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/timer.h>
|
||||
#include <isc/tls.h>
|
||||
@@ -233,6 +232,8 @@ struct dns_zone {
|
||||
isc_rwlock_t dblock;
|
||||
dns_db_t *db; /* Locked by dblock */
|
||||
|
||||
unsigned int tid;
|
||||
|
||||
/* Locked */
|
||||
dns_zonemgr_t *zmgr;
|
||||
ISC_LINK(dns_zone_t) link; /* Used by zmgr. */
|
||||
@@ -594,10 +595,10 @@ struct dns_zonemgr {
|
||||
isc_taskmgr_t *taskmgr;
|
||||
isc_timermgr_t *timermgr;
|
||||
isc_nm_t *netmgr;
|
||||
isc_taskpool_t *zonetasks;
|
||||
isc_taskpool_t *loadtasks;
|
||||
uint32_t workers;
|
||||
isc_task_t *task;
|
||||
isc_pool_t *mctxpool;
|
||||
isc_task_t **zonetasks;
|
||||
isc_task_t **loadtasks;
|
||||
isc_ratelimiter_t *checkdsrl;
|
||||
isc_ratelimiter_t *notifyrl;
|
||||
isc_ratelimiter_t *refreshrl;
|
||||
@@ -1093,57 +1094,58 @@ inc_stats(dns_zone_t *zone, isc_statscounter_t counter) {
|
||||
***/
|
||||
|
||||
isc_result_t
|
||||
dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) {
|
||||
dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid) {
|
||||
isc_result_t result;
|
||||
isc_time_t now;
|
||||
dns_zone_t *zone = NULL;
|
||||
dns_zone_t z = { .masterformat = dns_masterformat_none,
|
||||
.journalsize = -1,
|
||||
.rdclass = dns_rdataclass_none,
|
||||
.type = dns_zone_none,
|
||||
.refresh = DNS_ZONE_DEFAULTREFRESH,
|
||||
.retry = DNS_ZONE_DEFAULTRETRY,
|
||||
.maxrefresh = DNS_ZONE_MAXREFRESH,
|
||||
.minrefresh = DNS_ZONE_MINREFRESH,
|
||||
.maxretry = DNS_ZONE_MAXRETRY,
|
||||
.minretry = DNS_ZONE_MINRETRY,
|
||||
.notifytype = dns_notifytype_yes,
|
||||
.zero_no_soa_ttl = true,
|
||||
.check_names = dns_severity_ignore,
|
||||
.idlein = DNS_DEFAULT_IDLEIN,
|
||||
.idleout = DNS_DEFAULT_IDLEOUT,
|
||||
.notifysrc4dscp = -1,
|
||||
.notifysrc6dscp = -1,
|
||||
.parentalsrc4dscp = -1,
|
||||
.parentalsrc6dscp = -1,
|
||||
.xfrsource4dscp = -1,
|
||||
.xfrsource6dscp = -1,
|
||||
.altxfrsource4dscp = -1,
|
||||
.altxfrsource6dscp = -1,
|
||||
.maxxfrin = MAX_XFER_TIME,
|
||||
.maxxfrout = MAX_XFER_TIME,
|
||||
.sigvalidityinterval = 30 * 24 * 3600,
|
||||
.sigresigninginterval = 7 * 24 * 3600,
|
||||
.statlevel = dns_zonestat_none,
|
||||
.notifydelay = 5,
|
||||
.signatures = 10,
|
||||
.nodes = 100,
|
||||
.privatetype = (dns_rdatatype_t)0xffffU,
|
||||
.rpz_num = DNS_RPZ_INVALID_NUM,
|
||||
.requestixfr = true,
|
||||
.ixfr_ratio = 100,
|
||||
.requestexpire = true,
|
||||
.updatemethod = dns_updatemethod_increment,
|
||||
.magic = ZONE_MAGIC };
|
||||
|
||||
REQUIRE(zonep != NULL && *zonep == NULL);
|
||||
REQUIRE(mctx != NULL);
|
||||
|
||||
TIME_NOW(&now);
|
||||
zone = isc_mem_get(mctx, sizeof(*zone));
|
||||
*zone = z;
|
||||
*zone = (dns_zone_t){
|
||||
.masterformat = dns_masterformat_none,
|
||||
.journalsize = -1,
|
||||
.rdclass = dns_rdataclass_none,
|
||||
.type = dns_zone_none,
|
||||
.refresh = DNS_ZONE_DEFAULTREFRESH,
|
||||
.retry = DNS_ZONE_DEFAULTRETRY,
|
||||
.maxrefresh = DNS_ZONE_MAXREFRESH,
|
||||
.minrefresh = DNS_ZONE_MINREFRESH,
|
||||
.maxretry = DNS_ZONE_MAXRETRY,
|
||||
.minretry = DNS_ZONE_MINRETRY,
|
||||
.notifytype = dns_notifytype_yes,
|
||||
.zero_no_soa_ttl = true,
|
||||
.check_names = dns_severity_ignore,
|
||||
.idlein = DNS_DEFAULT_IDLEIN,
|
||||
.idleout = DNS_DEFAULT_IDLEOUT,
|
||||
.notifysrc4dscp = -1,
|
||||
.notifysrc6dscp = -1,
|
||||
.parentalsrc4dscp = -1,
|
||||
.parentalsrc6dscp = -1,
|
||||
.xfrsource4dscp = -1,
|
||||
.xfrsource6dscp = -1,
|
||||
.altxfrsource4dscp = -1,
|
||||
.altxfrsource6dscp = -1,
|
||||
.maxxfrin = MAX_XFER_TIME,
|
||||
.maxxfrout = MAX_XFER_TIME,
|
||||
.sigvalidityinterval = 30 * 24 * 3600,
|
||||
.sigresigninginterval = 7 * 24 * 3600,
|
||||
.statlevel = dns_zonestat_none,
|
||||
.notifydelay = 5,
|
||||
.signatures = 10,
|
||||
.nodes = 100,
|
||||
.privatetype = (dns_rdatatype_t)0xffffU,
|
||||
.rpz_num = DNS_RPZ_INVALID_NUM,
|
||||
.requestixfr = true,
|
||||
.ixfr_ratio = 100,
|
||||
.requestexpire = true,
|
||||
.updatemethod = dns_updatemethod_increment,
|
||||
.magic = ZONE_MAGIC,
|
||||
.tid = tid,
|
||||
};
|
||||
|
||||
zone->mctx = NULL;
|
||||
isc_mem_attach(mctx, &zone->mctx);
|
||||
isc_mutex_init(&zone->lock);
|
||||
ZONEDB_INITLOCK(&zone->dblock);
|
||||
@@ -16220,23 +16222,6 @@ dns_zone_getorigin(dns_zone_t *zone) {
|
||||
return (&zone->origin);
|
||||
}
|
||||
|
||||
void
|
||||
dns_zone_settask(dns_zone_t *zone, isc_task_t *task) {
|
||||
REQUIRE(DNS_ZONE_VALID(zone));
|
||||
|
||||
LOCK_ZONE(zone);
|
||||
if (zone->task != NULL) {
|
||||
isc_task_detach(&zone->task);
|
||||
}
|
||||
isc_task_attach(task, &zone->task);
|
||||
ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read);
|
||||
if (zone->db != NULL) {
|
||||
dns_db_settask(zone->db, zone->task);
|
||||
}
|
||||
ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read);
|
||||
UNLOCK_ZONE(zone);
|
||||
}
|
||||
|
||||
void
|
||||
dns_zone_gettask(dns_zone_t *zone, isc_task_t **target) {
|
||||
REQUIRE(DNS_ZONE_VALID(zone));
|
||||
@@ -18802,22 +18787,33 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
dns_zonemgr_t *zmgr;
|
||||
isc_result_t result;
|
||||
|
||||
REQUIRE(mctx != NULL);
|
||||
REQUIRE(taskmgr != NULL);
|
||||
REQUIRE(timermgr != NULL);
|
||||
REQUIRE(netmgr != NULL);
|
||||
|
||||
zmgr = isc_mem_get(mctx, sizeof(*zmgr));
|
||||
zmgr->mctx = NULL;
|
||||
|
||||
*zmgr = (dns_zonemgr_t){
|
||||
.taskmgr = taskmgr,
|
||||
.timermgr = timermgr,
|
||||
.netmgr = netmgr,
|
||||
.workers = isc_nm_getnworkers(netmgr),
|
||||
.zonetasks = NULL,
|
||||
.loadtasks = NULL,
|
||||
.task = NULL,
|
||||
.checkdsrl = NULL,
|
||||
.notifyrl = NULL,
|
||||
.refreshrl = NULL,
|
||||
.startupnotifyrl = NULL,
|
||||
.startuprefreshrl = NULL,
|
||||
.transfersin = 10,
|
||||
.transfersperns = 2,
|
||||
};
|
||||
|
||||
isc_refcount_init(&zmgr->refs, 1);
|
||||
isc_mem_attach(mctx, &zmgr->mctx);
|
||||
zmgr->taskmgr = taskmgr;
|
||||
zmgr->timermgr = timermgr;
|
||||
zmgr->netmgr = netmgr;
|
||||
zmgr->zonetasks = NULL;
|
||||
zmgr->loadtasks = NULL;
|
||||
zmgr->mctxpool = NULL;
|
||||
zmgr->task = NULL;
|
||||
zmgr->checkdsrl = NULL;
|
||||
zmgr->notifyrl = NULL;
|
||||
zmgr->refreshrl = NULL;
|
||||
zmgr->startupnotifyrl = NULL;
|
||||
zmgr->startuprefreshrl = NULL;
|
||||
|
||||
ISC_LIST_INIT(zmgr->zones);
|
||||
ISC_LIST_INIT(zmgr->waiting_for_xfrin);
|
||||
ISC_LIST_INIT(zmgr->xfrin_in_progress);
|
||||
@@ -18827,9 +18823,6 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
}
|
||||
isc_rwlock_init(&zmgr->rwlock, 0, 0);
|
||||
|
||||
zmgr->transfersin = 10;
|
||||
zmgr->transfersperns = 2;
|
||||
|
||||
/* Unreachable lock. */
|
||||
isc_rwlock_init(&zmgr->urlock, 0, 0);
|
||||
|
||||
@@ -18870,6 +18863,31 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
goto free_startupnotifyrl;
|
||||
}
|
||||
|
||||
zmgr->zonetasks = isc_mem_get(
|
||||
zmgr->mctx, zmgr->workers * sizeof(zmgr->zonetasks[0]));
|
||||
memset(zmgr->zonetasks, 0, zmgr->workers * sizeof(zmgr->zonetasks[0]));
|
||||
for (size_t i = 0; i < zmgr->workers; i++) {
|
||||
result = isc_task_create_bound(zmgr->taskmgr, 2,
|
||||
&zmgr->zonetasks[i], i);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto free_zonetasks;
|
||||
}
|
||||
isc_task_setname(zmgr->zonetasks[i], "zonemgr-zonetasks", NULL);
|
||||
}
|
||||
|
||||
zmgr->loadtasks = isc_mem_get(
|
||||
zmgr->mctx, zmgr->workers * sizeof(zmgr->loadtasks[0]));
|
||||
memset(zmgr->loadtasks, 0, zmgr->workers * sizeof(zmgr->loadtasks[0]));
|
||||
for (size_t i = 0; i < zmgr->workers; i++) {
|
||||
result = isc_task_create_bound(zmgr->taskmgr, 2,
|
||||
&zmgr->loadtasks[i], i);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto free_loadtasks;
|
||||
}
|
||||
isc_task_setname(zmgr->loadtasks[i], "zonemgr-loadtasks", NULL);
|
||||
isc_task_setprivilege(zmgr->loadtasks[i], true);
|
||||
}
|
||||
|
||||
/* Key file I/O locks. */
|
||||
zonemgr_keymgmt_init(zmgr);
|
||||
|
||||
@@ -18900,6 +18918,25 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||
free_iolock:
|
||||
isc_mutex_destroy(&zmgr->iolock);
|
||||
#endif /* if 0 */
|
||||
free_loadtasks:
|
||||
for (size_t i = 0; i < zmgr->workers; i++) {
|
||||
if (zmgr->loadtasks[i] != NULL) {
|
||||
isc_task_detach(&zmgr->loadtasks[i]);
|
||||
}
|
||||
}
|
||||
isc_mem_put(zmgr->mctx, zmgr->loadtasks,
|
||||
zmgr->workers * sizeof(zmgr->loadtasks[0]));
|
||||
|
||||
free_zonetasks:
|
||||
for (size_t i = 0; i < zmgr->workers; i++) {
|
||||
if (zmgr->zonetasks[i] != NULL) {
|
||||
isc_task_detach(&zmgr->zonetasks[i]);
|
||||
}
|
||||
}
|
||||
isc_mem_put(zmgr->mctx, zmgr->zonetasks,
|
||||
zmgr->workers * sizeof(zmgr->zonetasks[0]));
|
||||
|
||||
isc_ratelimiter_detach(&zmgr->startuprefreshrl);
|
||||
free_startupnotifyrl:
|
||||
isc_ratelimiter_detach(&zmgr->startupnotifyrl);
|
||||
free_refreshrl:
|
||||
@@ -18923,23 +18960,17 @@ dns_zonemgr_createzone(dns_zonemgr_t *zmgr, dns_zone_t **zonep) {
|
||||
isc_result_t result;
|
||||
isc_mem_t *mctx = NULL;
|
||||
dns_zone_t *zone = NULL;
|
||||
void *item;
|
||||
unsigned int tid;
|
||||
|
||||
REQUIRE(DNS_ZONEMGR_VALID(zmgr));
|
||||
REQUIRE(zonep != NULL && *zonep == NULL);
|
||||
|
||||
if (zmgr->mctxpool == NULL) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
tid = isc_random_uniform(zmgr->workers);
|
||||
|
||||
item = isc_pool_get(zmgr->mctxpool);
|
||||
if (item == NULL) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
mctx = isc_nm_getmctx(zmgr->netmgr, tid);
|
||||
INSIST(mctx != NULL);
|
||||
|
||||
isc_mem_attach((isc_mem_t *)item, &mctx);
|
||||
result = dns_zone_create(&zone, mctx);
|
||||
isc_mem_detach(&mctx);
|
||||
result = dns_zone_create(&zone, mctx, tid);
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
*zonep = zone;
|
||||
@@ -18963,8 +18994,8 @@ dns_zonemgr_managezone(dns_zonemgr_t *zmgr, dns_zone_t *zone) {
|
||||
REQUIRE(zone->timer == NULL);
|
||||
REQUIRE(zone->zmgr == NULL);
|
||||
|
||||
isc_taskpool_gettask(zmgr->zonetasks, &zone->task);
|
||||
isc_taskpool_gettask(zmgr->loadtasks, &zone->loadtask);
|
||||
isc_task_attach(zmgr->zonetasks[zone->tid], &zone->task);
|
||||
isc_task_attach(zmgr->loadtasks[zone->tid], &zone->loadtask);
|
||||
|
||||
/*
|
||||
* Set the task name. The tag will arbitrarily point to one
|
||||
@@ -19096,15 +19127,22 @@ dns_zonemgr_shutdown(dns_zonemgr_t *zmgr) {
|
||||
if (zmgr->task != NULL) {
|
||||
isc_task_destroy(&zmgr->task);
|
||||
}
|
||||
if (zmgr->zonetasks != NULL) {
|
||||
isc_taskpool_destroy(&zmgr->zonetasks);
|
||||
|
||||
for (size_t i = 0; i < zmgr->workers; i++) {
|
||||
if (zmgr->loadtasks[i] != NULL) {
|
||||
isc_task_detach(&zmgr->loadtasks[i]);
|
||||
}
|
||||
}
|
||||
if (zmgr->loadtasks != NULL) {
|
||||
isc_taskpool_destroy(&zmgr->loadtasks);
|
||||
}
|
||||
if (zmgr->mctxpool != NULL) {
|
||||
isc_pool_destroy(&zmgr->mctxpool);
|
||||
isc_mem_put(zmgr->mctx, zmgr->loadtasks,
|
||||
zmgr->workers * sizeof(zmgr->loadtasks[0]));
|
||||
|
||||
for (size_t i = 0; i < zmgr->workers; i++) {
|
||||
if (zmgr->zonetasks[i] != NULL) {
|
||||
isc_task_detach(&zmgr->zonetasks[i]);
|
||||
}
|
||||
}
|
||||
isc_mem_put(zmgr->mctx, zmgr->zonetasks,
|
||||
zmgr->workers * sizeof(zmgr->zonetasks[0]));
|
||||
|
||||
RWLOCK(&zmgr->rwlock, isc_rwlocktype_read);
|
||||
for (zone = ISC_LIST_HEAD(zmgr->zones); zone != NULL;
|
||||
@@ -19117,101 +19155,6 @@ dns_zonemgr_shutdown(dns_zonemgr_t *zmgr) {
|
||||
RWUNLOCK(&zmgr->rwlock, isc_rwlocktype_read);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
mctxinit(void **target, void *arg) {
|
||||
isc_mem_t *mctx = NULL;
|
||||
|
||||
UNUSED(arg);
|
||||
|
||||
REQUIRE(target != NULL && *target == NULL);
|
||||
|
||||
isc_mem_create(&mctx);
|
||||
isc_mem_setname(mctx, "zonemgr-pool");
|
||||
|
||||
*target = mctx;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
mctxfree(void **target) {
|
||||
isc_mem_t *mctx = *(isc_mem_t **)target;
|
||||
isc_mem_detach(&mctx);
|
||||
*target = NULL;
|
||||
}
|
||||
|
||||
#define ZONES_PER_TASK 100
|
||||
#define ZONES_PER_MCTX 1000
|
||||
|
||||
isc_result_t
|
||||
dns_zonemgr_setsize(dns_zonemgr_t *zmgr, int num_zones) {
|
||||
isc_result_t result;
|
||||
int ntasks = num_zones / ZONES_PER_TASK;
|
||||
int nmctx = num_zones / ZONES_PER_MCTX;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
isc_pool_t *mctxpool = NULL;
|
||||
|
||||
REQUIRE(DNS_ZONEMGR_VALID(zmgr));
|
||||
|
||||
/*
|
||||
* For anything fewer than 1000 zones we use 10 tasks in
|
||||
* the task pools. More than that, and we'll scale at one
|
||||
* task per 100 zones. Similarly, for anything smaller than
|
||||
* 2000 zones we use 2 memory contexts, then scale at 1:1000.
|
||||
*/
|
||||
if (ntasks < 10) {
|
||||
ntasks = 10;
|
||||
}
|
||||
if (nmctx < 2) {
|
||||
nmctx = 2;
|
||||
}
|
||||
|
||||
/* Create or resize the zone task pools. */
|
||||
if (zmgr->zonetasks == NULL) {
|
||||
result = isc_taskpool_create(zmgr->taskmgr, zmgr->mctx, ntasks,
|
||||
2, false, &pool);
|
||||
} else {
|
||||
result = isc_taskpool_expand(&zmgr->zonetasks, ntasks, false,
|
||||
&pool);
|
||||
}
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
zmgr->zonetasks = pool;
|
||||
}
|
||||
|
||||
/*
|
||||
* We always set all tasks in the zone-load task pool to
|
||||
* privileged. This prevents other tasks in the system from
|
||||
* running while the server task manager is in privileged
|
||||
* mode.
|
||||
*/
|
||||
pool = NULL;
|
||||
if (zmgr->loadtasks == NULL) {
|
||||
result = isc_taskpool_create(zmgr->taskmgr, zmgr->mctx, ntasks,
|
||||
2, true, &pool);
|
||||
} else {
|
||||
result = isc_taskpool_expand(&zmgr->loadtasks, ntasks, true,
|
||||
&pool);
|
||||
}
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
zmgr->loadtasks = pool;
|
||||
}
|
||||
|
||||
/* Create or resize the zone memory context pool. */
|
||||
if (zmgr->mctxpool == NULL) {
|
||||
result = isc_pool_create(zmgr->mctx, nmctx, mctxfree, mctxinit,
|
||||
NULL, &mctxpool);
|
||||
} else {
|
||||
result = isc_pool_expand(&zmgr->mctxpool, nmctx, &mctxpool);
|
||||
}
|
||||
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
zmgr->mctxpool = mctxpool;
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
static void
|
||||
zonemgr_free(dns_zonemgr_t *zmgr) {
|
||||
isc_mem_t *mctx;
|
||||
@@ -23687,3 +23630,13 @@ dns_zonemgr_set_tlsctx_cache(dns_zonemgr_t *zmgr,
|
||||
|
||||
RWUNLOCK(&zmgr->rwlock, isc_rwlocktype_write);
|
||||
}
|
||||
|
||||
isc_mem_t *
|
||||
dns_zone_mctx(dns_zone_t *zone) {
|
||||
return (zone->mctx);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
dns_zone_tid(dns_zone_t *zone) {
|
||||
return (zone->tid);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ libisc_la_HEADERS = \
|
||||
include/isc/once.h \
|
||||
include/isc/os.h \
|
||||
include/isc/parseint.h \
|
||||
include/isc/pool.h \
|
||||
include/isc/portset.h \
|
||||
include/isc/print.h \
|
||||
include/isc/quota.h \
|
||||
@@ -90,7 +89,6 @@ libisc_la_HEADERS = \
|
||||
include/isc/symtab.h \
|
||||
include/isc/syslog.h \
|
||||
include/isc/task.h \
|
||||
include/isc/taskpool.h \
|
||||
include/isc/thread.h \
|
||||
include/isc/time.h \
|
||||
include/isc/timer.h \
|
||||
@@ -168,7 +166,6 @@ libisc_la_SOURCES = \
|
||||
os.c \
|
||||
os_p.h \
|
||||
parseint.c \
|
||||
pool.c \
|
||||
portset.c \
|
||||
quota.c \
|
||||
radix.c \
|
||||
@@ -191,7 +188,6 @@ libisc_la_SOURCES = \
|
||||
syslog.c \
|
||||
task.c \
|
||||
task_p.h \
|
||||
taskpool.c \
|
||||
thread.c \
|
||||
time.c \
|
||||
timer.c \
|
||||
|
||||
@@ -686,6 +686,12 @@ isc_nm_getnworkers(const isc_nm_t *);
|
||||
* Return the number of active workers
|
||||
*/
|
||||
|
||||
isc_mem_t *
|
||||
isc_nm_getmctx(const isc_nm_t *netmgr, uint32_t tid);
|
||||
/*%<
|
||||
* Return memory context associated with respective nm worker
|
||||
*/
|
||||
|
||||
void
|
||||
isc_nmhandle_setwritetimeout(isc_nmhandle_t *handle, uint64_t write_timeout);
|
||||
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/*****
|
||||
***** Module Info
|
||||
*****/
|
||||
|
||||
/*! \file isc/pool.h
|
||||
* \brief An object pool is a mechanism for sharing a small pool of
|
||||
* fungible objects among a large number of objects that depend on them.
|
||||
*
|
||||
* This is useful, for example, when it causes performance problems for
|
||||
* large number of zones to share a single memory context or task object,
|
||||
* but it would create a different set of problems for them each to have an
|
||||
* independent task or memory context.
|
||||
*/
|
||||
|
||||
/***
|
||||
*** Imports.
|
||||
***/
|
||||
|
||||
#include <isc/lang.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
/*****
|
||||
***** Types.
|
||||
*****/
|
||||
|
||||
typedef void (*isc_pooldeallocator_t)(void **object);
|
||||
|
||||
typedef isc_result_t (*isc_poolinitializer_t)(void **target, void *arg);
|
||||
|
||||
typedef struct isc_pool isc_pool_t;
|
||||
|
||||
/*****
|
||||
***** Functions.
|
||||
*****/
|
||||
|
||||
isc_result_t
|
||||
isc_pool_create(isc_mem_t *mctx, unsigned int count, isc_pooldeallocator_t free,
|
||||
isc_poolinitializer_t init, void *initarg, isc_pool_t **poolp);
|
||||
/*%<
|
||||
* Create a pool of "count" object pointers. If 'free' is not NULL,
|
||||
* it points to a function that will detach the objects. 'init'
|
||||
* points to a function that will initialize the arguments, and
|
||||
* 'arg' to an argument to be passed into that function (for example,
|
||||
* a relevant manager or context object).
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'mctx' is a valid memory context.
|
||||
*
|
||||
*\li init != NULL
|
||||
*
|
||||
*\li poolp != NULL && *poolp == NULL
|
||||
*
|
||||
* Ensures:
|
||||
*
|
||||
*\li On success, '*poolp' points to the new object pool.
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
*\li #ISC_R_SUCCESS
|
||||
*\li #ISC_R_NOMEMORY
|
||||
*\li #ISC_R_UNEXPECTED
|
||||
*/
|
||||
|
||||
void *
|
||||
isc_pool_get(isc_pool_t *pool);
|
||||
/*%<
|
||||
* Returns a pointer to an object from the pool. Currently the object
|
||||
* is chosen from the pool at random. (This may be changed in the future
|
||||
* to something that guaratees balance.)
|
||||
*/
|
||||
|
||||
int
|
||||
isc_pool_count(isc_pool_t *pool);
|
||||
/*%<
|
||||
* Returns the number of objcts in the pool 'pool'.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_pool_expand(isc_pool_t **sourcep, unsigned int count, isc_pool_t **targetp);
|
||||
|
||||
/*%<
|
||||
* If 'size' is larger than the number of objects in the pool pointed to by
|
||||
* 'sourcep', then a new pool of size 'count' is allocated, the existing
|
||||
* objects are copied into it, additional ones created to bring the
|
||||
* total number up to 'count', and the resulting pool is attached to
|
||||
* 'targetp'.
|
||||
*
|
||||
* If 'count' is less than or equal to the number of objects in 'source', then
|
||||
* 'sourcep' is attached to 'targetp' without any other action being taken.
|
||||
*
|
||||
* In either case, 'sourcep' is detached.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
* \li 'sourcep' is not NULL and '*source' is not NULL
|
||||
* \li 'targetp' is not NULL and '*source' is NULL
|
||||
*
|
||||
* Ensures:
|
||||
*
|
||||
* \li On success, '*targetp' points to a valid task pool.
|
||||
* \li On success, '*sourcep' points to NULL.
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
* \li #ISC_R_SUCCESS
|
||||
* \li #ISC_R_NOMEMORY
|
||||
*/
|
||||
|
||||
void
|
||||
isc_pool_destroy(isc_pool_t **poolp);
|
||||
/*%<
|
||||
* Destroy a task pool. The tasks in the pool are detached but not
|
||||
* shut down.
|
||||
*
|
||||
* Requires:
|
||||
* \li '*poolp' is a valid task pool.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/*****
|
||||
***** Module Info
|
||||
*****/
|
||||
|
||||
/*! \file isc/taskpool.h
|
||||
* \brief A task pool is a mechanism for sharing a small number of tasks
|
||||
* among a large number of objects such that each object is
|
||||
* assigned a unique task, but each task may be shared by several
|
||||
* objects.
|
||||
*
|
||||
* Task pools are used to let objects that can exist in large
|
||||
* numbers (e.g., zones) use tasks for synchronization without
|
||||
* the memory overhead and unfair scheduling competition that
|
||||
* could result from creating a separate task for each object.
|
||||
*/
|
||||
|
||||
/***
|
||||
*** Imports.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <isc/lang.h>
|
||||
#include <isc/task.h>
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
/*****
|
||||
***** Types.
|
||||
*****/
|
||||
|
||||
typedef struct isc_taskpool isc_taskpool_t;
|
||||
|
||||
/*****
|
||||
***** Functions.
|
||||
*****/
|
||||
|
||||
isc_result_t
|
||||
isc_taskpool_create(isc_taskmgr_t *tmgr, isc_mem_t *mctx, unsigned int ntasks,
|
||||
unsigned int quantum, bool priv, isc_taskpool_t **poolp);
|
||||
/*%<
|
||||
* Create a task pool of "ntasks" tasks, each with quantum
|
||||
* "quantum".
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'tmgr' is a valid task manager.
|
||||
*
|
||||
*\li 'mctx' is a valid memory context.
|
||||
*
|
||||
*\li poolp != NULL && *poolp == NULL
|
||||
*
|
||||
* Ensures:
|
||||
*
|
||||
*\li On success, '*taskp' points to the new task pool.
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
*\li #ISC_R_SUCCESS
|
||||
*\li #ISC_R_NOMEMORY
|
||||
*\li #ISC_R_UNEXPECTED
|
||||
*/
|
||||
|
||||
void
|
||||
isc_taskpool_gettask(isc_taskpool_t *pool, isc_task_t **targetp);
|
||||
/*%<
|
||||
* Attach to a task from the pool. Currently the next task is chosen
|
||||
* from the pool at random. (This may be changed in the future to
|
||||
* something that guaratees balance.)
|
||||
*/
|
||||
|
||||
int
|
||||
isc_taskpool_size(isc_taskpool_t *pool);
|
||||
/*%<
|
||||
* Returns the number of tasks in the task pool 'pool'.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
isc_taskpool_expand(isc_taskpool_t **sourcep, unsigned int size, bool priv,
|
||||
isc_taskpool_t **targetp);
|
||||
|
||||
/*%<
|
||||
* If 'size' is larger than the number of tasks in the pool pointed to by
|
||||
* 'sourcep', then a new taskpool of size 'size' is allocated, the existing
|
||||
* tasks from are moved into it, additional tasks are created to bring the
|
||||
* total number up to 'size', and the resulting pool is attached to
|
||||
* 'targetp'.
|
||||
*
|
||||
* If 'size' is less than or equal to the tasks in pool 'source', then
|
||||
* 'sourcep' is attached to 'targetp' without any other action being taken.
|
||||
*
|
||||
* In either case, 'sourcep' is detached.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
* \li 'sourcep' is not NULL and '*source' is not NULL
|
||||
* \li 'targetp' is not NULL and '*source' is NULL
|
||||
*
|
||||
* Ensures:
|
||||
*
|
||||
* \li On success, '*targetp' points to a valid task pool.
|
||||
* \li On success, '*sourcep' points to NULL.
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
* \li #ISC_R_SUCCESS
|
||||
* \li #ISC_R_NOMEMORY
|
||||
*/
|
||||
|
||||
void
|
||||
isc_taskpool_destroy(isc_taskpool_t **poolp);
|
||||
/*%<
|
||||
* Destroy a task pool. The tasks in the pool are detached but not
|
||||
* shut down.
|
||||
*
|
||||
* Requires:
|
||||
* \li '*poolp' is a valid task pool.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
+13
-10
@@ -1130,10 +1130,11 @@ http_send_outgoing(isc_nm_http_session_t *session, isc_nmhandle_t *httphandle,
|
||||
* FLUSH_HTTP_WRITE_BUFFER_AFTER bytes in the write buffer, we
|
||||
* will flush the buffer. */
|
||||
if (cb != NULL) {
|
||||
INSIST(VALID_NMHANDLE(httphandle));
|
||||
|
||||
isc__nm_uvreq_t *newcb = isc__nm_uvreq_get(
|
||||
httphandle->sock->mgr, httphandle->sock);
|
||||
|
||||
INSIST(VALID_NMHANDLE(httphandle));
|
||||
newcb->cb.send = cb;
|
||||
newcb->cbarg = cbarg;
|
||||
isc_nmhandle_attach(httphandle, &newcb->handle);
|
||||
@@ -2129,6 +2130,7 @@ isc__nm_http_send(isc_nmhandle_t *handle, const isc_region_t *region,
|
||||
isc_nmsocket_t *sock = NULL;
|
||||
isc__netievent_httpsend_t *ievent = NULL;
|
||||
isc__nm_uvreq_t *uvreq = NULL;
|
||||
isc__networker_t *worker = NULL;
|
||||
|
||||
REQUIRE(VALID_NMHANDLE(handle));
|
||||
|
||||
@@ -2136,6 +2138,8 @@ isc__nm_http_send(isc_nmhandle_t *handle, const isc_region_t *region,
|
||||
|
||||
REQUIRE(VALID_NMSOCK(sock));
|
||||
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
|
||||
uvreq = isc__nm_uvreq_get(sock->mgr, sock);
|
||||
isc_nmhandle_attach(handle, &uvreq->handle);
|
||||
uvreq->cb.send = cb;
|
||||
@@ -2144,9 +2148,8 @@ isc__nm_http_send(isc_nmhandle_t *handle, const isc_region_t *region,
|
||||
uvreq->uvbuf.base = (char *)region->base;
|
||||
uvreq->uvbuf.len = region->length;
|
||||
|
||||
ievent = isc__nm_get_netievent_httpsend(sock->mgr, sock, uvreq);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
ievent = isc__nm_get_netievent_httpsend(worker, sock, uvreq);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2676,10 +2679,10 @@ isc__nm_http_stoplistening(isc_nmsocket_t *sock) {
|
||||
}
|
||||
|
||||
if (!isc__nm_in_netthread()) {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_httpstop_t *ievent =
|
||||
isc__nm_get_netievent_httpstop(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_httpstop(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
} else {
|
||||
REQUIRE(isc_nm_tid() == sock->tid);
|
||||
isc__netievent_httpstop_t ievent = { .sock = sock };
|
||||
@@ -2754,11 +2757,11 @@ isc__nm_http_close(isc_nmsocket_t *sock) {
|
||||
return;
|
||||
}
|
||||
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_httpclose_t *ievent =
|
||||
isc__nm_get_netievent_httpclose(sock->mgr, sock);
|
||||
isc__nm_get_netievent_httpclose(worker, sock);
|
||||
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+67
-59
@@ -224,6 +224,7 @@ typedef struct ievent {
|
||||
*/
|
||||
typedef struct isc__networker {
|
||||
isc_nm_t *mgr;
|
||||
isc_mem_t *mctx; /* per worker memory context */
|
||||
int id; /* thread id */
|
||||
uv_loop_t loop; /* libuv loop structure */
|
||||
uv_async_t async; /* async channel to send
|
||||
@@ -402,12 +403,12 @@ struct isc__nm_uvreq {
|
||||
};
|
||||
|
||||
void *
|
||||
isc__nm_get_netievent(isc_nm_t *mgr, isc__netievent_type type);
|
||||
isc__nm_get_netievent(isc__networker_t *worker, isc__netievent_type type);
|
||||
/*%<
|
||||
* Allocate an ievent and set the type.
|
||||
*/
|
||||
void
|
||||
isc__nm_put_netievent(isc_nm_t *mgr, void *ievent);
|
||||
isc__nm_put_netievent(isc__networker_t *worker, void *ievent);
|
||||
|
||||
/*
|
||||
* The macros here are used to simulate the "inheritance" in C, there's the base
|
||||
@@ -451,26 +452,26 @@ typedef struct isc__netievent__socket {
|
||||
#define NETIEVENT_SOCKET_TYPE(type) \
|
||||
typedef isc__netievent__socket_t isc__netievent_##type##_t;
|
||||
|
||||
#define NETIEVENT_SOCKET_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock); \
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
#define NETIEVENT_SOCKET_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock); \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent);
|
||||
|
||||
#define NETIEVENT_SOCKET_DEF(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock) { \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock) { \
|
||||
isc__netievent_##type##_t *ievent = \
|
||||
isc__nm_get_netievent(nm, netievent_##type); \
|
||||
isc__nm_get_netievent(worker, netievent_##type); \
|
||||
isc__nmsocket_attach(sock, &ievent->sock); \
|
||||
\
|
||||
return (ievent); \
|
||||
} \
|
||||
\
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent) { \
|
||||
isc__nmsocket_detach(&ievent->sock); \
|
||||
isc__nm_put_netievent(nm, ievent); \
|
||||
isc__nm_put_netievent(worker, ievent); \
|
||||
}
|
||||
|
||||
typedef struct isc__netievent__socket_req {
|
||||
@@ -481,27 +482,29 @@ typedef struct isc__netievent__socket_req {
|
||||
#define NETIEVENT_SOCKET_REQ_TYPE(type) \
|
||||
typedef isc__netievent__socket_req_t isc__netievent_##type##_t;
|
||||
|
||||
#define NETIEVENT_SOCKET_REQ_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock, isc__nm_uvreq_t *req); \
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
#define NETIEVENT_SOCKET_REQ_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock, \
|
||||
isc__nm_uvreq_t *req); \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent);
|
||||
|
||||
#define NETIEVENT_SOCKET_REQ_DEF(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock, \
|
||||
isc__nm_uvreq_t *req) { \
|
||||
isc__netievent_##type##_t *ievent = \
|
||||
isc__nm_get_netievent(nm, netievent_##type); \
|
||||
isc__nm_get_netievent(worker, netievent_##type); \
|
||||
isc__nmsocket_attach(sock, &ievent->sock); \
|
||||
ievent->req = req; \
|
||||
\
|
||||
return (ievent); \
|
||||
} \
|
||||
\
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent) { \
|
||||
isc__nmsocket_detach(&ievent->sock); \
|
||||
isc__nm_put_netievent(nm, ievent); \
|
||||
isc__nm_put_netievent(worker, ievent); \
|
||||
}
|
||||
|
||||
typedef struct isc__netievent__socket_req_result {
|
||||
@@ -513,19 +516,19 @@ typedef struct isc__netievent__socket_req_result {
|
||||
#define NETIEVENT_SOCKET_REQ_RESULT_TYPE(type) \
|
||||
typedef isc__netievent__socket_req_result_t isc__netievent_##type##_t;
|
||||
|
||||
#define NETIEVENT_SOCKET_REQ_RESULT_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock, isc__nm_uvreq_t *req, \
|
||||
isc_result_t result); \
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
#define NETIEVENT_SOCKET_REQ_RESULT_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock, \
|
||||
isc__nm_uvreq_t *req, isc_result_t result); \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent);
|
||||
|
||||
#define NETIEVENT_SOCKET_REQ_RESULT_DEF(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock, isc__nm_uvreq_t *req, \
|
||||
isc_result_t result) { \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock, \
|
||||
isc__nm_uvreq_t *req, isc_result_t result) { \
|
||||
isc__netievent_##type##_t *ievent = \
|
||||
isc__nm_get_netievent(nm, netievent_##type); \
|
||||
isc__nm_get_netievent(worker, netievent_##type); \
|
||||
isc__nmsocket_attach(sock, &ievent->sock); \
|
||||
ievent->req = req; \
|
||||
ievent->result = result; \
|
||||
@@ -533,10 +536,10 @@ typedef struct isc__netievent__socket_req_result {
|
||||
return (ievent); \
|
||||
} \
|
||||
\
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent) { \
|
||||
isc__nmsocket_detach(&ievent->sock); \
|
||||
isc__nm_put_netievent(nm, ievent); \
|
||||
isc__nm_put_netievent(worker, ievent); \
|
||||
}
|
||||
|
||||
typedef struct isc__netievent__socket_handle {
|
||||
@@ -547,28 +550,30 @@ typedef struct isc__netievent__socket_handle {
|
||||
#define NETIEVENT_SOCKET_HANDLE_TYPE(type) \
|
||||
typedef isc__netievent__socket_handle_t isc__netievent_##type##_t;
|
||||
|
||||
#define NETIEVENT_SOCKET_HANDLE_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock, isc_nmhandle_t *handle); \
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
#define NETIEVENT_SOCKET_HANDLE_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock, \
|
||||
isc_nmhandle_t *handle); \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent);
|
||||
|
||||
#define NETIEVENT_SOCKET_HANDLE_DEF(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock, isc_nmhandle_t *handle) { \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock, \
|
||||
isc_nmhandle_t *handle) { \
|
||||
isc__netievent_##type##_t *ievent = \
|
||||
isc__nm_get_netievent(nm, netievent_##type); \
|
||||
isc__nm_get_netievent(worker, netievent_##type); \
|
||||
isc__nmsocket_attach(sock, &ievent->sock); \
|
||||
isc_nmhandle_attach(handle, &ievent->handle); \
|
||||
\
|
||||
return (ievent); \
|
||||
} \
|
||||
\
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent) { \
|
||||
isc__nmsocket_detach(&ievent->sock); \
|
||||
isc_nmhandle_detach(&ievent->handle); \
|
||||
isc__nm_put_netievent(nm, ievent); \
|
||||
isc__nm_put_netievent(worker, ievent); \
|
||||
}
|
||||
|
||||
typedef struct isc__netievent__socket_quota {
|
||||
@@ -579,27 +584,29 @@ typedef struct isc__netievent__socket_quota {
|
||||
#define NETIEVENT_SOCKET_QUOTA_TYPE(type) \
|
||||
typedef isc__netievent__socket_quota_t isc__netievent_##type##_t;
|
||||
|
||||
#define NETIEVENT_SOCKET_QUOTA_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock, isc_quota_t *quota); \
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
#define NETIEVENT_SOCKET_QUOTA_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock, \
|
||||
isc_quota_t *quota); \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent);
|
||||
|
||||
#define NETIEVENT_SOCKET_QUOTA_DEF(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_nmsocket_t *sock, isc_quota_t *quota) { \
|
||||
isc__networker_t *worker, isc_nmsocket_t *sock, \
|
||||
isc_quota_t *quota) { \
|
||||
isc__netievent_##type##_t *ievent = \
|
||||
isc__nm_get_netievent(nm, netievent_##type); \
|
||||
isc__nm_get_netievent(worker, netievent_##type); \
|
||||
isc__nmsocket_attach(sock, &ievent->sock); \
|
||||
ievent->quota = quota; \
|
||||
\
|
||||
return (ievent); \
|
||||
} \
|
||||
\
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent) { \
|
||||
isc__nmsocket_detach(&ievent->sock); \
|
||||
isc__nm_put_netievent(nm, ievent); \
|
||||
isc__nm_put_netievent(worker, ievent); \
|
||||
}
|
||||
|
||||
typedef struct isc__netievent__task {
|
||||
@@ -611,26 +618,26 @@ typedef struct isc__netievent__task {
|
||||
#define NETIEVENT_TASK_TYPE(type) \
|
||||
typedef isc__netievent__task_t isc__netievent_##type##_t;
|
||||
|
||||
#define NETIEVENT_TASK_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_task_t *task); \
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
#define NETIEVENT_TASK_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc__networker_t *worker, isc_task_t *task); \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent);
|
||||
|
||||
#define NETIEVENT_TASK_DEF(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm, isc_task_t *task) { \
|
||||
isc__networker_t *worker, isc_task_t *task) { \
|
||||
isc__netievent_##type##_t *ievent = \
|
||||
isc__nm_get_netievent(nm, netievent_##type); \
|
||||
isc__nm_get_netievent(worker, netievent_##type); \
|
||||
ievent->task = task; \
|
||||
\
|
||||
return (ievent); \
|
||||
} \
|
||||
\
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent) { \
|
||||
ievent->task = NULL; \
|
||||
isc__nm_put_netievent(nm, ievent); \
|
||||
isc__nm_put_netievent(worker, ievent); \
|
||||
}
|
||||
|
||||
typedef struct isc__netievent_udpsend {
|
||||
@@ -653,23 +660,24 @@ typedef struct isc__netievent {
|
||||
|
||||
#define NETIEVENT_TYPE(type) typedef isc__netievent_t isc__netievent_##type##_t;
|
||||
|
||||
#define NETIEVENT_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type(isc_nm_t *nm); \
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
#define NETIEVENT_DECL(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc__networker_t *worker); \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent);
|
||||
|
||||
#define NETIEVENT_DEF(type) \
|
||||
isc__netievent_##type##_t *isc__nm_get_netievent_##type( \
|
||||
isc_nm_t *nm) { \
|
||||
isc__networker_t *worker) { \
|
||||
isc__netievent_##type##_t *ievent = \
|
||||
isc__nm_get_netievent(nm, netievent_##type); \
|
||||
isc__nm_get_netievent(worker, netievent_##type); \
|
||||
\
|
||||
return (ievent); \
|
||||
} \
|
||||
\
|
||||
void isc__nm_put_netievent_##type(isc_nm_t *nm, \
|
||||
void isc__nm_put_netievent_##type(isc__networker_t *worker, \
|
||||
isc__netievent_##type##_t *ievent) { \
|
||||
isc__nm_put_netievent(nm, ievent); \
|
||||
isc__nm_put_netievent(worker, ievent); \
|
||||
}
|
||||
|
||||
typedef union {
|
||||
|
||||
+75
-57
@@ -260,6 +260,9 @@ isc__netmgr_create(isc_mem_t *mctx, uint32_t workers, isc_nm_t **netmgrp) {
|
||||
.id = i,
|
||||
};
|
||||
|
||||
isc_mem_create(&worker->mctx);
|
||||
isc_mem_setname(worker->mctx, "netmgr-worker");
|
||||
|
||||
r = uv_loop_init(&worker->loop);
|
||||
UV_RUNTIME_CHECK(uv_loop_init, r);
|
||||
|
||||
@@ -274,8 +277,10 @@ isc__netmgr_create(isc_mem_t *mctx, uint32_t workers, isc_nm_t **netmgrp) {
|
||||
ISC_LIST_INIT(worker->ievents[type].list);
|
||||
}
|
||||
|
||||
worker->recvbuf = isc_mem_get(mctx, ISC_NETMGR_RECVBUF_SIZE);
|
||||
worker->sendbuf = isc_mem_get(mctx, ISC_NETMGR_SENDBUF_SIZE);
|
||||
worker->recvbuf = isc_mem_get(worker->mctx,
|
||||
ISC_NETMGR_RECVBUF_SIZE);
|
||||
worker->sendbuf = isc_mem_get(worker->mctx,
|
||||
ISC_NETMGR_SENDBUF_SIZE);
|
||||
|
||||
/*
|
||||
* We need to do this here and not in nm_thread to avoid a
|
||||
@@ -310,7 +315,7 @@ nm_destroy(isc_nm_t **mgr0) {
|
||||
|
||||
for (int i = 0; i < mgr->nworkers; i++) {
|
||||
isc__networker_t *worker = &mgr->workers[i];
|
||||
isc__netievent_t *event = isc__nm_get_netievent_stop(mgr);
|
||||
isc__netievent_t *event = isc__nm_get_netievent_stop(worker);
|
||||
isc__nm_enqueue_ievent(worker, event);
|
||||
}
|
||||
|
||||
@@ -333,11 +338,13 @@ nm_destroy(isc_nm_t **mgr0) {
|
||||
isc_mutex_destroy(&worker->ievents[type].lock);
|
||||
}
|
||||
|
||||
isc_mem_put(mgr->mctx, worker->sendbuf,
|
||||
isc_mem_put(worker->mctx, worker->sendbuf,
|
||||
ISC_NETMGR_SENDBUF_SIZE);
|
||||
isc_mem_put(mgr->mctx, worker->recvbuf,
|
||||
isc_mem_put(worker->mctx, worker->recvbuf,
|
||||
ISC_NETMGR_RECVBUF_SIZE);
|
||||
isc_thread_join(worker->thread, NULL);
|
||||
|
||||
isc_mem_detach(&worker->mctx);
|
||||
}
|
||||
|
||||
if (mgr->stats != NULL) {
|
||||
@@ -358,8 +365,7 @@ nm_destroy(isc_nm_t **mgr0) {
|
||||
|
||||
static void
|
||||
enqueue_pause(isc__networker_t *worker) {
|
||||
isc__netievent_pause_t *event =
|
||||
isc__nm_get_netievent_pause(worker->mgr);
|
||||
isc__netievent_pause_t *event = isc__nm_get_netievent_pause(worker);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)event);
|
||||
}
|
||||
|
||||
@@ -409,8 +415,7 @@ isc_nm_pause(isc_nm_t *mgr) {
|
||||
|
||||
static void
|
||||
enqueue_resume(isc__networker_t *worker) {
|
||||
isc__netievent_resume_t *event =
|
||||
isc__nm_get_netievent_resume(worker->mgr);
|
||||
isc__netievent_resume_t *event = isc__nm_get_netievent_resume(worker);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)event);
|
||||
}
|
||||
|
||||
@@ -490,9 +495,9 @@ isc__netmgr_shutdown(isc_nm_t *mgr) {
|
||||
REQUIRE(VALID_NM(mgr));
|
||||
|
||||
atomic_store(&mgr->closing, true);
|
||||
for (int i = 0; i < mgr->nworkers; i++) {
|
||||
for (size_t i = 0; i < (size_t)mgr->nworkers; i++) {
|
||||
isc__netievent_t *event = NULL;
|
||||
event = isc__nm_get_netievent_shutdown(mgr);
|
||||
event = isc__nm_get_netievent_shutdown(&mgr->workers[i]);
|
||||
isc__nm_enqueue_ievent(&mgr->workers[i], event);
|
||||
}
|
||||
}
|
||||
@@ -765,9 +770,9 @@ isc_nm_task_enqueue(isc_nm_t *nm, isc_task_t *task, int tid) {
|
||||
|
||||
if (isc_task_privileged(task)) {
|
||||
event = (isc__netievent_t *)
|
||||
isc__nm_get_netievent_privilegedtask(nm, task);
|
||||
isc__nm_get_netievent_privilegedtask(worker, task);
|
||||
} else {
|
||||
event = (isc__netievent_t *)isc__nm_get_netievent_task(nm,
|
||||
event = (isc__netievent_t *)isc__nm_get_netievent_task(worker,
|
||||
task);
|
||||
}
|
||||
|
||||
@@ -833,19 +838,19 @@ drain_queue(isc__networker_t *worker, netievent_type_t type) {
|
||||
* process_queue() to stop, e.g. it's only used for the netievent that
|
||||
* stops/pauses processing the enqueued netievents.
|
||||
*/
|
||||
#define NETIEVENT_CASE(type) \
|
||||
case netievent_##type: { \
|
||||
isc__nm_async_##type(worker, ievent); \
|
||||
isc__nm_put_netievent_##type( \
|
||||
worker->mgr, (isc__netievent_##type##_t *)ievent); \
|
||||
return (true); \
|
||||
#define NETIEVENT_CASE(type) \
|
||||
case netievent_##type: { \
|
||||
isc__nm_async_##type(worker, ievent); \
|
||||
isc__nm_put_netievent_##type( \
|
||||
worker, (isc__netievent_##type##_t *)ievent); \
|
||||
return (true); \
|
||||
}
|
||||
|
||||
#define NETIEVENT_CASE_NOMORE(type) \
|
||||
case netievent_##type: { \
|
||||
isc__nm_async_##type(worker, ievent); \
|
||||
isc__nm_put_netievent_##type(worker->mgr, ievent); \
|
||||
return (false); \
|
||||
#define NETIEVENT_CASE_NOMORE(type) \
|
||||
case netievent_##type: { \
|
||||
isc__nm_async_##type(worker, ievent); \
|
||||
isc__nm_put_netievent_##type(worker, ievent); \
|
||||
return (false); \
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -972,8 +977,8 @@ process_queue(isc__networker_t *worker, netievent_type_t type) {
|
||||
}
|
||||
|
||||
void *
|
||||
isc__nm_get_netievent(isc_nm_t *mgr, isc__netievent_type type) {
|
||||
isc__netievent_storage_t *event = isc_mem_get(mgr->mctx,
|
||||
isc__nm_get_netievent(isc__networker_t *worker, isc__netievent_type type) {
|
||||
isc__netievent_storage_t *event = isc_mem_get(worker->mctx,
|
||||
sizeof(*event));
|
||||
|
||||
*event = (isc__netievent_storage_t){ .ni.type = type };
|
||||
@@ -982,8 +987,8 @@ isc__nm_get_netievent(isc_nm_t *mgr, isc__netievent_type type) {
|
||||
}
|
||||
|
||||
void
|
||||
isc__nm_put_netievent(isc_nm_t *mgr, void *ievent) {
|
||||
isc_mem_put(mgr->mctx, ievent, sizeof(isc__netievent_storage_t));
|
||||
isc__nm_put_netievent(isc__networker_t *worker, void *ievent) {
|
||||
isc_mem_put(worker->mctx, ievent, sizeof(isc__netievent_storage_t));
|
||||
}
|
||||
|
||||
NETIEVENT_SOCKET_DEF(tcpclose);
|
||||
@@ -1211,7 +1216,8 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) {
|
||||
}
|
||||
|
||||
if (sock->buf != NULL) {
|
||||
isc_mem_put(sock->mgr->mctx, sock->buf, sock->buf_size);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc_mem_put(worker->mctx, sock->buf, sock->buf_size);
|
||||
}
|
||||
|
||||
if (sock->quota != NULL) {
|
||||
@@ -1554,9 +1560,8 @@ isc__nm_free_uvbuf(isc_nmsocket_t *sock, const uv_buf_t *buf) {
|
||||
|
||||
static isc_nmhandle_t *
|
||||
alloc_handle(isc_nmsocket_t *sock) {
|
||||
isc_nmhandle_t *handle =
|
||||
isc_mem_get(sock->mgr->mctx,
|
||||
sizeof(isc_nmhandle_t) + sock->extrahandlesize);
|
||||
isc_nmhandle_t *handle = isc_mem_get(
|
||||
sock->mgr->mctx, sizeof(isc_nmhandle_t) + sock->extrahandlesize);
|
||||
|
||||
*handle = (isc_nmhandle_t){ .magic = NMHANDLE_MAGIC };
|
||||
#ifdef NETMGR_TRACE
|
||||
@@ -1733,16 +1738,16 @@ isc__nmhandle_detach(isc_nmhandle_t **handlep FLARG) {
|
||||
if (sock->tid == isc_nm_tid() && sock->closehandle_cb == NULL) {
|
||||
nmhandle_detach_cb(&handle FLARG_PASS);
|
||||
} else {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_detach_t *event =
|
||||
isc__nm_get_netievent_detach(sock->mgr, sock);
|
||||
isc__nm_get_netievent_detach(worker, sock);
|
||||
/*
|
||||
* we are using implicit "attach" as the last reference
|
||||
* need to be destroyed explicitly in the async callback
|
||||
*/
|
||||
event->handle = handle;
|
||||
FLARG_IEVENT_PASS(event);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)event);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1792,9 +1797,11 @@ nmhandle_detach_cb(isc_nmhandle_t **handlep FLARG) {
|
||||
if (sock->tid == isc_nm_tid()) {
|
||||
sock->closehandle_cb(sock);
|
||||
} else {
|
||||
isc__networker_t *worker =
|
||||
&sock->mgr->workers[sock->tid];
|
||||
isc__netievent_close_t *event =
|
||||
isc__nm_get_netievent_close(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
isc__nm_get_netievent_close(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker,
|
||||
(isc__netievent_t *)event);
|
||||
}
|
||||
}
|
||||
@@ -1827,15 +1834,16 @@ isc_nmhandle_setdata(isc_nmhandle_t *handle, void *arg,
|
||||
void
|
||||
isc__nm_alloc_dnsbuf(isc_nmsocket_t *sock, size_t len) {
|
||||
REQUIRE(len <= NM_BIG_BUF);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
|
||||
if (sock->buf == NULL) {
|
||||
/* We don't have the buffer at all */
|
||||
size_t alloc_len = len < NM_REG_BUF ? NM_REG_BUF : NM_BIG_BUF;
|
||||
sock->buf = isc_mem_get(sock->mgr->mctx, alloc_len);
|
||||
sock->buf = isc_mem_get(worker->mctx, alloc_len);
|
||||
sock->buf_size = alloc_len;
|
||||
} else {
|
||||
/* We have the buffer but it's too small */
|
||||
sock->buf = isc_mem_reget(sock->mgr->mctx, sock->buf,
|
||||
sock->buf = isc_mem_reget(worker->mctx, sock->buf,
|
||||
sock->buf_size, NM_BIG_BUF);
|
||||
sock->buf_size = NM_BIG_BUF;
|
||||
}
|
||||
@@ -2430,13 +2438,13 @@ isc___nm_uvreq_get(isc_nm_t *mgr, isc_nmsocket_t *sock FLARG) {
|
||||
REQUIRE(VALID_NM(mgr));
|
||||
REQUIRE(VALID_NMSOCK(sock));
|
||||
|
||||
if (sock != NULL && isc__nmsocket_active(sock)) {
|
||||
if (isc__nmsocket_active(sock)) {
|
||||
/* Try to reuse one */
|
||||
req = isc_astack_pop(sock->inactivereqs);
|
||||
}
|
||||
|
||||
if (req == NULL) {
|
||||
req = isc_mem_get(mgr->mctx, sizeof(*req));
|
||||
req = isc_mem_get(sock->mgr->mctx, sizeof(*req));
|
||||
}
|
||||
|
||||
*req = (isc__nm_uvreq_t){ .magic = 0 };
|
||||
@@ -2452,6 +2460,7 @@ void
|
||||
isc___nm_uvreq_put(isc__nm_uvreq_t **req0, isc_nmsocket_t *sock FLARG) {
|
||||
isc__nm_uvreq_t *req = NULL;
|
||||
isc_nmhandle_t *handle = NULL;
|
||||
bool free = true;
|
||||
|
||||
REQUIRE(req0 != NULL);
|
||||
REQUIRE(VALID_UVREQ(*req0));
|
||||
@@ -2471,13 +2480,14 @@ isc___nm_uvreq_put(isc__nm_uvreq_t **req0, isc_nmsocket_t *sock FLARG) {
|
||||
req->handle = NULL;
|
||||
|
||||
#if !__SANITIZE_ADDRESS__ && !__SANITIZE_THREAD__
|
||||
if (!isc__nmsocket_active(sock) ||
|
||||
!isc_astack_trypush(sock->inactivereqs, req)) {
|
||||
if (isc__nmsocket_active(sock) &&
|
||||
isc_astack_trypush(sock->inactivereqs, req)) {
|
||||
free = false;
|
||||
}
|
||||
#endif /* !__SANITIZE_ADDRESS__ && !__SANITIZE_THREAD__ */
|
||||
if (free) {
|
||||
isc_mem_put(sock->mgr->mctx, req, sizeof(*req));
|
||||
}
|
||||
#else /* !__SANITIZE_ADDRESS__ && !__SANITIZE_THREAD__ */
|
||||
isc_mem_put(sock->mgr->mctx, req, sizeof(*req));
|
||||
#endif /* !__SANITIZE_ADDRESS__ && !__SANITIZE_THREAD__ */
|
||||
|
||||
if (handle != NULL) {
|
||||
isc__nmhandle_detach(&handle FLARG_PASS);
|
||||
@@ -2664,11 +2674,11 @@ isc__nm_connectcb(isc_nmsocket_t *sock, isc__nm_uvreq_t *uvreq,
|
||||
.result = eresult };
|
||||
isc__nm_async_connectcb(NULL, (isc__netievent_t *)&ievent);
|
||||
} else {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_connectcb_t *ievent =
|
||||
isc__nm_get_netievent_connectcb(sock->mgr, sock, uvreq,
|
||||
isc__nm_get_netievent_connectcb(worker, sock, uvreq,
|
||||
eresult);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2706,10 +2716,10 @@ isc__nm_readcb(isc_nmsocket_t *sock, isc__nm_uvreq_t *uvreq,
|
||||
|
||||
isc__nm_async_readcb(NULL, (isc__netievent_t *)&ievent);
|
||||
} else {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_readcb_t *ievent = isc__nm_get_netievent_readcb(
|
||||
sock->mgr, sock, uvreq, eresult);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
worker, sock, uvreq, eresult);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2751,10 +2761,10 @@ isc__nm_sendcb(isc_nmsocket_t *sock, isc__nm_uvreq_t *uvreq,
|
||||
return;
|
||||
}
|
||||
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_sendcb_t *ievent =
|
||||
isc__nm_get_netievent_sendcb(sock->mgr, sock, uvreq, eresult);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_sendcb(worker, sock, uvreq, eresult);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -3390,6 +3400,7 @@ isc__nm_after_work_cb(uv_work_t *req, int status) {
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
isc__nm_work_t *work = uv_req_get_data((uv_req_t *)req);
|
||||
isc_nm_t *netmgr = work->netmgr;
|
||||
isc__networker_t *worker = &netmgr->workers[isc_nm_tid()];
|
||||
|
||||
if (status != 0) {
|
||||
result = isc__nm_uverr2result(status);
|
||||
@@ -3397,7 +3408,7 @@ isc__nm_after_work_cb(uv_work_t *req, int status) {
|
||||
|
||||
work->after_cb(work->data, result);
|
||||
|
||||
isc_mem_put(netmgr->mctx, work, sizeof(*work));
|
||||
isc_mem_put(worker->mctx, work, sizeof(*work));
|
||||
|
||||
isc_nm_detach(&netmgr);
|
||||
}
|
||||
@@ -3414,7 +3425,7 @@ isc_nm_work_offload(isc_nm_t *netmgr, isc_nm_workcb_t work_cb,
|
||||
|
||||
worker = &netmgr->workers[isc_nm_tid()];
|
||||
|
||||
work = isc_mem_get(netmgr->mctx, sizeof(*work));
|
||||
work = isc_mem_get(worker->mctx, sizeof(*work));
|
||||
*work = (isc__nm_work_t){
|
||||
.cb = work_cb,
|
||||
.after_cb = after_work_cb,
|
||||
@@ -3568,6 +3579,13 @@ isc_nm_getnworkers(const isc_nm_t *netmgr) {
|
||||
return (netmgr->nworkers);
|
||||
}
|
||||
|
||||
isc_mem_t *
|
||||
isc_nm_getmctx(const isc_nm_t *netmgr, uint32_t tid) {
|
||||
REQUIRE(VALID_NM(netmgr));
|
||||
|
||||
return (netmgr->workers[tid].mctx);
|
||||
}
|
||||
|
||||
#ifdef NETMGR_TRACE
|
||||
/*
|
||||
* Dump all active sockets in netmgr. We output to stderr
|
||||
|
||||
+36
-34
@@ -338,19 +338,21 @@ isc_nm_tcpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
|
||||
(void)isc__nm_socket_min_mtu(sock->fd, sa_family);
|
||||
(void)isc__nm_socket_tcp_maxseg(sock->fd, NM_MAXSEG);
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpconnect(mgr, sock, req);
|
||||
isc__networker_t *worker = NULL;
|
||||
|
||||
if (isc__nm_in_netthread()) {
|
||||
atomic_store(&sock->active, true);
|
||||
sock->tid = isc_nm_tid();
|
||||
isc__nm_async_tcpconnect(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_put_netievent_tcpconnect(mgr, ievent);
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpconnect(worker, sock, req);
|
||||
isc__nm_async_tcpconnect(worker, (isc__netievent_t *)ievent);
|
||||
isc__nm_put_netievent_tcpconnect(worker, ievent);
|
||||
} else {
|
||||
atomic_init(&sock->active, false);
|
||||
sock->tid = isc_random_uniform(mgr->nworkers);
|
||||
isc__nm_enqueue_ievent(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpconnect(worker, sock, req);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
LOCK(&sock->lock);
|
||||
while (sock->result == ISC_R_UNSET) {
|
||||
@@ -413,17 +415,17 @@ start_tcp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock,
|
||||
#endif
|
||||
REQUIRE(csock->fd >= 0);
|
||||
|
||||
ievent = isc__nm_get_netievent_tcplisten(mgr, csock);
|
||||
isc__nm_maybe_enqueue_ievent(&mgr->workers[tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &mgr->workers[tid];
|
||||
ievent = isc__nm_get_netievent_tcplisten(worker, csock);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
static void
|
||||
enqueue_stoplistening(isc_nmsocket_t *sock) {
|
||||
isc__netievent_tcpstop_t *ievent =
|
||||
isc__nm_get_netievent_tcpstop(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tcpstop_t *ievent = isc__nm_get_netievent_tcpstop(worker,
|
||||
sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
@@ -728,7 +730,8 @@ isc__nm_tcp_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
: atomic_load(&sock->mgr->idle));
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpstartread(sock->mgr, sock);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpstartread(worker, sock);
|
||||
|
||||
/*
|
||||
* This MUST be done asynchronously, no matter which thread we're
|
||||
@@ -736,8 +739,7 @@ isc__nm_tcp_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
* isc_nm_read() again; if we tried to do that synchronously
|
||||
* we'd clash in processbuffer() and grow the stack indefinitely.
|
||||
*/
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -778,10 +780,10 @@ isc__nm_tcp_pauseread(isc_nmhandle_t *handle) {
|
||||
return;
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tcppauseread(sock->mgr, sock);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcppauseread(worker, sock);
|
||||
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -826,10 +828,10 @@ isc__nm_tcp_resumeread(isc_nmhandle_t *handle) {
|
||||
return;
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpstartread(sock->mgr, sock);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpstartread(worker, sock);
|
||||
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -905,9 +907,9 @@ quota_accept_cb(isc_quota_t *quota, void *sock0) {
|
||||
/*
|
||||
* Create a tcpaccept event and pass it using the async channel.
|
||||
*/
|
||||
ievent = isc__nm_get_netievent_tcpaccept(sock->mgr, sock, quota);
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpaccept(worker, sock, quota);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1068,9 +1070,9 @@ isc__nm_tcp_send(isc_nmhandle_t *handle, const isc_region_t *region,
|
||||
: atomic_load(&sock->mgr->idle));
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpsend(sock->mgr, sock, uvreq);
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpsend(worker, sock, uvreq);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1308,11 +1310,11 @@ isc__nm_tcp_close(isc_nmsocket_t *sock) {
|
||||
/*
|
||||
* We need to create an event and pass it using async channel
|
||||
*/
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tcpclose_t *ievent =
|
||||
isc__nm_get_netievent_tcpclose(sock->mgr, sock);
|
||||
isc__nm_get_netievent_tcpclose(worker, sock);
|
||||
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1396,9 +1398,9 @@ isc__nm_tcp_cancelread(isc_nmhandle_t *handle) {
|
||||
REQUIRE(VALID_NMSOCK(sock));
|
||||
REQUIRE(sock->type == isc_nm_tcpsocket);
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpcancel(sock->mgr, sock, handle);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpcancel(worker, sock, handle);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+29
-27
@@ -300,19 +300,21 @@ isc_nm_tcpdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
|
||||
result = isc__nm_socket_connectiontimeout(sock->fd, 120 * 1000);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpdnsconnect(mgr, sock, req);
|
||||
isc__networker_t *worker = NULL;
|
||||
|
||||
if (isc__nm_in_netthread()) {
|
||||
atomic_store(&sock->active, true);
|
||||
sock->tid = isc_nm_tid();
|
||||
isc__nm_async_tcpdnsconnect(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_put_netievent_tcpdnsconnect(mgr, ievent);
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpdnsconnect(worker, sock, req);
|
||||
isc__nm_async_tcpdnsconnect(worker, (isc__netievent_t *)ievent);
|
||||
isc__nm_put_netievent_tcpdnsconnect(worker, ievent);
|
||||
} else {
|
||||
atomic_init(&sock->active, false);
|
||||
sock->tid = isc_random_uniform(mgr->nworkers);
|
||||
isc__nm_enqueue_ievent(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpdnsconnect(worker, sock, req);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
LOCK(&sock->lock);
|
||||
@@ -350,10 +352,10 @@ isc__nm_tcpdns_lb_socket(sa_family_t sa_family) {
|
||||
|
||||
static void
|
||||
enqueue_stoplistening(isc_nmsocket_t *sock) {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tcpdnsstop_t *ievent =
|
||||
isc__nm_get_netievent_tcpdnsstop(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_tcpdnsstop(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -386,9 +388,9 @@ start_tcpdns_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock,
|
||||
#endif
|
||||
REQUIRE(csock->fd >= 0);
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpdnslisten(mgr, csock);
|
||||
isc__nm_maybe_enqueue_ievent(&mgr->workers[tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &mgr->workers[tid];
|
||||
ievent = isc__nm_get_netievent_tcpdnslisten(worker, csock);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
isc_result_t
|
||||
isc_nm_listentcpdns(isc_nm_t *mgr, isc_sockaddr_t *iface,
|
||||
@@ -695,7 +697,8 @@ isc__nm_tcpdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
: atomic_load(&sock->mgr->idle));
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpdnsread(sock->mgr, sock);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpdnsread(worker, sock);
|
||||
|
||||
/*
|
||||
* This MUST be done asynchronously, no matter which thread we're
|
||||
@@ -703,8 +706,7 @@ isc__nm_tcpdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
* isc_nm_read() again; if we tried to do that synchronously
|
||||
* we'd clash in processbuffer() and grow the stack indefinitely.
|
||||
*/
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -902,10 +904,10 @@ quota_accept_cb(isc_quota_t *quota, void *sock0) {
|
||||
* Create a tcpdnsaccept event and pass it using the async channel.
|
||||
*/
|
||||
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tcpdnsaccept_t *ievent =
|
||||
isc__nm_get_netievent_tcpdnsaccept(sock->mgr, sock, quota);
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_tcpdnsaccept(worker, sock, quota);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1093,9 +1095,9 @@ isc__nm_tcpdns_send(isc_nmhandle_t *handle, isc_region_t *region,
|
||||
: atomic_load(&sock->mgr->idle));
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpdnssend(sock->mgr, sock, uvreq);
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpdnssend(worker, sock, uvreq);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1357,11 +1359,11 @@ isc__nm_tcpdns_close(isc_nmsocket_t *sock) {
|
||||
/*
|
||||
* We need to create an event and pass it using async channel
|
||||
*/
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tcpdnsclose_t *ievent =
|
||||
isc__nm_get_netievent_tcpdnsclose(sock->mgr, sock);
|
||||
isc__nm_get_netievent_tcpdnsclose(worker, sock);
|
||||
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1446,9 +1448,9 @@ isc__nm_tcpdns_cancelread(isc_nmhandle_t *handle) {
|
||||
REQUIRE(VALID_NMSOCK(sock));
|
||||
REQUIRE(sock->type == isc_nm_tcpdnssocket);
|
||||
|
||||
ievent = isc__nm_get_netievent_tcpdnscancel(sock->mgr, sock, handle);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tcpdnscancel(worker, sock, handle);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+42
-36
@@ -354,17 +354,20 @@ isc_nm_tlsdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
|
||||
result = isc__nm_socket_connectiontimeout(sock->fd, 120 * 1000);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
|
||||
ievent = isc__nm_get_netievent_tlsdnsconnect(mgr, sock, req);
|
||||
isc__networker_t *worker = NULL;
|
||||
|
||||
if (isc__nm_in_netthread()) {
|
||||
atomic_store(&sock->active, true);
|
||||
sock->tid = isc_nm_tid();
|
||||
isc__nm_async_tlsdnsconnect(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_put_netievent_tlsdnsconnect(mgr, ievent);
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlsdnsconnect(worker, sock, req);
|
||||
isc__nm_async_tlsdnsconnect(worker, (isc__netievent_t *)ievent);
|
||||
isc__nm_put_netievent_tlsdnsconnect(worker, ievent);
|
||||
} else {
|
||||
atomic_init(&sock->active, false);
|
||||
sock->tid = isc_random_uniform(mgr->nworkers);
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlsdnsconnect(worker, sock, req);
|
||||
isc__nm_enqueue_ievent(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
}
|
||||
@@ -446,17 +449,17 @@ start_tlsdns_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock,
|
||||
#endif
|
||||
REQUIRE(csock->fd >= 0);
|
||||
|
||||
ievent = isc__nm_get_netievent_tlsdnslisten(mgr, csock);
|
||||
isc__nm_maybe_enqueue_ievent(&mgr->workers[tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &mgr->workers[tid];
|
||||
ievent = isc__nm_get_netievent_tlsdnslisten(worker, csock);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
static void
|
||||
enqueue_stoplistening(isc_nmsocket_t *sock) {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tlsdnsstop_t *ievent =
|
||||
isc__nm_get_netievent_tlsdnsstop(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_tlsdnsstop(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
@@ -700,10 +703,10 @@ static void
|
||||
tls_shutdown(isc_nmsocket_t *sock) {
|
||||
REQUIRE(VALID_NMSOCK(sock));
|
||||
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tlsdnsshutdown_t *ievent =
|
||||
isc__nm_get_netievent_tlsdnsshutdown(sock->mgr, sock);
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_tlsdnsshutdown(worker, sock);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -849,7 +852,8 @@ isc__nm_tlsdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
: atomic_load(&sock->mgr->idle));
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tlsdnsread(sock->mgr, sock);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlsdnsread(worker, sock);
|
||||
|
||||
/*
|
||||
* This MUST be done asynchronously, no matter which thread
|
||||
@@ -858,8 +862,7 @@ isc__nm_tlsdns_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
* we'd clash in processbuffer() and grow the stack
|
||||
* indefinitely.
|
||||
*/
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1151,7 +1154,9 @@ free_senddata(isc_nmsocket_t *sock) {
|
||||
REQUIRE(sock->tls.senddata.base != NULL);
|
||||
REQUIRE(sock->tls.senddata.length > 0);
|
||||
|
||||
isc_mem_put(sock->mgr->mctx, sock->tls.senddata.base,
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
|
||||
isc_mem_put(worker->mctx, sock->tls.senddata.base,
|
||||
sock->tls.senddata.length);
|
||||
sock->tls.senddata.base = NULL;
|
||||
sock->tls.senddata.length = 0;
|
||||
@@ -1186,6 +1191,7 @@ static isc_result_t
|
||||
tls_cycle_output(isc_nmsocket_t *sock) {
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
int pending;
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
|
||||
while ((pending = BIO_pending(sock->tls.app_rbio)) > 0) {
|
||||
isc__nm_uvreq_t *req = NULL;
|
||||
@@ -1202,7 +1208,7 @@ tls_cycle_output(isc_nmsocket_t *sock) {
|
||||
pending = (int)ISC_NETMGR_TCP_RECVBUF_SIZE;
|
||||
}
|
||||
|
||||
sock->tls.senddata.base = isc_mem_get(sock->mgr->mctx, pending);
|
||||
sock->tls.senddata.base = isc_mem_get(worker->mctx, pending);
|
||||
sock->tls.senddata.length = pending;
|
||||
|
||||
/* It's a bit misnomer here, but it does the right thing */
|
||||
@@ -1323,9 +1329,9 @@ async_tlsdns_cycle(isc_nmsocket_t *sock) {
|
||||
return;
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tlsdnscycle(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlsdnscycle(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1420,10 +1426,10 @@ quota_accept_cb(isc_quota_t *quota, void *sock0) {
|
||||
* channel.
|
||||
*/
|
||||
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tlsdnsaccept_t *ievent =
|
||||
isc__nm_get_netievent_tlsdnsaccept(sock->mgr, sock, quota);
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_tlsdnsaccept(worker, sock, quota);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1644,9 +1650,9 @@ isc__nm_tlsdns_send(isc_nmhandle_t *handle, isc_region_t *region,
|
||||
: atomic_load(&sock->mgr->idle));
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tlsdnssend(sock->mgr, sock, uvreq);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlsdnssend(worker, sock, uvreq);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1675,10 +1681,10 @@ isc__nm_async_tlsdnssend(isc__networker_t *worker, isc__netievent_t *ev0) {
|
||||
|
||||
static void
|
||||
tlsdns_send_enqueue(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tlsdnssend_t *ievent =
|
||||
isc__nm_get_netievent_tlsdnssend(sock->mgr, sock, req);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_tlsdnssend(worker, sock, req);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
@@ -1928,11 +1934,11 @@ isc__nm_tlsdns_close(isc_nmsocket_t *sock) {
|
||||
* We need to create an event and pass it using async
|
||||
* channel
|
||||
*/
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tlsdnsclose_t *ievent =
|
||||
isc__nm_get_netievent_tlsdnsclose(sock->mgr, sock);
|
||||
isc__nm_get_netievent_tlsdnsclose(worker, sock);
|
||||
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2038,9 +2044,9 @@ isc__nm_tlsdns_cancelread(isc_nmhandle_t *handle) {
|
||||
REQUIRE(VALID_NMSOCK(sock));
|
||||
REQUIRE(sock->type == isc_nm_tlsdnssocket);
|
||||
|
||||
ievent = isc__nm_get_netievent_tlsdnscancel(sock->mgr, sock, handle);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlsdnscancel(worker, sock, handle);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+25
-22
@@ -125,16 +125,18 @@ tls_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
||||
}
|
||||
}
|
||||
|
||||
/* We are tying to avoid a memory allocation for small write
|
||||
isc__networker_t *worker =
|
||||
&handle->sock->mgr->workers[handle->sock->tid];
|
||||
/* We are trying to avoid a memory allocation for small write
|
||||
* requests. See the mirroring code in the tls_send_outgoing()
|
||||
* function. */
|
||||
if (send_req->data.length > sizeof(send_req->smallbuf)) {
|
||||
isc_mem_put(handle->sock->mgr->mctx, send_req->data.base,
|
||||
isc_mem_put(worker->mctx, send_req->data.base,
|
||||
send_req->data.length);
|
||||
} else {
|
||||
INSIST(&send_req->smallbuf[0] == send_req->data.base);
|
||||
}
|
||||
isc_mem_put(handle->sock->mgr->mctx, send_req, sizeof(*send_req));
|
||||
isc_mem_put(worker->mctx, send_req, sizeof(*send_req));
|
||||
tlssock->tlsstream.nsending--;
|
||||
|
||||
if (finish && eresult == ISC_R_SUCCESS) {
|
||||
@@ -206,10 +208,10 @@ tls_failed_read_cb(isc_nmsocket_t *sock, const isc_result_t result) {
|
||||
|
||||
static void
|
||||
async_tls_do_bio(isc_nmsocket_t *sock) {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tlsdobio_t *ievent =
|
||||
isc__nm_get_netievent_tlsdobio(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_tlsdobio(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -244,13 +246,15 @@ tls_send_outgoing(isc_nmsocket_t *sock, bool finish, isc_nmhandle_t *tlshandle,
|
||||
pending = TLS_BUF_SIZE;
|
||||
}
|
||||
|
||||
send_req = isc_mem_get(sock->mgr->mctx, sizeof(*send_req));
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
|
||||
send_req = isc_mem_get(worker->mctx, sizeof(*send_req));
|
||||
*send_req = (isc_nmsocket_tls_send_req_t){ .finish = finish,
|
||||
.data.length = pending };
|
||||
|
||||
/* Let's try to avoid a memory allocation for small write requests */
|
||||
if ((size_t)pending > sizeof(send_req->smallbuf)) {
|
||||
send_req->data.base = isc_mem_get(sock->mgr->mctx, pending);
|
||||
send_req->data.base = isc_mem_get(worker->mctx, pending);
|
||||
} else {
|
||||
send_req->data.base = &send_req->smallbuf[0];
|
||||
}
|
||||
@@ -726,9 +730,9 @@ isc__nm_tls_send(isc_nmhandle_t *handle, const isc_region_t *region,
|
||||
/*
|
||||
* We need to create an event and pass it using async channel
|
||||
*/
|
||||
ievent = isc__nm_get_netievent_tlssend(sock->mgr, sock, uvreq);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlssend(worker, sock, uvreq);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -765,9 +769,9 @@ isc__nm_tls_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
sock->recv_cb = cb;
|
||||
sock->recv_cbarg = cbarg;
|
||||
|
||||
ievent = isc__nm_get_netievent_tlsstartread(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlsstartread(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -832,9 +836,9 @@ isc__nm_tls_close(isc_nmsocket_t *sock) {
|
||||
return;
|
||||
}
|
||||
|
||||
ievent = isc__nm_get_netievent_tlsclose(sock->mgr, sock);
|
||||
isc__nm_maybe_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_tlsclose(worker, sock);
|
||||
isc__nm_maybe_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -963,7 +967,6 @@ tls_cancelread(isc_nmsocket_t *sock) {
|
||||
void
|
||||
isc__nm_tls_cancelread(isc_nmhandle_t *handle) {
|
||||
isc_nmsocket_t *sock = NULL;
|
||||
isc__netievent_tlscancel_t *ievent = NULL;
|
||||
|
||||
REQUIRE(VALID_NMHANDLE(handle));
|
||||
|
||||
@@ -974,10 +977,10 @@ isc__nm_tls_cancelread(isc_nmhandle_t *handle) {
|
||||
if (sock->tid == isc_nm_tid()) {
|
||||
tls_cancelread(sock);
|
||||
} else {
|
||||
ievent = isc__nm_get_netievent_tlscancel(sock->mgr, sock,
|
||||
handle);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_tlscancel_t *ievent =
|
||||
isc__nm_get_netievent_tlscancel(worker, sock, handle);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
-30
@@ -132,17 +132,17 @@ start_udp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock,
|
||||
#endif
|
||||
REQUIRE(csock->fd >= 0);
|
||||
|
||||
ievent = isc__nm_get_netievent_udplisten(mgr, csock);
|
||||
ievent = isc__nm_get_netievent_udplisten(&mgr->workers[tid], csock);
|
||||
isc__nm_maybe_enqueue_ievent(&mgr->workers[tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
static void
|
||||
enqueue_stoplistening(isc_nmsocket_t *sock) {
|
||||
isc__netievent_udpstop_t *ievent =
|
||||
isc__nm_get_netievent_udpstop(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_udpstop_t *ievent = isc__nm_get_netievent_udpstop(worker,
|
||||
sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
@@ -377,19 +377,18 @@ isc_nm_routeconnect(isc_nm_t *mgr, isc_nm_cb_t cb, void *cbarg,
|
||||
return (result);
|
||||
}
|
||||
|
||||
event = isc__nm_get_netievent_routeconnect(mgr, sock, req);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
event = isc__nm_get_netievent_routeconnect(worker, sock, req);
|
||||
|
||||
if (isc__nm_in_netthread()) {
|
||||
atomic_store(&sock->active, true);
|
||||
sock->tid = isc_nm_tid();
|
||||
isc__nm_async_routeconnect(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)event);
|
||||
isc__nm_put_netievent_routeconnect(mgr, event);
|
||||
isc__nm_async_routeconnect(worker, (isc__netievent_t *)event);
|
||||
isc__nm_put_netievent_routeconnect(worker, event);
|
||||
} else {
|
||||
atomic_init(&sock->active, false);
|
||||
sock->tid = 0;
|
||||
isc__nm_enqueue_ievent(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)event);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)event);
|
||||
}
|
||||
LOCK(&sock->lock);
|
||||
while (sock->result == ISC_R_UNSET) {
|
||||
@@ -743,13 +742,13 @@ send:
|
||||
|
||||
isc__nm_async_udpsend(NULL, (isc__netievent_t *)&ievent);
|
||||
} else {
|
||||
isc__networker_t *worker = &sock->mgr->workers[rsock->tid];
|
||||
isc__netievent_udpsend_t *ievent =
|
||||
isc__nm_get_netievent_udpsend(sock->mgr, rsock);
|
||||
isc__nm_get_netievent_udpsend(worker, rsock);
|
||||
ievent->peer = *peer;
|
||||
ievent->req = uvreq;
|
||||
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[rsock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1020,19 +1019,21 @@ isc_nm_udpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
|
||||
|
||||
(void)isc__nm_socket_min_mtu(sock->fd, sa_family);
|
||||
|
||||
event = isc__nm_get_netievent_udpconnect(mgr, sock, req);
|
||||
isc__networker_t *worker = NULL;
|
||||
|
||||
if (isc__nm_in_netthread()) {
|
||||
atomic_store(&sock->active, true);
|
||||
sock->tid = isc_nm_tid();
|
||||
isc__nm_async_udpconnect(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)event);
|
||||
isc__nm_put_netievent_udpconnect(mgr, event);
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
event = isc__nm_get_netievent_udpconnect(worker, sock, req);
|
||||
isc__nm_async_udpconnect(worker, (isc__netievent_t *)event);
|
||||
isc__nm_put_netievent_udpconnect(worker, event);
|
||||
} else {
|
||||
atomic_init(&sock->active, false);
|
||||
sock->tid = isc_random_uniform(mgr->nworkers);
|
||||
isc__nm_enqueue_ievent(&mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)event);
|
||||
worker = &sock->mgr->workers[sock->tid];
|
||||
event = isc__nm_get_netievent_udpconnect(worker, sock, req);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)event);
|
||||
}
|
||||
LOCK(&sock->lock);
|
||||
while (sock->result == ISC_R_UNSET) {
|
||||
@@ -1157,10 +1158,10 @@ isc__nm_udp_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
|
||||
isc__netievent_udpread_t ievent = { .sock = sock };
|
||||
isc__nm_async_udpread(NULL, (isc__netievent_t *)&ievent);
|
||||
} else {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_udpread_t *ievent =
|
||||
isc__nm_get_netievent_udpread(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_udpread(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1310,10 +1311,10 @@ isc__nm_udp_close(isc_nmsocket_t *sock) {
|
||||
if (sock->tid == isc_nm_tid()) {
|
||||
udp_close_direct(sock);
|
||||
} else {
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
isc__netievent_udpclose_t *ievent =
|
||||
isc__nm_get_netievent_udpclose(sock->mgr, sock);
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__nm_get_netievent_udpclose(worker, sock);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1373,10 +1374,9 @@ isc__nm_udp_cancelread(isc_nmhandle_t *handle) {
|
||||
REQUIRE(VALID_NMSOCK(sock));
|
||||
REQUIRE(sock->type == isc_nm_udpsocket);
|
||||
|
||||
ievent = isc__nm_get_netievent_udpcancel(sock->mgr, sock, handle);
|
||||
|
||||
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
|
||||
(isc__netievent_t *)ievent);
|
||||
isc__networker_t *worker = &sock->mgr->workers[sock->tid];
|
||||
ievent = isc__nm_get_netievent_udpcancel(worker, sock, handle);
|
||||
isc__nm_enqueue_ievent(worker, (isc__netievent_t *)ievent);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
-163
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/pool.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
/***
|
||||
*** Types.
|
||||
***/
|
||||
|
||||
struct isc_pool {
|
||||
isc_mem_t *mctx;
|
||||
unsigned int count;
|
||||
isc_pooldeallocator_t free;
|
||||
isc_poolinitializer_t init;
|
||||
void *initarg;
|
||||
void **pool;
|
||||
};
|
||||
|
||||
/***
|
||||
*** Functions.
|
||||
***/
|
||||
|
||||
static isc_result_t
|
||||
alloc_pool(isc_mem_t *mctx, unsigned int count, isc_pool_t **poolp) {
|
||||
isc_pool_t *pool;
|
||||
|
||||
pool = isc_mem_get(mctx, sizeof(*pool));
|
||||
pool->count = count;
|
||||
pool->free = NULL;
|
||||
pool->init = NULL;
|
||||
pool->initarg = NULL;
|
||||
pool->mctx = NULL;
|
||||
isc_mem_attach(mctx, &pool->mctx);
|
||||
pool->pool = isc_mem_get(mctx, count * sizeof(void *));
|
||||
memset(pool->pool, 0, count * sizeof(void *));
|
||||
|
||||
*poolp = pool;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_pool_create(isc_mem_t *mctx, unsigned int count,
|
||||
isc_pooldeallocator_t release, isc_poolinitializer_t init,
|
||||
void *initarg, isc_pool_t **poolp) {
|
||||
isc_pool_t *pool = NULL;
|
||||
isc_result_t result;
|
||||
unsigned int i;
|
||||
|
||||
INSIST(count > 0);
|
||||
|
||||
/* Allocate the pool structure */
|
||||
result = alloc_pool(mctx, count, &pool);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
pool->free = release;
|
||||
pool->init = init;
|
||||
pool->initarg = initarg;
|
||||
|
||||
/* Populate the pool */
|
||||
for (i = 0; i < count; i++) {
|
||||
result = init(&pool->pool[i], initarg);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_pool_destroy(&pool);
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
*poolp = pool;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void *
|
||||
isc_pool_get(isc_pool_t *pool) {
|
||||
return (pool->pool[isc_random_uniform(pool->count)]);
|
||||
}
|
||||
|
||||
int
|
||||
isc_pool_count(isc_pool_t *pool) {
|
||||
REQUIRE(pool != NULL);
|
||||
return (pool->count);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_pool_expand(isc_pool_t **sourcep, unsigned int count,
|
||||
isc_pool_t **targetp) {
|
||||
isc_result_t result;
|
||||
isc_pool_t *pool;
|
||||
|
||||
REQUIRE(sourcep != NULL && *sourcep != NULL);
|
||||
REQUIRE(targetp != NULL && *targetp == NULL);
|
||||
|
||||
pool = *sourcep;
|
||||
*sourcep = NULL;
|
||||
if (count > pool->count) {
|
||||
isc_pool_t *newpool = NULL;
|
||||
unsigned int i;
|
||||
|
||||
/* Allocate a new pool structure */
|
||||
result = alloc_pool(pool->mctx, count, &newpool);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
newpool->free = pool->free;
|
||||
newpool->init = pool->init;
|
||||
newpool->initarg = pool->initarg;
|
||||
|
||||
/* Populate the new entries */
|
||||
for (i = pool->count; i < count; i++) {
|
||||
result = newpool->init(&newpool->pool[i],
|
||||
newpool->initarg);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_pool_destroy(&newpool);
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy over the objects from the old pool */
|
||||
for (i = 0; i < pool->count; i++) {
|
||||
newpool->pool[i] = pool->pool[i];
|
||||
pool->pool[i] = NULL;
|
||||
}
|
||||
|
||||
isc_pool_destroy(&pool);
|
||||
pool = newpool;
|
||||
}
|
||||
|
||||
*targetp = pool;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
isc_pool_destroy(isc_pool_t **poolp) {
|
||||
unsigned int i;
|
||||
isc_pool_t *pool = *poolp;
|
||||
*poolp = NULL;
|
||||
for (i = 0; i < pool->count; i++) {
|
||||
if (pool->free != NULL && pool->pool[i] != NULL) {
|
||||
pool->free(&pool->pool[i]);
|
||||
}
|
||||
}
|
||||
isc_mem_put(pool->mctx, pool->pool, pool->count * sizeof(void *));
|
||||
isc_mem_putanddetach(&pool->mctx, pool, sizeof(*pool));
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/taskpool.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
/***
|
||||
*** Types.
|
||||
***/
|
||||
|
||||
struct isc_taskpool {
|
||||
isc_mem_t *mctx;
|
||||
isc_taskmgr_t *tmgr;
|
||||
unsigned int ntasks;
|
||||
unsigned int quantum;
|
||||
isc_task_t **tasks;
|
||||
};
|
||||
|
||||
/***
|
||||
*** Functions.
|
||||
***/
|
||||
|
||||
static void
|
||||
alloc_pool(isc_taskmgr_t *tmgr, isc_mem_t *mctx, unsigned int ntasks,
|
||||
unsigned int quantum, isc_taskpool_t **poolp) {
|
||||
isc_taskpool_t *pool;
|
||||
unsigned int i;
|
||||
|
||||
pool = isc_mem_get(mctx, sizeof(*pool));
|
||||
|
||||
pool->mctx = NULL;
|
||||
isc_mem_attach(mctx, &pool->mctx);
|
||||
pool->ntasks = ntasks;
|
||||
pool->quantum = quantum;
|
||||
pool->tmgr = tmgr;
|
||||
pool->tasks = isc_mem_get(mctx, ntasks * sizeof(isc_task_t *));
|
||||
for (i = 0; i < ntasks; i++) {
|
||||
pool->tasks[i] = NULL;
|
||||
}
|
||||
|
||||
*poolp = pool;
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_taskpool_create(isc_taskmgr_t *tmgr, isc_mem_t *mctx, unsigned int ntasks,
|
||||
unsigned int quantum, bool priv, isc_taskpool_t **poolp) {
|
||||
unsigned int i;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
|
||||
INSIST(ntasks > 0);
|
||||
|
||||
/* Allocate the pool structure */
|
||||
alloc_pool(tmgr, mctx, ntasks, quantum, &pool);
|
||||
|
||||
/* Create the tasks */
|
||||
for (i = 0; i < ntasks; i++) {
|
||||
isc_result_t result = isc_task_create_bound(tmgr, quantum,
|
||||
&pool->tasks[i], i);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_taskpool_destroy(&pool);
|
||||
return (result);
|
||||
}
|
||||
isc_task_setprivilege(pool->tasks[i], priv);
|
||||
isc_task_setname(pool->tasks[i], "taskpool", NULL);
|
||||
}
|
||||
|
||||
*poolp = pool;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
isc_taskpool_gettask(isc_taskpool_t *pool, isc_task_t **targetp) {
|
||||
isc_task_attach(pool->tasks[isc_random_uniform(pool->ntasks)], targetp);
|
||||
}
|
||||
|
||||
int
|
||||
isc_taskpool_size(isc_taskpool_t *pool) {
|
||||
REQUIRE(pool != NULL);
|
||||
return (pool->ntasks);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_taskpool_expand(isc_taskpool_t **sourcep, unsigned int size, bool priv,
|
||||
isc_taskpool_t **targetp) {
|
||||
isc_taskpool_t *pool;
|
||||
|
||||
REQUIRE(sourcep != NULL && *sourcep != NULL);
|
||||
REQUIRE(targetp != NULL && *targetp == NULL);
|
||||
|
||||
pool = *sourcep;
|
||||
*sourcep = NULL;
|
||||
if (size > pool->ntasks) {
|
||||
isc_taskpool_t *newpool = NULL;
|
||||
unsigned int i;
|
||||
|
||||
/* Allocate a new pool structure */
|
||||
alloc_pool(pool->tmgr, pool->mctx, size, pool->quantum,
|
||||
&newpool);
|
||||
|
||||
/* Copy over the tasks from the old pool */
|
||||
for (i = 0; i < pool->ntasks; i++) {
|
||||
newpool->tasks[i] = pool->tasks[i];
|
||||
pool->tasks[i] = NULL;
|
||||
}
|
||||
|
||||
/* Create new tasks */
|
||||
for (i = pool->ntasks; i < size; i++) {
|
||||
isc_result_t result =
|
||||
isc_task_create_bound(pool->tmgr, pool->quantum,
|
||||
&newpool->tasks[i], i);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
*sourcep = pool;
|
||||
isc_taskpool_destroy(&newpool);
|
||||
return (result);
|
||||
}
|
||||
isc_task_setprivilege(newpool->tasks[i], priv);
|
||||
isc_task_setname(newpool->tasks[i], "taskpool", NULL);
|
||||
}
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
pool = newpool;
|
||||
}
|
||||
|
||||
*targetp = pool;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
isc_taskpool_destroy(isc_taskpool_t **poolp) {
|
||||
unsigned int i;
|
||||
isc_taskpool_t *pool = *poolp;
|
||||
*poolp = NULL;
|
||||
for (i = 0; i < pool->ntasks; i++) {
|
||||
if (pool->tasks[i] != NULL) {
|
||||
isc_task_detach(&pool->tasks[i]);
|
||||
}
|
||||
}
|
||||
isc_mem_put(pool->mctx, pool->tasks,
|
||||
pool->ntasks * sizeof(isc_task_t *));
|
||||
isc_mem_putanddetach(&pool->mctx, pool, sizeof(*pool));
|
||||
}
|
||||
@@ -30,7 +30,6 @@ check_PROGRAMS = \
|
||||
netaddr_test \
|
||||
netmgr_test \
|
||||
parse_test \
|
||||
pool_test \
|
||||
quota_test \
|
||||
radix_test \
|
||||
random_test \
|
||||
@@ -42,7 +41,6 @@ check_PROGRAMS = \
|
||||
stats_test \
|
||||
symtab_test \
|
||||
task_test \
|
||||
taskpool_test \
|
||||
time_test \
|
||||
timer_test
|
||||
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <sched.h> /* IWYU pragma: keep */
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/pool.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
poolinit(void **target, void *arg) {
|
||||
isc_result_t result;
|
||||
|
||||
isc_taskmgr_t *mgr = (isc_taskmgr_t *)arg;
|
||||
isc_task_t *task = NULL;
|
||||
result = isc_task_create(mgr, 0, &task);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
*target = (void *)task;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
poolfree(void **target) {
|
||||
isc_task_t *task = *(isc_task_t **)target;
|
||||
isc_task_destroy(&task);
|
||||
*target = NULL;
|
||||
}
|
||||
|
||||
/* Create a pool */
|
||||
static void
|
||||
create_pool(void **state) {
|
||||
isc_result_t result;
|
||||
isc_pool_t *pool = NULL;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_pool_create(test_mctx, 8, poolfree, poolinit, taskmgr,
|
||||
&pool);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool), 8);
|
||||
|
||||
isc_pool_destroy(&pool);
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
/* Resize a pool */
|
||||
static void
|
||||
expand_pool(void **state) {
|
||||
isc_result_t result;
|
||||
isc_pool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_pool_create(test_mctx, 10, poolfree, poolinit, taskmgr,
|
||||
&pool1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool1), 10);
|
||||
|
||||
/* resizing to a smaller size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_pool_expand(&pool1, 5, &pool2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool2), 10);
|
||||
assert_ptr_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to the same size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_pool_expand(&pool1, 10, &pool2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool2), 10);
|
||||
assert_ptr_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to larger size should make a new pool */
|
||||
hold = pool1;
|
||||
result = isc_pool_expand(&pool1, 20, &pool2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool2), 20);
|
||||
assert_ptr_not_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
|
||||
isc_pool_destroy(&pool2);
|
||||
assert_null(pool2);
|
||||
}
|
||||
|
||||
/* Get objects */
|
||||
static void
|
||||
get_objects(void **state) {
|
||||
isc_result_t result;
|
||||
isc_pool_t *pool = NULL;
|
||||
void *item;
|
||||
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_pool_create(test_mctx, 2, poolfree, poolinit, taskmgr,
|
||||
&pool);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_pool_count(pool), 2);
|
||||
|
||||
item = isc_pool_get(pool);
|
||||
assert_non_null(item);
|
||||
isc_task_attach((isc_task_t *)item, &task1);
|
||||
|
||||
item = isc_pool_get(pool);
|
||||
assert_non_null(item);
|
||||
isc_task_attach((isc_task_t *)item, &task2);
|
||||
|
||||
item = isc_pool_get(pool);
|
||||
assert_non_null(item);
|
||||
isc_task_attach((isc_task_t *)item, &task3);
|
||||
|
||||
isc_task_detach(&task1);
|
||||
isc_task_detach(&task2);
|
||||
isc_task_detach(&task3);
|
||||
|
||||
isc_pool_destroy(&pool);
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(create_pool, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(expand_pool, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(get_objects, _setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (SKIPPED_TEST_EXIT_CODE);
|
||||
}
|
||||
|
||||
#endif /* if HAVE_CMOCKA */
|
||||
@@ -1,204 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <sched.h> /* IWYU pragma: keep */
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/task.h>
|
||||
#include <isc/taskpool.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include "isctest.h"
|
||||
|
||||
#define TASK_MAGIC ISC_MAGIC('T', 'A', 'S', 'K')
|
||||
#define VALID_TASK(t) ISC_MAGIC_VALID(t, TASK_MAGIC)
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_test_begin(NULL, true, 0);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
isc_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Create a taskpool */
|
||||
static void
|
||||
create_pool(void **state) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, test_mctx, 8, 2, false, &pool);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool), 8);
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
/* Resize a taskpool */
|
||||
static void
|
||||
expand_pool(void **state) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool1 = NULL, *pool2 = NULL, *hold = NULL;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, test_mctx, 10, 2, false, &pool1);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool1), 10);
|
||||
|
||||
/* resizing to a smaller size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 5, false, &pool2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool2), 10);
|
||||
assert_ptr_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to the same size should have no effect */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 10, false, &pool2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool2), 10);
|
||||
assert_ptr_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
pool1 = pool2;
|
||||
pool2 = NULL;
|
||||
|
||||
/* resizing to larger size should make a new pool */
|
||||
hold = pool1;
|
||||
result = isc_taskpool_expand(&pool1, 20, false, &pool2);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool2), 20);
|
||||
assert_ptr_not_equal(pool2, hold);
|
||||
assert_null(pool1);
|
||||
|
||||
isc_taskpool_destroy(&pool2);
|
||||
assert_null(pool2);
|
||||
}
|
||||
|
||||
/* Get tasks */
|
||||
static void
|
||||
get_tasks(void **state) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, test_mctx, 2, 2, false, &pool);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool), 2);
|
||||
|
||||
/* two tasks in pool; make sure we can access them more than twice */
|
||||
isc_taskpool_gettask(pool, &task1);
|
||||
assert_true(VALID_TASK(task1));
|
||||
|
||||
isc_taskpool_gettask(pool, &task2);
|
||||
assert_true(VALID_TASK(task2));
|
||||
|
||||
isc_taskpool_gettask(pool, &task3);
|
||||
assert_true(VALID_TASK(task3));
|
||||
|
||||
isc_task_destroy(&task1);
|
||||
isc_task_destroy(&task2);
|
||||
isc_task_destroy(&task3);
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
/* Set privileges */
|
||||
static void
|
||||
set_privilege(void **state) {
|
||||
isc_result_t result;
|
||||
isc_taskpool_t *pool = NULL;
|
||||
isc_task_t *task1 = NULL, *task2 = NULL, *task3 = NULL;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = isc_taskpool_create(taskmgr, test_mctx, 2, 2, true, &pool);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(isc_taskpool_size(pool), 2);
|
||||
|
||||
isc_taskpool_gettask(pool, &task1);
|
||||
isc_taskpool_gettask(pool, &task2);
|
||||
isc_taskpool_gettask(pool, &task3);
|
||||
|
||||
assert_true(VALID_TASK(task1));
|
||||
assert_true(VALID_TASK(task2));
|
||||
assert_true(VALID_TASK(task3));
|
||||
|
||||
assert_true(isc_task_getprivilege(task1));
|
||||
assert_true(isc_task_getprivilege(task2));
|
||||
assert_true(isc_task_getprivilege(task3));
|
||||
|
||||
isc_task_destroy(&task1);
|
||||
isc_task_destroy(&task2);
|
||||
isc_task_destroy(&task3);
|
||||
|
||||
isc_taskpool_destroy(&pool);
|
||||
assert_null(pool);
|
||||
}
|
||||
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(create_pool, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(expand_pool, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(get_tasks, _setup, _teardown),
|
||||
cmocka_unit_test_setup_teardown(set_privilege, _setup,
|
||||
_teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (SKIPPED_TEST_EXIT_CODE);
|
||||
}
|
||||
|
||||
#endif /* if HAVE_CMOCKA */
|
||||
@@ -413,7 +413,7 @@ ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
|
||||
|
||||
zone = *zonep;
|
||||
if (zone == NULL) {
|
||||
CHECK(dns_zone_create(&zone, mctx));
|
||||
CHECK(dns_zone_create(&zone, mctx, 0));
|
||||
}
|
||||
|
||||
isc_buffer_constinit(&buffer, name, strlen(name));
|
||||
@@ -449,7 +449,7 @@ ns_test_setupzonemgr(void) {
|
||||
isc_result_t result;
|
||||
REQUIRE(zonemgr == NULL);
|
||||
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, NULL, &zonemgr);
|
||||
result = dns_zonemgr_create(mctx, taskmgr, timermgr, netmgr, &zonemgr);
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -458,11 +458,6 @@ ns_test_managezone(dns_zone_t *zone) {
|
||||
isc_result_t result;
|
||||
REQUIRE(zonemgr != NULL);
|
||||
|
||||
result = dns_zonemgr_setsize(zonemgr, 1);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
return (result);
|
||||
}
|
||||
|
||||
result = dns_zonemgr_managezone(zonemgr, zone);
|
||||
return (result);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <isc/serial.h>
|
||||
#include <isc/stats.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/taskpool.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/db.h>
|
||||
|
||||
Reference in New Issue
Block a user