]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Convert stopping TCP children to to isc_async callback
authorOndřej Surý <ondrej@isc.org>
Thu, 23 Mar 2023 11:34:49 +0000 (12:34 +0100)
committerOndřej Surý <ondrej@isc.org>
Fri, 24 Mar 2023 06:58:52 +0000 (07:58 +0100)
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.

lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tcp.c

index 585382a335526a8f4369de2ec69d5ce2b0e02c74..345f477295c8310b27a23efcae100fe6e4ab709c 100644 (file)
@@ -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);
index ad94c121ab230eda1c0c3a6591f788342a2653cb..ba4a712b01ad7ca7ee80697ee45aa40bf8e74e2b 100644 (file)
@@ -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);
index 44a2ae7e85448d950bd6cfba868ecf4144ffa69d..2cc936009a7e760f1ea29e6a958c2789232cd17f 100644 (file)
@@ -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) {