From: Ondřej Surý Date: Thu, 23 Mar 2023 11:11:04 +0000 (+0100) Subject: Convert stopping UDP children to to isc_async callback X-Git-Tag: v9.19.12~66^2~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8cb4cfd9db524e61c61420fc2da3f917773b6d93;p=thirdparty%2Fbind9.git Convert stopping UDP children to to isc_async callback Simplify the stopping of the UDP 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 d9bc96cb48d..9af3da4447d 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -269,8 +269,6 @@ typedef enum isc__netievent_type { netievent_settlsctx, netievent_sockstop, /* for multilayer sockets */ - netievent_udpstop, - netievent_tcplisten, netievent_tcpstop, } isc__netievent_type; @@ -1236,8 +1234,6 @@ isc__nm_udp_settimeout(isc_nmhandle_t *handle, uint32_t timeout); * Set or clear the recv timeout for the UDP socket associated with 'handle'. */ -void -isc__nm_async_udpstop(isc__networker_t *worker, isc__netievent_t *ev0); void isc__nm_async_udpcancel(isc__networker_t *worker, isc__netievent_t *ev0); /*%< @@ -1705,7 +1701,6 @@ NETIEVENT_SOCKET_TYPE(tlsclose); /* NETIEVENT_SOCKET_TYPE(tlsconnect); */ /* unique type, defined independently */ NETIEVENT_SOCKET_TYPE(tlsdobio); -NETIEVENT_SOCKET_TYPE(udpstop); #ifdef HAVE_LIBNGHTTP2 NETIEVENT_SOCKET_REQ_TYPE(httpsend); @@ -1734,7 +1729,6 @@ NETIEVENT_SOCKET_DECL(tcpstop); NETIEVENT_SOCKET_DECL(tlsclose); NETIEVENT_SOCKET_DECL(tlsconnect); NETIEVENT_SOCKET_DECL(tlsdobio); -NETIEVENT_SOCKET_DECL(udpstop); #ifdef HAVE_LIBNGHTTP2 NETIEVENT_SOCKET_REQ_DECL(httpsend); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 9acb16c69b4..2e08db02189 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -439,7 +439,6 @@ process_netievent(void *arg) { isc__networker_t *worker = ievent->worker; switch (ievent->type) { - NETIEVENT_CASE(udpstop); NETIEVENT_CASE(udpcancel); NETIEVENT_CASE(tcpaccept); @@ -488,7 +487,6 @@ NETIEVENT_SOCKET_DEF(tcpstop); NETIEVENT_SOCKET_DEF(tlsclose); NETIEVENT_SOCKET_DEF(tlsconnect); NETIEVENT_SOCKET_DEF(tlsdobio); -NETIEVENT_SOCKET_DEF(udpstop); NETIEVENT_SOCKET_HANDLE_DEF(udpcancel); #ifdef HAVE_LIBNGHTTP2 diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index 55d8936ecf9..a443a1df40f 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -415,31 +415,34 @@ isc_nm_routeconnect(isc_nm_t *mgr, isc_nm_cb_t cb, void *cbarg) { #endif /* USE_ROUTE_SOCKET */ } +/* + * Asynchronous 'udpstop' call handler: stop listening on a UDP socket. + */ static void -stop_udp_child(isc_nmsocket_t *sock, uint32_t tid) { - isc_nmsocket_t *csock = NULL; - isc__netievent_udpstop_t *ievent = NULL; +stop_udp_child_job(void *arg) { + isc_nmsocket_t *sock = arg; + REQUIRE(VALID_NMSOCK(sock)); + REQUIRE(sock->tid == isc_tid()); + REQUIRE(sock->parent != NULL); - csock = &sock->children[tid]; - REQUIRE(VALID_NMSOCK(csock)); + isc__nm_udp_close(sock); - atomic_store(&csock->active, false); - ievent = isc__nm_get_netievent_udpstop(csock->worker, csock); + (void)atomic_fetch_sub(&sock->parent->rchildren, 1); - if (tid == 0) { - isc__nm_process_ievent(csock->worker, - (isc__netievent_t *)ievent); - } else { - isc__nm_enqueue_ievent(csock->worker, - (isc__netievent_t *)ievent); - } + REQUIRE(!sock->worker->loop->paused); + isc_barrier_wait(&sock->parent->stop_barrier); } static void -stop_udp_parent(isc_nmsocket_t *sock) { - /* Stop the parent */ - atomic_store(&sock->closed, true); - isc__nmsocket_prep_destroy(sock); +stop_udp_child(isc_nmsocket_t *sock) { + REQUIRE(VALID_NMSOCK(sock)); + + atomic_store(&sock->active, false); + if (sock->tid == 0) { + stop_udp_child_job(sock); + } else { + isc_async_run(sock->worker->loop, stop_udp_child_job, sock); + } } void @@ -452,36 +455,20 @@ isc__nm_udp_stoplistening(isc_nmsocket_t *sock) { RUNTIME_CHECK(atomic_compare_exchange_strong(&sock->closing, &(bool){ false }, true)); - /* Stop all the children */ + /* Mark the parent socket inactive */ + atomic_store(&sock->active, false); + + /* Stop all the other threads' children */ for (size_t i = 1; i < sock->nchildren; i++) { - stop_udp_child(sock, i); + stop_udp_child(&sock->children[i]); } - stop_udp_child(sock, 0); + /* Stop the child for the main thread */ + stop_udp_child(&sock->children[0]); - stop_udp_parent(sock); -} - -/* - * Asynchronous 'udpstop' call handler: stop listening on a UDP socket. - */ -void -isc__nm_async_udpstop(isc__networker_t *worker, isc__netievent_t *ev0) { - isc__netievent_udpstop_t *ievent = (isc__netievent_udpstop_t *)ev0; - isc_nmsocket_t *sock = ievent->sock; - - UNUSED(worker); - - REQUIRE(VALID_NMSOCK(sock)); - REQUIRE(sock->tid == isc_tid()); - REQUIRE(sock->parent != NULL); - - isc__nm_udp_close(sock); - - (void)atomic_fetch_sub(&sock->parent->rchildren, 1); - - REQUIRE(!worker->loop->paused); - isc_barrier_wait(&sock->parent->stop_barrier); + /* Stop the parent */ + atomic_store(&sock->closed, true); + isc__nmsocket_prep_destroy(sock); } /*