From a011d4221175fa6255654b64dd8bf89ddc3ac2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 27 Apr 2021 00:07:43 +0200 Subject: [PATCH] Add new isc_managers API to simplify <*>mgr create/destroy Previously, netmgr, taskmgr, timermgr and socketmgr all had their own isc_<*>mgr_create() and isc_<*>mgr_destroy() functions. The new isc_managers_create() and isc_managers_destroy() fold all four into a single function and makes sure the objects are created and destroy in correct order. Especially now, when taskmgr runs on top of netmgr, the correct order is important and when the code was duplicated at many places it's easy to make mistake. The former isc_<*>mgr_create() and isc_<*>mgr_destroy() functions were made private and a single call to isc_managers_create() and isc_managers_destroy() is required at the program startup / shutdown. --- bin/delv/delv.c | 20 +---- bin/dig/dighost.c | 22 +---- bin/dnssec/dnssec-signzone.c | 12 +-- bin/named/controlconf.c | 8 +- bin/named/include/named/globals.h | 2 +- bin/named/main.c | 62 +++---------- bin/named/server.c | 13 +-- bin/named/statschannel.c | 2 +- bin/nsupdate/nsupdate.c | 26 ++---- bin/rndc/rndc.c | 13 +-- bin/tests/system/pipelined/pipequeries.c | 27 ++---- bin/tests/system/resolve.c | 40 ++------- bin/tests/system/tkey/keycreate.c | 39 ++++---- bin/tests/system/tkey/keydelete.c | 42 ++++----- bin/tests/test_client.c | 5 +- bin/tests/test_server.c | 5 +- bin/tools/mdig.c | 26 ++---- lib/dns/tests/dnstest.c | 20 +---- lib/isc/Makefile.am | 6 ++ lib/isc/hp.c | 3 + lib/isc/include/isc/hp.h | 6 +- lib/isc/include/isc/managers.h | 30 +++++++ lib/isc/include/isc/netmgr.h | 9 -- lib/isc/include/isc/socket.h | 66 +------------- lib/isc/include/isc/task.h | 75 +--------------- lib/isc/include/isc/timer.h | 54 +---------- lib/isc/managers.c | 109 +++++++++++++++++++++++ lib/isc/netmgr/netmgr.c | 16 ++-- lib/isc/netmgr_p.h | 29 ++++++ lib/isc/socket_p.h | 81 +++++++++++++++++ lib/isc/task.c | 10 +-- lib/isc/task_p.h | 86 ++++++++++++++++++ lib/isc/tests/Makefile.am | 2 +- lib/isc/tests/doh_test.c | 5 +- lib/isc/tests/isctest.c | 23 +---- lib/isc/tests/netmgr_test.c | 9 +- lib/isc/tests/socket_test.c | 2 +- lib/isc/tests/task_test.c | 15 ++-- lib/isc/timer.c | 12 +-- lib/isc/timer_p.h | 65 ++++++++++++++ lib/isc/unix/socket.c | 10 +-- lib/isc/unix/socket_p.h | 25 ------ lib/isc/win32/libisc.def.in | 11 +-- lib/isc/win32/libisc.vcxproj.filters.in | 6 ++ lib/isc/win32/libisc.vcxproj.in | 2 + lib/isc/win32/socket.c | 10 +-- lib/ns/tests/nstest.c | 39 ++------ util/copyrights | 7 +- 48 files changed, 591 insertions(+), 616 deletions(-) create mode 100644 lib/isc/include/isc/managers.h create mode 100644 lib/isc/managers.c create mode 100644 lib/isc/netmgr_p.h create mode 100644 lib/isc/socket_p.h create mode 100644 lib/isc/task_p.h create mode 100644 lib/isc/timer_p.h delete mode 100644 lib/isc/unix/socket_p.h diff --git a/bin/delv/delv.c b/bin/delv/delv.c index fc974853c4..c7eb8d6839 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -1761,10 +1762,8 @@ main(int argc, char *argv[]) { isc_mem_create(&mctx); CHECK(isc_appctx_create(mctx, &actx)); - netmgr = isc_nm_start(mctx, 1); - CHECK(isc_taskmgr_create(mctx, 0, netmgr, &taskmgr)); - CHECK(isc_socketmgr_create(mctx, &socketmgr)); - CHECK(isc_timermgr_create(mctx, &timermgr)); + isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr, + &socketmgr); parse_args(argc, argv); @@ -1867,18 +1866,7 @@ cleanup: if (client != NULL) { dns_client_destroy(&client); } - if (taskmgr != NULL) { - isc_taskmgr_destroy(&taskmgr); - } - if (netmgr != NULL) { - isc_nm_destroy(&netmgr); - } - if (timermgr != NULL) { - isc_timermgr_destroy(&timermgr); - } - if (socketmgr != NULL) { - isc_socketmgr_destroy(&socketmgr); - } + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); if (actx != NULL) { isc_appctx_destroy(&actx); } diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index a4a2ebdaf1..09926547b5 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -106,9 +107,9 @@ unsigned int timeout = 0; unsigned int extrabytes; isc_mem_t *mctx = NULL; isc_log_t *lctx = NULL; +isc_nm_t *netmgr = NULL; isc_taskmgr_t *taskmgr = NULL; isc_task_t *global_task = NULL; -isc_nm_t *netmgr = NULL; isc_sockaddr_t localaddr; isc_refcount_t sendcount = ATOMIC_VAR_INIT(0); isc_refcount_t recvcount = ATOMIC_VAR_INIT(0); @@ -1360,10 +1361,7 @@ setup_libs(void) { isc_log_setdebuglevel(lctx, 0); - netmgr = isc_nm_start(mctx, 1); - - result = isc_taskmgr_create(mctx, 0, netmgr, &taskmgr); - check_result(result, "isc_taskmgr_create"); + isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, NULL, NULL); result = isc_task_create(taskmgr, 0, &global_task); check_result(result, "isc_task_create"); @@ -4226,20 +4224,8 @@ destroy_libs(void) { debug("freeing task"); isc_task_detach(&global_task); } - /* - * The taskmgr_destroy() and isc_nm_destroy() calls block until - * all events are cleared. - */ - if (taskmgr != NULL) { - debug("freeing taskmgr"); - isc_taskmgr_destroy(&taskmgr); - } - debug("closing down netmgr"); - isc_nm_closedown(netmgr); - - debug("destroy netmgr"); - isc_nm_destroy(&netmgr); + isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL); LOCK_LOOKUP; isc_refcount_destroy(&recvcount); diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 902dfce8b4..f19b692612 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -3963,13 +3964,7 @@ main(int argc, char *argv[]) { print_time(outfp); print_version(outfp); - netmgr = isc_nm_start(mctx, ntasks); - - result = isc_taskmgr_create(mctx, 0, netmgr, &taskmgr); - if (result != ISC_R_SUCCESS) { - fatal("failed to create task manager: %s", - isc_result_totext(result)); - } + isc_managers_create(mctx, ntasks, 0, 0, &netmgr, &taskmgr, NULL, NULL); master = NULL; result = isc_task_create(taskmgr, 0, &master); @@ -4020,8 +4015,7 @@ main(int argc, char *argv[]) { for (i = 0; i < (int)ntasks; i++) { isc_task_detach(&tasks[i]); } - isc_taskmgr_destroy(&taskmgr); - isc_nm_destroy(&netmgr); + isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL); isc_mem_put(mctx, tasks, ntasks * sizeof(isc_task_t *)); postsign(); TIME_NOW(&sign_finish); diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index 01918009a3..d3084b3ea1 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -1164,10 +1164,10 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp, } #endif - CHECK(isc_nm_listentcp(named_g_nm, (isc_nmiface_t *)&listener->address, - control_newconn, listener, - sizeof(controlconnection_t), 5, NULL, - &listener->sock)); + CHECK(isc_nm_listentcp( + named_g_netmgr, (isc_nmiface_t *)&listener->address, + control_newconn, listener, sizeof(controlconnection_t), 5, NULL, + &listener->sock)); #if 0 /* XXX: no unix socket support yet */ if (type == isc_socktype_unix) { diff --git a/bin/named/include/named/globals.h b/bin/named/include/named/globals.h index b8ea5946a4..8663eaf012 100644 --- a/bin/named/include/named/globals.h +++ b/bin/named/include/named/globals.h @@ -62,7 +62,7 @@ EXTERN bool named_g_run_done INIT(false); */ EXTERN isc_timermgr_t *named_g_timermgr INIT(NULL); EXTERN isc_socketmgr_t *named_g_socketmgr INIT(NULL); -EXTERN isc_nm_t *named_g_nm INIT(NULL); +EXTERN isc_nm_t *named_g_netmgr INIT(NULL); EXTERN cfg_parser_t *named_g_parser INIT(NULL); EXTERN cfg_parser_t *named_g_addparser INIT(NULL); EXTERN const char *named_g_version INIT(PACKAGE_VERSION); diff --git a/bin/named/main.c b/bin/named/main.c index f033607609..28bfdd57f6 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -937,45 +938,17 @@ create_managers(void) { "using %u UDP listener%s per interface", named_g_udpdisp, named_g_udpdisp == 1 ? "" : "s"); - /* - * We have ncpus network threads, ncpus worker threads, ncpus - * old network threads - make it 4x just to be safe. The memory - * impact is negligible. - */ - isc_hp_init(4 * named_g_cpus); - named_g_nm = isc_nm_start(named_g_mctx, named_g_cpus); - if (named_g_nm == NULL) { - UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_nm_start() failed"); - return (ISC_R_UNEXPECTED); + result = isc_managers_create(named_g_mctx, named_g_cpus, + 0 /* quantum */, maxsocks, &named_g_netmgr, + &named_g_taskmgr, &named_g_timermgr, + &named_g_socketmgr); + if (result != ISC_R_SUCCESS) { + return (result); } - result = isc_taskmgr_create(named_g_mctx, 0, named_g_nm, - &named_g_taskmgr); - if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_taskmgr_create() failed: %s", - isc_result_totext(result)); - return (ISC_R_UNEXPECTED); - } - - result = isc_timermgr_create(named_g_mctx, &named_g_timermgr); - if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_timermgr_create() failed: %s", - isc_result_totext(result)); - return (ISC_R_UNEXPECTED); - } - - result = isc_socketmgr_create2(named_g_mctx, &named_g_socketmgr, - maxsocks, named_g_cpus); - if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_socketmgr_create() failed: %s", - isc_result_totext(result)); - return (ISC_R_UNEXPECTED); - } isc_socketmgr_maxudp(named_g_socketmgr, maxudp); - isc_nm_maxudp(named_g_nm, maxudp); + isc_nm_maxudp(named_g_netmgr, maxudp); + result = isc_socketmgr_getmaxsockets(named_g_socketmgr, &socks); if (result == ISC_R_SUCCESS) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, @@ -988,21 +961,8 @@ create_managers(void) { static void destroy_managers(void) { - /* - * isc_nm_closedown() closes all active connections, freeing - * attached clients and other resources and preventing new - * connections from being established, but it not does not - * stop all processing or destroy the netmgr yet. - */ - isc_nm_closedown(named_g_nm); - - /* - * isc_taskmgr_destroy() will block until all tasks have exited. - */ - isc_taskmgr_destroy(&named_g_taskmgr); - isc_nm_destroy(&named_g_nm); - isc_timermgr_destroy(&named_g_timermgr); - isc_socketmgr_destroy(&named_g_socketmgr); + isc_managers_destroy(&named_g_netmgr, &named_g_taskmgr, + &named_g_timermgr, &named_g_socketmgr); } static void diff --git a/bin/named/server.c b/bin/named/server.c index e306fd63b5..3edad71616 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -8840,7 +8840,8 @@ load_configuration(const char *filename, named_server_t *server, advertised = MAX_ADVERTISED_TIMEOUT; } - isc_nm_settimeouts(named_g_nm, initial, idle, keepalive, advertised); + isc_nm_settimeouts(named_g_netmgr, initial, idle, keepalive, + advertised); /* * Configure sets of UDP query source ports. @@ -9950,7 +9951,7 @@ run_server(isc_task_t *task, isc_event_t *event) { CHECKFATAL(ns_interfacemgr_create( named_g_mctx, server->sctx, named_g_taskmgr, - named_g_timermgr, named_g_socketmgr, named_g_nm, + named_g_timermgr, named_g_socketmgr, named_g_netmgr, named_g_dispatchmgr, server->task, named_g_udpdisp, geoip, named_g_cpus, &server->interfacemgr), "creating interface manager"); @@ -10220,7 +10221,7 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) { CHECKFATAL(dns_zonemgr_create(named_g_mctx, named_g_taskmgr, named_g_timermgr, named_g_socketmgr, - named_g_nm, &server->zonemgr), + named_g_netmgr, &server->zonemgr), "dns_zonemgr_create"); CHECKFATAL(dns_zonemgr_setsize(server->zonemgr, 1000), "dns_zonemgr_" "setsize"); @@ -10260,7 +10261,7 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) { isc_sockstatscounter_max), "isc_stats_create"); isc_socketmgr_setstats(named_g_socketmgr, server->sockstats); - isc_nm_setstats(named_g_nm, server->sockstats); + isc_nm_setstats(named_g_netmgr, server->sockstats); CHECKFATAL(isc_stats_create(named_g_mctx, &server->zonestats, dns_zonestatscounter_max), @@ -16342,7 +16343,7 @@ named_server_tcptimeouts(isc_lex_t *lex, isc_buffer_t **text) { return (ISC_R_UNEXPECTEDEND); } - isc_nm_gettimeouts(named_g_nm, &initial, &idle, &keepalive, + isc_nm_gettimeouts(named_g_netmgr, &initial, &idle, &keepalive, &advertised); /* Look for optional arguments. */ @@ -16396,7 +16397,7 @@ named_server_tcptimeouts(isc_lex_t *lex, isc_buffer_t **text) { result = isc_task_beginexclusive(named_g_server->task); RUNTIME_CHECK(result == ISC_R_SUCCESS); - isc_nm_settimeouts(named_g_nm, initial, idle, keepalive, + isc_nm_settimeouts(named_g_netmgr, initial, idle, keepalive, advertised); isc_task_endexclusive(named_g_server->task); diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c index d2cfc12bf5..7e1e982646 100644 --- a/bin/named/statschannel.c +++ b/bin/named/statschannel.c @@ -3612,7 +3612,7 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp, CHECK(ISC_R_FAMILYNOSUPPORT); } - CHECK(isc_httpdmgr_create(named_g_nm, server->mctx, addr, client_ok, + CHECK(isc_httpdmgr_create(named_g_netmgr, server->mctx, addr, client_ok, destroy_listener, listener, &listener->httpdmgr)); diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 4965a274f5..b5ab597899 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -923,16 +924,8 @@ setup_system(void) { result = dns_dispatchmgr_create(gmctx, &dispatchmgr); check_result(result, "dns_dispatchmgr_create"); - result = isc_socketmgr_create(gmctx, &socketmgr); - check_result(result, "dns_socketmgr_create"); - - result = isc_timermgr_create(gmctx, &timermgr); - check_result(result, "dns_timermgr_create"); - - netmgr = isc_nm_start(gmctx, 1); - - result = isc_taskmgr_create(gmctx, 0, netmgr, &taskmgr); - check_result(result, "isc_taskmgr_create"); + isc_managers_create(gmctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr, + &socketmgr); result = isc_task_create(taskmgr, 0, &global_task); check_result(result, "isc_task_create"); @@ -3325,21 +3318,12 @@ cleanup(void) { dst_key_free(&sig0key); } - ddebug("Shutting down task manager"); - isc_taskmgr_destroy(&taskmgr); - - ddebug("Shutting down network manager"); - isc_nm_destroy(&netmgr); + ddebug("Shutting down managers"); + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); ddebug("Destroying event"); isc_event_free(&global_event); - ddebug("Shutting down socket manager"); - isc_socketmgr_destroy(&socketmgr); - - ddebug("Shutting down timer manager"); - isc_timermgr_destroy(&timermgr); - #ifdef HAVE_GSSAPI /* * Cleanup GSSAPI resources after taskmgr has been destroyed. diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 624910a02d..fe30895f99 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ const char *progname = NULL; bool verbose; +static isc_nm_t *netmgr = NULL; static isc_taskmgr_t *taskmgr = NULL; static isc_task_t *rndc_task = NULL; @@ -72,7 +74,6 @@ static bool local4set = false, local6set = false; static int nserveraddrs; static int currentaddr = 0; static unsigned int remoteport = 0; -static isc_nm_t *netmgr = NULL; static isc_buffer_t *databuf = NULL; static isccc_ccmsg_t rndc_ccmsg; static uint32_t algorithm; @@ -1030,9 +1031,7 @@ main(int argc, char **argv) { serial = isc_random32(); isc_mem_create(&rndc_mctx); - netmgr = isc_nm_start(rndc_mctx, 1); - DO("create task manager", - isc_taskmgr_create(rndc_mctx, 0, netmgr, &taskmgr)); + isc_managers_create(rndc_mctx, 1, 0, 0, &netmgr, &taskmgr, NULL, NULL); DO("create task", isc_task_create(taskmgr, 0, &rndc_task)); isc_log_create(rndc_mctx, &log, &logconfig); isc_log_setcontext(log); @@ -1089,9 +1088,7 @@ main(int argc, char **argv) { } isc_task_detach(&rndc_task); - isc_taskmgr_destroy(&taskmgr); - - isc_nm_closedown(netmgr); + isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL); /* * Note: when TCP connections are shut down, there will be a final @@ -1101,8 +1098,6 @@ main(int argc, char **argv) { */ isccc_ccmsg_invalidate(&rndc_ccmsg); - isc_nm_destroy(&netmgr); - isc_log_destroy(&log); isc_log_setcontext(NULL); diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c index 02f312ee2f..aa2007d7d2 100644 --- a/bin/tests/system/pipelined/pipequeries.c +++ b/bin/tests/system/pipelined/pipequeries.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -208,10 +209,10 @@ main(int argc, char *argv[]) { isc_logconfig_t *lcfg; isc_nm_t *netmgr = NULL; isc_taskmgr_t *taskmgr = NULL; - isc_task_t *task; - isc_timermgr_t *timermgr; - isc_socketmgr_t *socketmgr; - dns_dispatchmgr_t *dispatchmgr; + isc_task_t *task = NULL; + isc_timermgr_t *timermgr = NULL; + isc_socketmgr_t *socketmgr = NULL; + dns_dispatchmgr_t *dispatchmgr = NULL; unsigned int attrs, attrmask; dns_dispatch_t *dispatchv4; dns_view_t *view; @@ -277,17 +278,10 @@ main(int argc, char *argv[]) { RUNCHECK(dst_lib_init(mctx, NULL)); - netmgr = isc_nm_start(mctx, 1); + isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr, + &socketmgr); - RUNCHECK(isc_taskmgr_create(mctx, 0, netmgr, &taskmgr)); - task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); - timermgr = NULL; - - RUNCHECK(isc_timermgr_create(mctx, &timermgr)); - socketmgr = NULL; - RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); - dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr)); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY | @@ -318,13 +312,10 @@ main(int argc, char *argv[]) { dns_dispatch_detach(&dispatchv4); dns_dispatchmgr_destroy(&dispatchmgr); - isc_socketmgr_destroy(&socketmgr); - isc_timermgr_destroy(&timermgr); - isc_task_shutdown(task); isc_task_detach(&task); - isc_taskmgr_destroy(&taskmgr); - isc_nm_destroy(&netmgr); + + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); dst_lib_destroy(); diff --git a/bin/tests/system/resolve.c b/bin/tests/system/resolve.c index b2fc5225a8..c8f7a18621 100644 --- a/bin/tests/system/resolve.c +++ b/bin/tests/system/resolve.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -66,25 +67,8 @@ isc_timermgr_t *ctxs_timermgr = NULL; static void ctxs_destroy(void) { - if (ctxs_netmgr != NULL) { - isc_nm_closedown(ctxs_netmgr); - } - - if (ctxs_taskmgr != NULL) { - isc_taskmgr_destroy(&ctxs_taskmgr); - } - - if (ctxs_netmgr != NULL) { - isc_nm_destroy(&ctxs_netmgr); - } - - if (ctxs_timermgr != NULL) { - isc_timermgr_destroy(&ctxs_timermgr); - } - - if (ctxs_socketmgr != NULL) { - isc_socketmgr_destroy(&ctxs_socketmgr); - } + isc_managers_destroy(&ctxs_netmgr, &ctxs_taskmgr, &ctxs_timermgr, + &ctxs_socketmgr); if (ctxs_actx != NULL) { isc_appctx_destroy(&ctxs_actx); @@ -106,22 +90,8 @@ ctxs_init(void) { goto fail; } - ctxs_netmgr = isc_nm_start(ctxs_mctx, 1); - - result = isc_taskmgr_create(ctxs_mctx, 0, ctxs_netmgr, &ctxs_taskmgr); - if (result != ISC_R_SUCCESS) { - goto fail; - } - - result = isc_socketmgr_create(ctxs_mctx, &ctxs_socketmgr); - if (result != ISC_R_SUCCESS) { - goto fail; - } - - result = isc_timermgr_create(ctxs_mctx, &ctxs_timermgr); - if (result != ISC_R_SUCCESS) { - goto fail; - } + isc_managers_create(ctxs_mctx, 1, 0, 0, &ctxs_netmgr, &ctxs_taskmgr, + &ctxs_timermgr, &ctxs_socketmgr); return (ISC_R_SUCCESS); diff --git a/bin/tests/system/tkey/keycreate.c b/bin/tests/system/tkey/keycreate.c index 51ed1212dd..b72b38056a 100644 --- a/bin/tests/system/tkey/keycreate.c +++ b/bin/tests/system/tkey/keycreate.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -191,21 +192,21 @@ sendquery(isc_task_t *task, isc_event_t *event) { int main(int argc, char *argv[]) { - char *ourkeyname; + char *ourkeyname = NULL; isc_nm_t *netmgr = NULL; isc_taskmgr_t *taskmgr = NULL; - isc_timermgr_t *timermgr; - isc_socketmgr_t *socketmgr; - isc_socket_t *sock; + isc_timermgr_t *timermgr = NULL; + isc_socketmgr_t *socketmgr = NULL; + isc_socket_t *sock = NULL; unsigned int attrs, attrmask; isc_sockaddr_t bind_any; - dns_dispatchmgr_t *dispatchmgr; - dns_dispatch_t *dispatchv4; - dns_view_t *view; - dns_tkeyctx_t *tctx; - isc_log_t *log; - isc_logconfig_t *logconfig; - isc_task_t *task; + dns_dispatchmgr_t *dispatchmgr = NULL; + dns_dispatch_t *dispatchv4 = NULL; + dns_view_t *view = NULL; + dns_tkeyctx_t *tctx = NULL; + isc_log_t *log = NULL; + isc_logconfig_t *logconfig = NULL; + isc_task_t *task = NULL; isc_result_t result; int type; @@ -235,17 +236,12 @@ main(int argc, char *argv[]) { RUNCHECK(dst_lib_init(mctx, NULL)); - netmgr = isc_nm_start(mctx, 1); + isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr, + &socketmgr); - RUNCHECK(isc_taskmgr_create(mctx, 0, netmgr, &taskmgr)); - task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); - timermgr = NULL; - RUNCHECK(isc_timermgr_create(mctx, &timermgr)); - socketmgr = NULL; - RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); - dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr)); + isc_sockaddr_any(&bind_any); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY | DNS_DISPATCHATTR_IPV4; @@ -293,11 +289,8 @@ main(int argc, char *argv[]) { dns_dispatchmgr_destroy(&dispatchmgr); isc_task_shutdown(task); isc_task_detach(&task); - isc_taskmgr_destroy(&taskmgr); - isc_nm_destroy(&netmgr); isc_socket_detach(&sock); - isc_socketmgr_destroy(&socketmgr); - isc_timermgr_destroy(&timermgr); + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); dst_key_free(&ourkey); dns_tsigkey_detach(&initialkey); diff --git a/bin/tests/system/tkey/keydelete.c b/bin/tests/system/tkey/keydelete.c index cc92df049c..891b9cd04f 100644 --- a/bin/tests/system/tkey/keydelete.c +++ b/bin/tests/system/tkey/keydelete.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -135,22 +136,22 @@ sendquery(isc_task_t *task, isc_event_t *event) { int main(int argc, char **argv) { - char *keyname; - isc_nm_t *netmgr; + char *keyname = NULL; + isc_nm_t *netmgr = NULL; isc_taskmgr_t *taskmgr = NULL; - isc_timermgr_t *timermgr; - isc_socketmgr_t *socketmgr; - isc_socket_t *sock; + isc_timermgr_t *timermgr = NULL; + isc_socketmgr_t *socketmgr = NULL; + isc_socket_t *sock = NULL; unsigned int attrs, attrmask; isc_sockaddr_t bind_any; - dns_dispatchmgr_t *dispatchmgr; - dns_dispatch_t *dispatchv4; - dns_view_t *view; - dns_tkeyctx_t *tctx; - dst_key_t *dstkey; - isc_log_t *log; - isc_logconfig_t *logconfig; - isc_task_t *task; + dns_dispatchmgr_t *dispatchmgr = NULL; + dns_dispatch_t *dispatchv4 = NULL; + dns_view_t *view = NULL; + dns_tkeyctx_t *tctx = NULL; + dst_key_t *dstkey = NULL; + isc_log_t *log = NULL; + isc_logconfig_t *logconfig = NULL; + isc_task_t *task = NULL; isc_result_t result; int type; @@ -179,16 +180,10 @@ main(int argc, char **argv) { RUNCHECK(dst_lib_init(mctx, NULL)); - netmgr = isc_nm_start(mctx, 1); + isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr, + &socketmgr); - RUNCHECK(isc_taskmgr_create(mctx, 0, netmgr, &taskmgr)); - task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); - timermgr = NULL; - RUNCHECK(isc_timermgr_create(mctx, &timermgr)); - socketmgr = NULL; - RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); - dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr)); isc_sockaddr_any(&bind_any); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY | @@ -237,11 +232,8 @@ main(int argc, char **argv) { dns_dispatchmgr_destroy(&dispatchmgr); isc_task_shutdown(task); isc_task_detach(&task); - isc_taskmgr_destroy(&taskmgr); - isc_nm_destroy(&netmgr); isc_socket_detach(&sock); - isc_socketmgr_destroy(&socketmgr); - isc_timermgr_destroy(&timermgr); + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); dns_tsigkeyring_detach(&ring); diff --git a/bin/tests/test_client.c b/bin/tests/test_client.c index c145115af8..7c9f10e2c6 100644 --- a/bin/tests/test_client.c +++ b/bin/tests/test_client.c @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -307,7 +308,7 @@ setup(void) { isc_mem_create(&mctx); - netmgr = isc_nm_start(mctx, workers); + isc_managers_create(mctx, workers, 0, 0, &netmgr, NULL, NULL, NULL); } static void @@ -316,7 +317,7 @@ teardown(void) { close(out); } - isc_nm_destroy(&netmgr); + isc_managers_destroy(&netmgr, NULL, NULL, NULL); isc_mem_destroy(&mctx); if (tls_ctx) { isc_tlsctx_free(&tls_ctx); diff --git a/bin/tests/test_server.c b/bin/tests/test_server.c index 9276b62022..a53577e201 100644 --- a/bin/tests/test_server.c +++ b/bin/tests/test_server.c @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -188,12 +189,12 @@ setup(void) { isc_mem_create(&mctx); - netmgr = isc_nm_start(mctx, workers); + isc_managers_create(mctx, workers, 0, 0, &netmgr, NULL, NULL, NULL); } static void teardown(void) { - isc_nm_destroy(&netmgr); + isc_managers_destroy(&netmgr, NULL, NULL, NULL); isc_mem_destroy(&mctx); if (tls_ctx) { isc_tlsctx_free(&tls_ctx); diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index a8c47b6197..1b0f04c4ce 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -2070,10 +2071,10 @@ main(int argc, char *argv[]) { isc_logconfig_t *lcfg; isc_nm_t *netmgr = NULL; isc_taskmgr_t *taskmgr = NULL; - isc_task_t *task; - isc_timermgr_t *timermgr; - isc_socketmgr_t *socketmgr; - dns_dispatchmgr_t *dispatchmgr; + isc_task_t *task = NULL; + isc_timermgr_t *timermgr = NULL; + isc_socketmgr_t *socketmgr = NULL; + dns_dispatchmgr_t *dispatchmgr = NULL; unsigned int attrs, attrmask; dns_dispatch_t *dispatchvx; dns_view_t *view; @@ -2130,17 +2131,11 @@ main(int argc, char *argv[]) { fatal("can't choose between IPv4 and IPv6"); } - netmgr = isc_nm_start(mctx, 1); + isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr, + &socketmgr); - RUNCHECK(isc_taskmgr_create(mctx, 0, netmgr, &taskmgr)); - task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); - timermgr = NULL; - RUNCHECK(isc_timermgr_create(mctx, &timermgr)); - socketmgr = NULL; - RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); - dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr)); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY; @@ -2206,13 +2201,10 @@ main(int argc, char *argv[]) { dns_dispatch_detach(&dispatchvx); dns_dispatchmgr_destroy(&dispatchmgr); - isc_socketmgr_destroy(&socketmgr); - isc_timermgr_destroy(&timermgr); - isc_task_shutdown(task); isc_task_detach(&task); - isc_taskmgr_destroy(&taskmgr); - isc_nm_destroy(&netmgr); + + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); dst_lib_destroy(); diff --git a/lib/dns/tests/dnstest.c b/lib/dns/tests/dnstest.c index 71f0e0c743..6a247b6b05 100644 --- a/lib/dns/tests/dnstest.c +++ b/lib/dns/tests/dnstest.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -95,18 +96,7 @@ cleanup_managers(void) { isc_task_shutdown(maintask); isc_task_destroy(&maintask); } - if (socketmgr != NULL) { - isc_socketmgr_destroy(&socketmgr); - } - if (taskmgr != NULL) { - isc_taskmgr_destroy(&taskmgr); - } - if (netmgr != NULL) { - isc_nm_destroy(&netmgr); - } - if (timermgr != NULL) { - isc_timermgr_destroy(&timermgr); - } + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); if (app_running) { isc_app_finish(); } @@ -117,10 +107,8 @@ create_managers(void) { isc_result_t result; ncpus = isc_os_ncpus(); - netmgr = isc_nm_start(dt_mctx, ncpus); - CHECK(isc_taskmgr_create(dt_mctx, 0, netmgr, &taskmgr)); - CHECK(isc_timermgr_create(dt_mctx, &timermgr)); - CHECK(isc_socketmgr_create(dt_mctx, &socketmgr)); + isc_managers_create(dt_mctx, ncpus, 0, 0, &netmgr, &taskmgr, &timermgr, + &socketmgr); CHECK(isc_task_create(taskmgr, 0, &maintask)); return (ISC_R_SUCCESS); diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 22212d9e38..96124a2d89 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -46,6 +46,7 @@ libisc_la_HEADERS = \ include/isc/list.h \ include/isc/log.h \ include/isc/magic.h \ + include/isc/managers.h \ include/isc/md.h \ include/isc/mem.h \ include/isc/meminfo.h \ @@ -182,6 +183,7 @@ libisc_la_SOURCES = \ lex.c \ lib.c \ log.c \ + managers.c \ md.c \ mem.c \ mutexblock.c \ @@ -222,6 +224,10 @@ libisc_la_SOURCES = \ pthreads/thread.c \ entropy_private.h \ fsaccess_common_p.h \ + task_p.h \ + timer_p.h \ + socket_p.h \ + netmgr_p.h \ lib_p.h \ mem_p.h \ tls_p.h diff --git a/lib/isc/hp.c b/lib/isc/hp.c index 92d160b3eb..20646a8a74 100644 --- a/lib/isc/hp.c +++ b/lib/isc/hp.c @@ -82,6 +82,9 @@ tid(void) { void isc_hp_init(int max_threads) { + if (isc__hp_max_threads > max_threads) { + return; + } isc__hp_max_threads = max_threads; isc__hp_max_retired = max_threads * HP_MAX_HPS; } diff --git a/lib/isc/include/isc/hp.h b/lib/isc/include/isc/hp.h index 44155e625a..948eaa894a 100644 --- a/lib/isc/include/isc/hp.h +++ b/lib/isc/include/isc/hp.h @@ -66,8 +66,10 @@ typedef void(isc_hp_deletefunc_t)(void *); void isc_hp_init(int max_threads); /*%< - * Initialize hazard pointer constants - isc__hp_max_threads. If more threads - * will try to access hp it will assert. + * Initialize hazard pointer constants, isc__hp_max_threads and + * isc__hp_max_retired. If more threads try to access hp, it + * will assert. Calling this function repeatedly can be used + * to increase the limits, but cannot reduce them. */ isc_hp_t * diff --git a/lib/isc/include/isc/managers.h b/lib/isc/include/isc/managers.h new file mode 100644 index 0000000000..3b3227b09e --- /dev/null +++ b/lib/isc/include/isc/managers.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + +#include +#include +#include +#include +#include + +typedef struct isc_managers isc_managers_t; + +isc_result_t +isc_managers_create(isc_mem_t *mctx, size_t workers, size_t quantum, + size_t sockets, isc_nm_t **netmgrp, + isc_taskmgr_t **taskmgrp, isc_timermgr_t **timermgrp, + isc_socketmgr_t **socketmgrp); + +void +isc_managers_destroy(isc_nm_t **netmgrp, isc_taskmgr_t **taskmgrp, + isc_timermgr_t **timermgrp, isc_socketmgr_t **socketmgrp); diff --git a/lib/isc/include/isc/netmgr.h b/lib/isc/include/isc/netmgr.h index 5ecb92d022..e0a1719026 100644 --- a/lib/isc/include/isc/netmgr.h +++ b/lib/isc/include/isc/netmgr.h @@ -68,19 +68,10 @@ typedef void (*isc_nm_opaquecb_t)(void *arg); * callbacks. */ -isc_nm_t * -isc_nm_start(isc_mem_t *mctx, uint32_t workers); -/*%< - * Creates a new network manager with 'workers' worker threads, - * and starts it running. - */ - void isc_nm_attach(isc_nm_t *mgr, isc_nm_t **dst); void isc_nm_detach(isc_nm_t **mgr0); -void -isc_nm_destroy(isc_nm_t **mgr0); /*%< * Attach/detach a network manager. When all references have been * released, the network manager is shut down, freeing all resources. diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index 61b853c990..ad6cf29603 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -9,8 +9,7 @@ * information regarding copyright ownership. */ -#ifndef ISC_SOCKET_H -#define ISC_SOCKET_H 1 +#pragma once /***** ***** Module Info @@ -676,42 +675,6 @@ isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region, isc_task_t *task, */ /*@}*/ -isc_result_t -isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp); - -isc_result_t -isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, - unsigned int maxsocks, int nthreads); -/*%< - * Create a socket manager. If "maxsocks" is non-zero, it specifies the - * maximum number of sockets that the created manager should handle. - * isc_socketmgr_create() is equivalent of isc_socketmgr_create2() with - * "maxsocks" being zero. - * - * Notes: - * - *\li All memory will be allocated in memory context 'mctx'. - * - * Requires: - * - *\li 'mctx' is a valid memory context. - * - *\li 'managerp' points to a NULL isc_socketmgr_t. - * - *\li 'actx' is a valid application context (for createinctx()). - * - * Ensures: - * - *\li '*managerp' is a valid isc_socketmgr_t. - * - * Returns: - * - *\li #ISC_R_SUCCESS - *\li #ISC_R_NOMEMORY - *\li #ISC_R_UNEXPECTED - *\li #ISC_R_NOTIMPLEMENTED - */ - isc_result_t isc_socketmgr_getmaxsockets(isc_socketmgr_t *manager, unsigned int *nsockp); /*%< @@ -741,31 +704,6 @@ isc_socketmgr_setstats(isc_socketmgr_t *manager, isc_stats_t *stats); * (see above). */ -void -isc_socketmgr_destroy(isc_socketmgr_t **managerp); -/*%< - * Destroy a socket manager. - * - * Notes: - * - *\li This routine blocks until there are no sockets left in the manager, - * so if the caller holds any socket references using the manager, it - * must detach them before calling isc_socketmgr_destroy() or it will - * block forever. - * - * Requires: - * - *\li '*managerp' is a valid isc_socketmgr_t. - * - *\li All sockets managed by this manager are fully detached. - * - * Ensures: - * - *\li *managerp == NULL - * - *\li All resources used by the manager have been freed. - */ - isc_sockettype_t isc_socket_gettype(isc_socket_t *sock); /*%< @@ -908,5 +846,3 @@ typedef isc_result_t (*isc_socketmgrcreatefunc_t)(isc_mem_t * mctx, isc_socketmgr_t **managerp); ISC_LANG_ENDDECLS - -#endif /* ISC_SOCKET_H */ diff --git a/lib/isc/include/isc/task.h b/lib/isc/include/isc/task.h index 29e7c99544..f8a790403e 100644 --- a/lib/isc/include/isc/task.h +++ b/lib/isc/include/isc/task.h @@ -9,8 +9,7 @@ * information regarding copyright ownership. */ -#ifndef ISC_TASK_H -#define ISC_TASK_H 1 +#pragma once /***** ***** Module Info @@ -626,81 +625,11 @@ isc_task_privilege(isc_task_t *task); ***** Task Manager. *****/ -isc_result_t -isc_taskmgr_create(isc_mem_t *mctx, unsigned int default_quantum, isc_nm_t *nm, - isc_taskmgr_t **managerp); -/*%< - * Create a new task manager. - * - * Notes: - * - *\li If 'default_quantum' is non-zero, then it will be used as the default - * quantum value when tasks are created. If zero, then an implementation - * defined default quantum will be used. - * - *\li If 'nm' is set then netmgr is paused when an exclusive task mode - * is requested. - * - * Requires: - * - *\li 'mctx' is a valid memory context. - * - *\li managerp != NULL && *managerp == NULL - * - * Ensures: - * - *\li On success, '*managerp' will be attached to the newly created task - * manager. - * - * Returns: - * - *\li #ISC_R_SUCCESS - *\li #ISC_R_NOMEMORY - *\li #ISC_R_NOTHREADS No threads could be created. - *\li #ISC_R_UNEXPECTED An unexpected error occurred. - *\li #ISC_R_SHUTTINGDOWN The non-threaded, shared, task - * manager shutting down. - */ - void isc_taskmgr_attach(isc_taskmgr_t *, isc_taskmgr_t **); void isc_taskmgr_detach(isc_taskmgr_t *); -void -isc_taskmgr_destroy(isc_taskmgr_t **managerp); -/*%< - * Destroy '*managerp'. - * - * Notes: - * - *\li Calling isc_taskmgr_destroy() will shutdown all tasks managed by - * *managerp that haven't already been shutdown. The call will block - * until all tasks have entered the done state. - * - *\li isc_taskmgr_destroy() must not be called by a task event action, - * because it would block forever waiting for the event action to - * complete. An event action that wants to cause task manager shutdown - * should request some non-event action thread of execution to do the - * shutdown, e.g. by signaling a condition variable or using - * isc_app_shutdown(). - * - *\li Task manager references are not reference counted, so the caller - * must ensure that no attempt will be made to use the manager after - * isc_taskmgr_destroy() returns. - * - * Requires: - * - *\li '*managerp' is a valid task manager. - * - *\li isc_taskmgr_destroy() has not be called previously on '*managerp'. - * - * Ensures: - * - *\li All resources used by the task manager, and any tasks it managed, - * have been freed. - */ - void isc_taskmgr_setexcltask(isc_taskmgr_t *mgr, isc_task_t *task); /*%< @@ -736,5 +665,3 @@ isc_taskmgr_renderjson(isc_taskmgr_t *mgr, void *tasksobj0); #endif /* HAVE_JSON_C */ ISC_LANG_ENDDECLS - -#endif /* ISC_TASK_H */ diff --git a/lib/isc/include/isc/timer.h b/lib/isc/include/isc/timer.h index 88601b8f85..96376e5cc8 100644 --- a/lib/isc/include/isc/timer.h +++ b/lib/isc/include/isc/timer.h @@ -9,8 +9,7 @@ * information regarding copyright ownership. */ -#ifndef ISC_TIMER_H -#define ISC_TIMER_H 1 +#pragma once /***** ***** Module Info @@ -276,58 +275,7 @@ isc_timer_gettype(isc_timer_t *timer); *\li 'timer' to be a valid timer. */ -isc_result_t -isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp); -/*%< - * Create a timer manager. - * - * Notes: - * - *\li All memory will be allocated in memory context 'mctx'. - * - * Requires: - * - *\li 'mctx' is a valid memory context. - * - *\li 'managerp' points to a NULL isc_timermgr_t. - * - * Ensures: - * - *\li '*managerp' is a valid isc_timermgr_t. - * - * Returns: - * - *\li Success - *\li No memory - *\li Unexpected error - */ - -void -isc_timermgr_destroy(isc_timermgr_t **managerp); -/*%< - * Destroy a timer manager. - * - * Notes: - * - *\li This routine blocks until there are no timers left in the manager, - * so if the caller holds any timer references using the manager, it - * must detach them before calling isc_timermgr_destroy() or it will - * block forever. - * - * Requires: - * - *\li '*managerp' is a valid isc_timermgr_t. - * - * Ensures: - * - *\li *managerp == NULL - * - *\li All resources used by the manager have been freed. - */ - void isc_timermgr_poke(isc_timermgr_t *m); ISC_LANG_ENDDECLS - -#endif /* ISC_TIMER_H */ diff --git a/lib/isc/managers.c b/lib/isc/managers.c new file mode 100644 index 0000000000..8a17fd1e05 --- /dev/null +++ b/lib/isc/managers.c @@ -0,0 +1,109 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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. + */ + +#include +#include +#include + +#include "netmgr_p.h" +#include "socket_p.h" +#include "task_p.h" +#include "timer_p.h" + +isc_result_t +isc_managers_create(isc_mem_t *mctx, size_t workers, size_t quantum, + size_t sockets, isc_nm_t **netmgrp, + isc_taskmgr_t **taskmgrp, isc_timermgr_t **timermgrp, + isc_socketmgr_t **socketmgrp) { + isc_result_t result; + isc_nm_t *netmgr = NULL; + isc_socketmgr_t *socketmgr = NULL; + isc_taskmgr_t *taskmgr = NULL; + isc_timermgr_t *timermgr = NULL; + + /* + * We have ncpus network threads, ncpus old network threads - make + * it 4x just to be on the safe side. + */ + isc_hp_init(4 * workers); + + REQUIRE(netmgrp != NULL && *netmgrp == NULL); + isc__netmgr_create(mctx, workers, &netmgr); + *netmgrp = netmgr; + INSIST(netmgr != NULL); + + REQUIRE(taskmgrp == NULL || *taskmgrp == NULL); + if (taskmgrp != NULL) { + result = isc__taskmgr_create(mctx, quantum, netmgr, &taskmgr); + if (result != ISC_R_SUCCESS) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "isc_taskmgr_create() failed: %s", + isc_result_totext(result)); + goto fail; + } + *taskmgrp = taskmgr; + } + + REQUIRE(timermgrp == NULL || *timermgrp == NULL); + if (timermgrp != NULL) { + result = isc__timermgr_create(mctx, &timermgr); + if (result != ISC_R_SUCCESS) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "isc_timermgr_create() failed: %s", + isc_result_totext(result)); + goto fail; + } + *timermgrp = timermgr; + } + + REQUIRE(socketmgrp == NULL || *socketmgrp == NULL); + if (socketmgrp != NULL) { + result = isc__socketmgr_create(mctx, &socketmgr, sockets, + workers); + if (result != ISC_R_SUCCESS) { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "isc_socketmgr_create() failed: %s", + isc_result_totext(result)); + goto fail; + } + *socketmgrp = socketmgr; + } + + return (ISC_R_SUCCESS); +fail: + isc_managers_destroy(netmgrp, taskmgrp, timermgrp, socketmgrp); + + return (result); +} + +void +isc_managers_destroy(isc_nm_t **netmgrp, isc_taskmgr_t **taskmgrp, + isc_timermgr_t **timermgrp, isc_socketmgr_t **socketmgrp) { + if (netmgrp != NULL && *netmgrp != NULL) { + isc_nm_closedown(*netmgrp); + } + + if (taskmgrp != NULL && *taskmgrp != NULL) { + isc__taskmgr_destroy(taskmgrp); + } + + if (netmgrp != NULL && *netmgrp != NULL) { + isc__netmgr_destroy(netmgrp); + } + + if (timermgrp != NULL && *timermgrp != NULL) { + isc__timermgr_destroy(timermgrp); + } + + if (socketmgrp != NULL && *socketmgrp != NULL) { + isc__socketmgr_destroy(socketmgrp); + } +} diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 0699fe807e..7acaca8791 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -37,6 +37,7 @@ #include #include "netmgr-int.h" +#include "netmgr_p.h" #include "openssl_shim.h" #include "uv-compat.h" @@ -206,8 +207,8 @@ isc__nm_winsock_destroy(void) { } #endif /* WIN32 */ -isc_nm_t * -isc_nm_start(isc_mem_t *mctx, uint32_t workers) { +void +isc__netmgr_create(isc_mem_t *mctx, uint32_t workers, isc_nm_t **netmgrp) { isc_nm_t *mgr = NULL; char name[32]; @@ -296,7 +297,7 @@ isc_nm_start(isc_mem_t *mctx, uint32_t workers) { } mgr->magic = NM_MAGIC; - return (mgr); + *netmgrp = mgr; } /* @@ -485,14 +486,13 @@ isc_nm_closedown(isc_nm_t *mgr) { } void -isc_nm_destroy(isc_nm_t **mgr0) { +isc__netmgr_destroy(isc_nm_t **netmgrp) { isc_nm_t *mgr = NULL; int counter = 0; - REQUIRE(mgr0 != NULL); - REQUIRE(VALID_NM(*mgr0)); + REQUIRE(VALID_NM(*netmgrp)); - mgr = *mgr0; + mgr = *netmgrp; /* * Close active connections. @@ -524,7 +524,7 @@ isc_nm_destroy(isc_nm_t **mgr0) { /* * Detach final reference. */ - isc_nm_detach(mgr0); + isc_nm_detach(netmgrp); } void diff --git a/lib/isc/netmgr_p.h b/lib/isc/netmgr_p.h new file mode 100644 index 0000000000..ce934d51c9 --- /dev/null +++ b/lib/isc/netmgr_p.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + +#include +#include + +void +isc__netmgr_create(isc_mem_t *mctx, uint32_t workers, isc_nm_t **netgmrp); +/*%< + * Creates a new network manager with 'workers' worker threads, + * and starts it running. + */ + +void +isc__netmgr_destroy(isc_nm_t **netmgrp); +/*%< + * Destroy is working the same way as isc_nm_detach, but it actively waits + * for all other references to be gone. + */ diff --git a/lib/isc/socket_p.h b/lib/isc/socket_p.h new file mode 100644 index 0000000000..2ac133fd13 --- /dev/null +++ b/lib/isc/socket_p.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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. + */ + +#include +#include +#include + +isc_result_t +isc__socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp, + unsigned int maxsocks, int nthreads); +/*%< + * Create a socket manager. If "maxsocks" is non-zero, it specifies the + * maximum number of sockets that the created manager should handle. + * + * Notes: + * + *\li All memory will be allocated in memory context 'mctx'. + * + * Requires: + * + *\li 'mctx' is a valid memory context. + * + *\li 'managerp' points to a NULL isc_socketmgr_t. + * + * Ensures: + * + *\li '*managerp' is a valid isc_socketmgr_t. + * + * Returns: + * + *\li #ISC_R_SUCCESS + *\li #ISC_R_NOMEMORY + *\li #ISC_R_UNEXPECTED + *\li #ISC_R_NOTIMPLEMENTED + */ + +void +isc__socketmgr_destroy(isc_socketmgr_t **managerp); +/*%< + * Destroy a socket manager. + * + * Notes: + * + *\li This routine blocks until there are no sockets left in the manager, + * so if the caller holds any socket references using the manager, it + * must detach them before calling isc_socketmgr_destroy() or it will + * block forever. + * + * Requires: + * + *\li '*managerp' is a valid isc_socketmgr_t. + * + *\li All sockets managed by this manager are fully detached. + * + * Ensures: + * + *\li *managerp == NULL + * + *\li All resources used by the manager have been freed. + */ + +#if !WIN32 + +#include + +typedef struct isc_socketwait isc_socketwait_t; +int +isc__socketmgr_waitevents(isc_socketmgr_t *, struct timeval *, + isc_socketwait_t **); +isc_result_t +isc__socketmgr_dispatch(isc_socketmgr_t *, isc_socketwait_t *); + +#endif diff --git a/lib/isc/task.c b/lib/isc/task.c index b8996a7f0e..2c987875b3 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -44,9 +44,7 @@ #include #endif /* HAVE_JSON_C */ -#ifdef OPENSSL_LEAKS -#include -#endif /* ifdef OPENSSL_LEAKS */ +#include "task_p.h" /* * Task manager is built around 'as little locking as possible' concept. @@ -967,8 +965,8 @@ isc_taskmgr_detach(isc_taskmgr_t *manager) { } isc_result_t -isc_taskmgr_create(isc_mem_t *mctx, unsigned int default_quantum, isc_nm_t *nm, - isc_taskmgr_t **managerp) { +isc__taskmgr_create(isc_mem_t *mctx, unsigned int default_quantum, isc_nm_t *nm, + isc_taskmgr_t **managerp) { isc_taskmgr_t *manager; /* @@ -1010,7 +1008,7 @@ isc_taskmgr_create(isc_mem_t *mctx, unsigned int default_quantum, isc_nm_t *nm, } void -isc_taskmgr_destroy(isc_taskmgr_t **managerp) { +isc__taskmgr_destroy(isc_taskmgr_t **managerp) { isc_taskmgr_t *manager; isc_task_t *task; diff --git a/lib/isc/task_p.h b/lib/isc/task_p.h new file mode 100644 index 0000000000..fbf3eb1c56 --- /dev/null +++ b/lib/isc/task_p.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + +#include +#include +#include + +isc_result_t +isc__taskmgr_create(isc_mem_t *mctx, unsigned int default_quantum, isc_nm_t *nm, + isc_taskmgr_t **managerp); +/*%< + * Create a new task manager. + * + * Notes: + * + *\li If 'default_quantum' is non-zero, then it will be used as the default + * quantum value when tasks are created. If zero, then an implementation + * defined default quantum will be used. + * + *\li If 'nm' is set then netmgr is paused when an exclusive task mode + * is requested. + * + * Requires: + * + *\li 'mctx' is a valid memory context. + * + *\li managerp != NULL && *managerp == NULL + * + * Ensures: + * + *\li On success, '*managerp' will be attached to the newly created task + * manager. + * + * Returns: + * + *\li #ISC_R_SUCCESS + *\li #ISC_R_NOMEMORY + *\li #ISC_R_NOTHREADS No threads could be created. + *\li #ISC_R_UNEXPECTED An unexpected error occurred. + *\li #ISC_R_SHUTTINGDOWN The non-threaded, shared, task + * manager shutting down. + */ + +void +isc__taskmgr_destroy(isc_taskmgr_t **managerp); +/*%< + * Destroy '*managerp'. + * + * Notes: + * + *\li Calling isc_taskmgr_destroy() will shutdown all tasks managed by + * *managerp that haven't already been shutdown. The call will block + * until all tasks have entered the done state. + * + *\li isc_taskmgr_destroy() must not be called by a task event action, + * because it would block forever waiting for the event action to + * complete. An event action that wants to cause task manager shutdown + * should request some non-event action thread of execution to do the + * shutdown, e.g. by signaling a condition variable or using + * isc_app_shutdown(). + * + *\li Task manager references are not reference counted, so the caller + * must ensure that no attempt will be made to use the manager after + * isc_taskmgr_destroy() returns. + * + * Requires: + * + *\li '*managerp' is a valid task manager. + * + *\li isc_taskmgr_destroy() has not be called previously on '*managerp'. + * + * Ensures: + * + *\li All resources used by the task manager, and any tasks it managed, + * have been freed. + */ diff --git a/lib/isc/tests/Makefile.am b/lib/isc/tests/Makefile.am index 1cee32d754..c8da51d3ee 100644 --- a/lib/isc/tests/Makefile.am +++ b/lib/isc/tests/Makefile.am @@ -10,7 +10,7 @@ LDADD += \ check_LTLIBRARIES = libisctest.la libisctest_la_SOURCES = \ - ../unix/socket_p.h \ + ../socket_p.h \ isctest.c \ isctest.h \ uv_wrap.h diff --git a/lib/isc/tests/doh_test.c b/lib/isc/tests/doh_test.c index a0a93584d2..a04a000a68 100644 --- a/lib/isc/tests/doh_test.c +++ b/lib/isc/tests/doh_test.c @@ -43,6 +43,7 @@ #include "../netmgr/netmgr-int.h" #include "../netmgr/uv-compat.c" #include "../netmgr/uv-compat.h" +#include "../netmgr_p.h" #include "isctest.h" #define MAX_NM 2 @@ -319,7 +320,7 @@ nm_setup(void **state) { nm = isc_mem_get(test_mctx, MAX_NM * sizeof(nm[0])); for (size_t i = 0; i < MAX_NM; i++) { - nm[i] = isc_nm_start(test_mctx, nworkers); + isc__netmgr_create(test_mctx, nworkers, &nm[i]); assert_non_null(nm[i]); } @@ -339,7 +340,7 @@ nm_teardown(void **state) { isc_nm_t **nm = (isc_nm_t **)*state; for (size_t i = 0; i < MAX_NM; i++) { - isc_nm_destroy(&nm[i]); + isc__netmgr_destroy(&nm[i]); assert_null(nm[i]); } isc_mem_put(test_mctx, nm, MAX_NM * sizeof(nm[0])); diff --git a/lib/isc/tests/isctest.c b/lib/isc/tests/isctest.c index c9b6b6929f..bf35210251 100644 --- a/lib/isc/tests/isctest.c +++ b/lib/isc/tests/isctest.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -58,18 +59,7 @@ cleanup_managers(void) { isc_task_shutdown(maintask); isc_task_destroy(&maintask); } - if (socketmgr != NULL) { - isc_socketmgr_destroy(&socketmgr); - } - if (taskmgr != NULL) { - isc_taskmgr_destroy(&taskmgr); - } - if (netmgr != NULL) { - isc_nm_destroy(&netmgr); - } - if (timermgr != NULL) { - isc_timermgr_destroy(&timermgr); - } + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); } static isc_result_t @@ -87,14 +77,12 @@ create_managers(unsigned int workers) { INSIST(workers != 0); isc_hp_init(6 * workers); + isc_managers_create(test_mctx, workers, 0, 0, &netmgr, &taskmgr, + &timermgr, &socketmgr); - netmgr = isc_nm_start(test_mctx, workers); - CHECK(isc_taskmgr_create(test_mctx, 0, netmgr, &taskmgr)); CHECK(isc_task_create(taskmgr, 0, &maintask)); isc_taskmgr_setexcltask(taskmgr, maintask); - CHECK(isc_timermgr_create(test_mctx, &timermgr)); - CHECK(isc_socketmgr_create(test_mctx, &socketmgr)); return (ISC_R_SUCCESS); cleanup: @@ -150,9 +138,6 @@ isc_test_end(void) { if (maintask != NULL) { isc_task_detach(&maintask); } - if (taskmgr != NULL) { - isc_taskmgr_destroy(&taskmgr); - } cleanup_managers(); diff --git a/lib/isc/tests/netmgr_test.c b/lib/isc/tests/netmgr_test.c index d062dbb799..661133a92d 100644 --- a/lib/isc/tests/netmgr_test.c +++ b/lib/isc/tests/netmgr_test.c @@ -37,6 +37,7 @@ #include "../netmgr/udp.c" #include "../netmgr/uv-compat.c" #include "../netmgr/uv-compat.h" +#include "../netmgr_p.h" #include "isctest.h" typedef void (*stream_connect_function)(isc_nm_t *nm); @@ -335,12 +336,12 @@ nm_setup(void **state __attribute__((unused))) { return (-1); } - listen_nm = isc_nm_start(test_mctx, workers); + isc__netmgr_create(test_mctx, workers, &listen_nm); assert_non_null(listen_nm); isc_nm_settimeouts(listen_nm, T_INIT, T_IDLE, T_KEEPALIVE, T_ADVERTISED); - connect_nm = isc_nm_start(test_mctx, workers); + isc__netmgr_create(test_mctx, workers, &connect_nm); assert_non_null(connect_nm); isc_nm_settimeouts(connect_nm, T_INIT, T_IDLE, T_KEEPALIVE, T_ADVERTISED); @@ -358,10 +359,10 @@ static int nm_teardown(void **state __attribute__((unused))) { UNUSED(state); - isc_nm_destroy(&connect_nm); + isc__netmgr_destroy(&connect_nm); assert_null(connect_nm); - isc_nm_destroy(&listen_nm); + isc__netmgr_destroy(&listen_nm); assert_null(listen_nm); WAIT_FOR_EQ(active_cconnects, 0); diff --git a/lib/isc/tests/socket_test.c b/lib/isc/tests/socket_test.c index 47e98a7b46..003571848e 100644 --- a/lib/isc/tests/socket_test.c +++ b/lib/isc/tests/socket_test.c @@ -30,7 +30,7 @@ #include #include -#include "../unix/socket_p.h" +#include "../socket_p.h" #include "isctest.h" static bool recv_dscp; diff --git a/lib/isc/tests/task_test.c b/lib/isc/tests/task_test.c index f6b40f203d..be649393ec 100644 --- a/lib/isc/tests/task_test.c +++ b/lib/isc/tests/task_test.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -784,7 +785,6 @@ maxtask_cb(isc_task_t *task, isc_event_t *event) { static void manytasks(void **state) { isc_mem_t *mctx = NULL; - isc_result_t result; isc_event_t *event = NULL; uintptr_t ntasks = 10000; @@ -801,9 +801,7 @@ manytasks(void **state) { isc_mem_debugging = ISC_MEM_DEBUGRECORD; isc_mem_create(&mctx); - netmgr = isc_nm_start(mctx, 4); - result = isc_taskmgr_create(mctx, 0, netmgr, &taskmgr); - assert_int_equal(result, ISC_R_SUCCESS); + isc_managers_create(mctx, 4, 0, 0, &netmgr, &taskmgr, NULL, NULL); atomic_init(&done, false); @@ -818,8 +816,8 @@ manytasks(void **state) { } UNLOCK(&lock); - isc_taskmgr_destroy(&taskmgr); - isc_nm_destroy(&netmgr); + isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL); + isc_mem_destroy(&mctx); isc_condition_destroy(&cv); isc_mutex_destroy(&lock); @@ -899,7 +897,7 @@ sd_event2(isc_task_t *task, isc_event_t *event) { } static void -shutdown(void **state) { +task_shutdown(void **state) { isc_result_t result; isc_eventtype_t event_type; isc_event_t *event = NULL; @@ -1545,7 +1543,8 @@ main(int argc, char **argv) { cmocka_unit_test_setup_teardown(purgeevent_notpurge, _setup, _teardown), cmocka_unit_test_setup_teardown(purgerange, _setup, _teardown), - cmocka_unit_test_setup_teardown(shutdown, _setup4, _teardown), + cmocka_unit_test_setup_teardown(task_shutdown, _setup4, + _teardown), cmocka_unit_test_setup_teardown(task_exclusive, _setup4, _teardown), }; diff --git a/lib/isc/timer.c b/lib/isc/timer.c index af49801660..a29d966726 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -29,9 +29,7 @@ #include #include -#ifdef OPENSSL_LEAKS -#include -#endif /* ifdef OPENSSL_LEAKS */ +#include "timer_p.h" #ifdef ISC_TIMER_TRACE #define XTRACE(s) fprintf(stderr, "%s\n", (s)) @@ -630,10 +628,6 @@ static isc_threadresult_t } UNLOCK(&manager->lock); -#ifdef OPENSSL_LEAKS - ERR_remove_state(0); -#endif /* ifdef OPENSSL_LEAKS */ - return ((isc_threadresult_t)0); } @@ -663,7 +657,7 @@ set_index(void *what, unsigned int index) { } isc_result_t -isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) { +isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) { isc_timermgr_t *manager; isc_result_t result; @@ -707,7 +701,7 @@ isc_timermgr_poke(isc_timermgr_t *manager) { } void -isc_timermgr_destroy(isc_timermgr_t **managerp) { +isc__timermgr_destroy(isc_timermgr_t **managerp) { isc_timermgr_t *manager; /* diff --git a/lib/isc/timer_p.h b/lib/isc/timer_p.h new file mode 100644 index 0000000000..dca9d72466 --- /dev/null +++ b/lib/isc/timer_p.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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 + +#include +#include +#include + +isc_result_t +isc__timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp); +/*%< + * Create a timer manager. + * + * Notes: + * + *\li All memory will be allocated in memory context 'mctx'. + * + * Requires: + * + *\li 'mctx' is a valid memory context. + * + *\li 'managerp' points to a NULL isc_timermgr_t. + * + * Ensures: + * + *\li '*managerp' is a valid isc_timermgr_t. + * + * Returns: + * + *\li Success + *\li No memory + *\li Unexpected error + */ + +void +isc__timermgr_destroy(isc_timermgr_t **managerp); +/*%< + * Destroy a timer manager. + * + * Notes: + * + *\li This routine blocks until there are no timers left in the manager, + * so if the caller holds any timer references using the manager, it + * must detach them before calling isc_timermgr_destroy() or it will + * block forever. + * + * Requires: + * + *\li '*managerp' is a valid isc_timermgr_t. + * + * Ensures: + * + *\li *managerp == NULL + * + *\li All resources used by the manager have been freed. + */ diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 03923b79c7..c196874483 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -74,6 +74,7 @@ #include #include "errno2result.h" +#include "socket_p.h" #ifdef ENABLE_TCP_FASTOPEN #include @@ -3752,12 +3753,7 @@ cleanup_thread(isc_mem_t *mctx, isc__socketthread_t *thread) { } isc_result_t -isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) { - return (isc_socketmgr_create2(mctx, managerp, 0, 1)); -} - -isc_result_t -isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, +isc__socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp, unsigned int maxsocks, int nthreads) { int i; isc_socketmgr_t *manager; @@ -3828,7 +3824,7 @@ isc_socketmgr_setstats(isc_socketmgr_t *manager, isc_stats_t *stats) { } void -isc_socketmgr_destroy(isc_socketmgr_t **managerp) { +isc__socketmgr_destroy(isc_socketmgr_t **managerp) { isc_socketmgr_t *manager; /* diff --git a/lib/isc/unix/socket_p.h b/lib/isc/unix/socket_p.h deleted file mode 100644 index e6dd818d3c..0000000000 --- a/lib/isc/unix/socket_p.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * 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. - */ - -#ifndef ISC_SOCKET_P_H -#define ISC_SOCKET_P_H - -/*! \file */ - -#include - -typedef struct isc_socketwait isc_socketwait_t; -int -isc__socketmgr_waitevents(isc_socketmgr_t *, struct timeval *, - isc_socketwait_t **); -isc_result_t -isc__socketmgr_dispatch(isc_socketmgr_t *, isc_socketwait_t *); -#endif /* ISC_SOCKET_P_H */ diff --git a/lib/isc/win32/libisc.def.in b/lib/isc/win32/libisc.def.in index 9160199e6d..d5ae24177c 100644 --- a/lib/isc/win32/libisc.def.in +++ b/lib/isc/win32/libisc.def.in @@ -96,9 +96,6 @@ isc_socket_send isc_socket_sendto isc_socket_sendto2 isc_socket_setname -isc_socketmgr_create -isc_socketmgr_create2 -isc_socketmgr_destroy isc_socketmgr_getmaxsockets isc_socketmgr_setreserved isc_socketmgr_setstats @@ -352,6 +349,8 @@ isc_logconfig_create isc_logconfig_destroy isc_logconfig_use isc_logfile_roll +isc_managers_create +isc_managers_destroy isc_md_new isc_md_init isc_md_reset @@ -453,7 +452,6 @@ isc_nmhandle_setdata isc_nmhandle_settimeout isc_nm_cancelread isc_nm_closedown -isc_nm_destroy isc_nm_detach isc_nm_http_endpoint isc_nm_httpconnect @@ -469,7 +467,6 @@ isc_nm_read isc_nm_resumeread isc_nm_send isc_nm_setstats -isc_nm_start isc_nm_stoplistening isc_nm_tcpconnect isc_nm_tcpdnsconnect @@ -653,8 +650,6 @@ isc_task_setprivilege isc_task_shutdown isc_task_unpause isc_task_unsend -isc_taskmgr_create -isc_taskmgr_destroy isc_taskmgr_excltask @IF NOTYET isc_taskmgr_renderjson @@ -706,8 +701,6 @@ isc_timer_detach isc_timer_gettype isc_timer_reset isc_timer_touch -isc_timermgr_create -isc_timermgr_destroy isc_timermgr_poke isc_tls_get_http2_alpn isc_tls_create diff --git a/lib/isc/win32/libisc.vcxproj.filters.in b/lib/isc/win32/libisc.vcxproj.filters.in index c859f3e46d..6c10081745 100644 --- a/lib/isc/win32/libisc.vcxproj.filters.in +++ b/lib/isc/win32/libisc.vcxproj.filters.in @@ -140,6 +140,9 @@ Library Header Files + + Library Header Files + Library Header Files @@ -530,6 +533,9 @@ Library Source Files + + Library Source Files + Library Source Files diff --git a/lib/isc/win32/libisc.vcxproj.in b/lib/isc/win32/libisc.vcxproj.in index 19439387ed..7689222868 100644 --- a/lib/isc/win32/libisc.vcxproj.in +++ b/lib/isc/win32/libisc.vcxproj.in @@ -302,6 +302,7 @@ copy InstallFiles ..\Build\Release\ + @@ -412,6 +413,7 @@ copy InstallFiles ..\Build\Release\ + diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index cf101189f8..3fecf3ee40 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -82,6 +82,7 @@ #endif /* HAVE_LIBXML2 */ #include "errno2result.h" +#include "socket_p.h" /* * Set by the -T dscp option on the command line. If set to a value @@ -2548,12 +2549,7 @@ SocketIoThread(LPVOID ThreadContext) { * Create a new socket manager. */ isc_result_t -isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) { - return (isc_socketmgr_create2(mctx, managerp, 0, 1)); -} - -isc_result_t -isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, +isc__socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp, unsigned int maxsocks, int nthreads) { isc_socketmgr_t *manager; @@ -2611,7 +2607,7 @@ isc_socketmgr_setstats(isc_socketmgr_t *manager, isc_stats_t *stats) { } void -isc_socketmgr_destroy(isc_socketmgr_t **managerp) { +isc__socketmgr_destroy(isc_socketmgr_t **managerp) { isc_socketmgr_t *manager; /* diff --git a/lib/ns/tests/nstest.c b/lib/ns/tests/nstest.c index 173a5c80e7..67f0792bdc 100644 --- a/lib/ns/tests/nstest.c +++ b/lib/ns/tests/nstest.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,6 @@ isc_taskmgr_t *taskmgr = NULL; isc_task_t *maintask = NULL; isc_timermgr_t *timermgr = NULL; isc_socketmgr_t *socketmgr = NULL; -isc_nm_t *nm = NULL; dns_zonemgr_t *zonemgr = NULL; dns_dispatchmgr_t *dispatchmgr = NULL; ns_clientmgr_t *clientmgr = NULL; @@ -198,28 +198,9 @@ cleanup_managers(void) { if (interfacemgr != NULL) { ns_interfacemgr_detach(&interfacemgr); } - if (socketmgr != NULL) { - isc_socketmgr_destroy(&socketmgr); - } - ns_test_nap(500000); - if (nm != NULL) { - /* - * Force something in the workqueue as a workaround - * for libuv bug - not sending uv_close callback. - */ - isc_nm_pause(nm); - isc_nm_resume(nm); - isc_nm_detach(&nm); - } - if (taskmgr != NULL) { - isc_taskmgr_destroy(&taskmgr); - } - if (netmgr != NULL) { - isc_nm_destroy(&netmgr); - } - if (timermgr != NULL) { - isc_timermgr_destroy(&timermgr); - } + + isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr); + if (app_running) { isc_app_finish(); } @@ -241,24 +222,18 @@ create_managers(void) { isc_event_t *event = NULL; ncpus = isc_os_ncpus(); - netmgr = isc_nm_start(mctx, ncpus); - CHECK(isc_taskmgr_create(mctx, 0, netmgr, &taskmgr)); + isc_managers_create(mctx, ncpus, 0, 0, &netmgr, &taskmgr, &timermgr, + &socketmgr); CHECK(isc_task_create(taskmgr, 0, &maintask)); isc_taskmgr_setexcltask(taskmgr, maintask); CHECK(isc_task_onshutdown(maintask, shutdown_managers, NULL)); - CHECK(isc_timermgr_create(mctx, &timermgr)); - - CHECK(isc_socketmgr_create(mctx, &socketmgr)); - - nm = isc_nm_start(mctx, ncpus); - CHECK(ns_server_create(mctx, matchview, &sctx)); CHECK(dns_dispatchmgr_create(mctx, &dispatchmgr)); CHECK(ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr, socketmgr, - nm, dispatchmgr, maintask, ncpus, NULL, + netmgr, dispatchmgr, maintask, ncpus, NULL, ncpus, &interfacemgr)); CHECK(ns_listenlist_default(mctx, port, -1, true, &listenon)); diff --git a/util/copyrights b/util/copyrights index 1e37f6a4c7..ba92b26e62 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1887,6 +1887,7 @@ ./lib/isc/include/isc/list.h C 1997,1998,1999,2000,2001,2002,2004,2006,2007,2011,2012,2013,2016,2018,2019,2020,2021 ./lib/isc/include/isc/log.h C 1999,2000,2001,2002,2004,2005,2006,2007,2009,2014,2016,2017,2018,2019,2020,2021 ./lib/isc/include/isc/magic.h C 1999,2000,2001,2004,2005,2006,2007,2016,2017,2018,2019,2020,2021 +./lib/isc/include/isc/managers.h C 2021 ./lib/isc/include/isc/md.h C 2018,2019,2020,2021 ./lib/isc/include/isc/mem.h C 1997,1998,1999,2000,2001,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2015,2016,2017,2018,2019,2020,2021 ./lib/isc/include/isc/meminfo.h C 2015,2016,2018,2019,2020,2021 @@ -1944,6 +1945,7 @@ ./lib/isc/lib.c C 1999,2000,2001,2004,2005,2007,2009,2013,2014,2015,2016,2018,2019,2020,2021 ./lib/isc/lib_p.h C 2021 ./lib/isc/log.c C 1999,2000,2001,2002,2003,2004,2005,2006,2007,2009,2011,2012,2013,2014,2016,2017,2018,2019,2020,2021 +./lib/isc/managers.c C 2021 ./lib/isc/md.c C 2018,2019,2020,2021 ./lib/isc/mem.c C 1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 ./lib/isc/mem_p.h C 2018,2019,2020,2021 @@ -1960,6 +1962,7 @@ ./lib/isc/netmgr/uv-compat.c C 2020,2021 ./lib/isc/netmgr/uv-compat.h C 2019,2020,2021 ./lib/isc/netmgr/uverr2result.c C 2019,2020,2021 +./lib/isc/netmgr_p.h C 2021 ./lib/isc/netscope.c C 2002,2004,2005,2006,2007,2016,2018,2019,2020,2021 ./lib/isc/nonce.c C 2018,2019,2020,2021 ./lib/isc/openssl_shim.c C 2018,2019,2020,2021 @@ -1989,10 +1992,12 @@ ./lib/isc/serial.c C 1999,2000,2001,2004,2005,2007,2016,2018,2019,2020,2021 ./lib/isc/siphash.c C 2019,2020,2021 ./lib/isc/sockaddr.c C 1999,2000,2001,2002,2003,2004,2005,2006,2007,2010,2011,2012,2014,2015,2016,2017,2018,2019,2020,2021 +./lib/isc/socket_p.h C 2021 ./lib/isc/stats.c C 2009,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 ./lib/isc/string.c C 1999,2000,2001,2003,2004,2005,2006,2007,2011,2012,2014,2015,2016,2018,2019,2020,2021 ./lib/isc/symtab.c C 1996,1997,1998,1999,2000,2001,2004,2005,2007,2011,2012,2013,2016,2018,2019,2020,2021 ./lib/isc/task.c C 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 +./lib/isc/task_p.h C 2021 ./lib/isc/taskpool.c C 1999,2000,2001,2004,2005,2007,2011,2012,2013,2016,2018,2019,2020,2021 ./lib/isc/tests/aes_test.c C 2014,2016,2018,2019,2020,2021 ./lib/isc/tests/buffer_test.c C 2014,2015,2016,2017,2018,2019,2020,2021 @@ -2031,6 +2036,7 @@ ./lib/isc/tests/timer_test.c C 2018,2019,2020,2021 ./lib/isc/tests/uv_wrap.h C 2020,2021 ./lib/isc/timer.c C 1998,1999,2000,2001,2002,2004,2005,2007,2008,2009,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 +./lib/isc/timer_p.h C 2021 ./lib/isc/tls.c C 2021 ./lib/isc/tls_p.h C 2021 ./lib/isc/tm.c C 2014,2016,2018,2019,2020,2021 @@ -2059,7 +2065,6 @@ ./lib/isc/unix/pk11_api.c C 2014,2016,2018,2019,2020,2021 ./lib/isc/unix/resource.c C 2000,2001,2004,2007,2008,2009,2016,2018,2019,2020,2021 ./lib/isc/unix/socket.c C 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021 -./lib/isc/unix/socket_p.h C 2000,2001,2004,2005,2007,2008,2009,2016,2018,2019,2020,2021 ./lib/isc/unix/stdio.c C 2000,2001,2004,2007,2011,2012,2013,2014,2016,2018,2019,2020,2021 ./lib/isc/unix/stdtime.c C 1999,2000,2001,2004,2005,2007,2016,2018,2019,2020,2021 ./lib/isc/unix/syslog.c C 2001,2004,2005,2007,2016,2018,2019,2020,2021