From: Ondřej Surý Date: Thu, 23 Mar 2023 11:34:49 +0000 (+0100) Subject: Convert stopping TCP children to to isc_async callback X-Git-Tag: v9.19.12~66^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4419848efd87f9a70857488d0588922a858ba350;p=thirdparty%2Fbind9.git Convert stopping TCP children to to isc_async callback Simplify the stopping of the TCP children by using the isc_async API from the loopmgr instead of using the asychronous netievent mechanism in the netmgr. --- diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 585382a3355..345f477295c 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -268,8 +268,6 @@ typedef enum isc__netievent_type { netievent_settlsctx, netievent_sockstop, /* for multilayer sockets */ - - netievent_tcpstop, } isc__netievent_type; typedef union { @@ -1293,8 +1291,6 @@ isc__nmhandle_tcp_set_manual_timer(isc_nmhandle_t *handle, const bool manual); void isc__nm_async_tcpaccept(isc__networker_t *worker, isc__netievent_t *ev0); -void -isc__nm_async_tcpstop(isc__networker_t *worker, isc__netievent_t *ev0); /*%< * Callback handlers for asynchronous TCP events (connect, listen, * stoplisten, send, read, pause, close). @@ -1692,7 +1688,6 @@ isc__nmsocket_stop(isc_nmsocket_t *listener); * typedef all the netievent types */ -NETIEVENT_SOCKET_TYPE(tcpstop); NETIEVENT_SOCKET_TYPE(tlsclose); /* NETIEVENT_SOCKET_TYPE(tlsconnect); */ /* unique type, defined independently */ @@ -1720,7 +1715,6 @@ NETIEVENT_SOCKET_TYPE(sockstop); /* Now declared the helper functions */ -NETIEVENT_SOCKET_DECL(tcpstop); NETIEVENT_SOCKET_DECL(tlsclose); NETIEVENT_SOCKET_DECL(tlsconnect); NETIEVENT_SOCKET_DECL(tlsdobio); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index ad94c121ab2..ba4a712b01a 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -442,7 +442,6 @@ process_netievent(void *arg) { NETIEVENT_CASE(udpcancel); NETIEVENT_CASE(tcpaccept); - NETIEVENT_CASE(tcpstop); NETIEVENT_CASE(tlssend); NETIEVENT_CASE(tlsclose); @@ -481,7 +480,6 @@ isc__nm_put_netievent(isc__networker_t *worker, void *ievent) { isc__networker_unref(worker); } -NETIEVENT_SOCKET_DEF(tcpstop); NETIEVENT_SOCKET_DEF(tlsclose); NETIEVENT_SOCKET_DEF(tlsconnect); NETIEVENT_SOCKET_DEF(tlsdobio); diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index 44a2ae7e854..2cc936009a7 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -582,23 +582,52 @@ done: isc__nm_accept_connection_log(ssock, result, can_log_tcp_quota()); } +static void +stop_tcp_child_job(void *arg) { + isc_nmsocket_t *sock = arg; + + REQUIRE(VALID_NMSOCK(sock)); + REQUIRE(sock->tid == isc_tid()); + REQUIRE(sock->parent != NULL); + REQUIRE(sock->type == isc_nm_tcpsocket); + + RUNTIME_CHECK(atomic_compare_exchange_strong(&sock->closing, + &(bool){ false }, true)); + + /* + * The order of the close operation is important here, the uv_close() + * gets scheduled in the reverse order, so we need to close the timer + * last, so its gone by the time we destroy the socket + */ + + /* 2. close the listening socket */ + isc__nmsocket_clearcb(sock); + isc__nm_stop_reading(sock); + uv_close(&sock->uv_handle.handle, tcp_stop_cb); + + /* 1. close the read timer */ + isc__nmsocket_timer_stop(sock); + uv_close(&sock->read_timer, NULL); + + (void)atomic_fetch_sub(&sock->parent->rchildren, 1); + + REQUIRE(!sock->worker->loop->paused); + isc_barrier_wait(&sock->parent->stop_barrier); +} + static void stop_tcp_child(isc_nmsocket_t *sock, uint32_t tid) { isc_nmsocket_t *csock = NULL; - isc__netievent_tcpstop_t *ievent = NULL; csock = &sock->children[tid]; REQUIRE(VALID_NMSOCK(csock)); atomic_store(&csock->active, false); - ievent = isc__nm_get_netievent_tcpstop(csock->worker, csock); if (tid == 0) { - isc__nm_process_ievent(csock->worker, - (isc__netievent_t *)ievent); + stop_tcp_child_job(csock); } else { - isc__nm_enqueue_ievent(csock->worker, - (isc__netievent_t *)ievent); + isc_async_run(csock->worker->loop, stop_tcp_child_job, csock); } } @@ -648,42 +677,6 @@ tcp_stop_cb(uv_handle_t *handle) { isc__nmsocket_detach(&sock); } -void -isc__nm_async_tcpstop(isc__networker_t *worker, isc__netievent_t *ev0) { - isc__netievent_tcpstop_t *ievent = (isc__netievent_tcpstop_t *)ev0; - isc_nmsocket_t *sock = ievent->sock; - - UNUSED(worker); - - REQUIRE(VALID_NMSOCK(sock)); - REQUIRE(sock->tid == isc_tid()); - REQUIRE(sock->parent != NULL); - REQUIRE(sock->type == isc_nm_tcpsocket); - - RUNTIME_CHECK(atomic_compare_exchange_strong(&sock->closing, - &(bool){ false }, true)); - - /* - * The order of the close operation is important here, the uv_close() - * gets scheduled in the reverse order, so we need to close the timer - * last, so its gone by the time we destroy the socket - */ - - /* 2. close the listening socket */ - isc__nmsocket_clearcb(sock); - isc__nm_stop_reading(sock); - uv_close(&sock->uv_handle.handle, tcp_stop_cb); - - /* 1. close the read timer */ - isc__nmsocket_timer_stop(sock); - uv_close(&sock->read_timer, NULL); - - (void)atomic_fetch_sub(&sock->parent->rchildren, 1); - - REQUIRE(!worker->loop->paused); - isc_barrier_wait(&sock->parent->stop_barrier); -} - void isc__nm_tcp_failed_read_cb(isc_nmsocket_t *sock, isc_result_t result, bool async) {