From: Amaury Denoyelle Date: Mon, 21 Aug 2023 12:24:17 +0000 (+0200) Subject: MINOR: connection: simplify removal of idle conns from their trees X-Git-Tag: v2.9-dev4~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=77ac8eb4a6d0337d83fbd4448a1ed62988d4610a;p=thirdparty%2Fhaproxy.git MINOR: connection: simplify removal of idle conns from their trees Small change of API for conn_delete_from_tree(). Now the connection instance is taken as argument instead of its inner node. No functional change introduced with this commit. This simplifies slightly invocation of conn_delete_from_tree(). The most useful changes is that this function will be extended in the next patch to be able to remove the connection from its new idle list at the same time as in its idle tree. --- diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h index 92b85afde4..1d21657128 100644 --- a/include/haproxy/connection.h +++ b/include/haproxy/connection.h @@ -81,7 +81,7 @@ int conn_install_mux_be(struct connection *conn, void *ctx, struct session *sess const struct mux_ops *force_mux_ops); int conn_install_mux_chk(struct connection *conn, void *ctx, struct session *sess); -void conn_delete_from_tree(struct eb64_node *node); +void conn_delete_from_tree(struct connection *conn); void conn_init(struct connection *conn, void *target); struct connection *conn_new(void *target); diff --git a/src/backend.c b/src/backend.c index a2deaed47d..6be443a8bc 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1163,7 +1163,7 @@ static struct connection *conn_backend_get(struct stream *s, struct server *srv, HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); conn = srv_lookup_conn(is_safe ? &srv->per_thr[tid].safe_conns : &srv->per_thr[tid].idle_conns, hash); if (conn) - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); /* If we failed to pick a connection from the idle list, let's try again with * the safe list. @@ -1171,7 +1171,7 @@ static struct connection *conn_backend_get(struct stream *s, struct server *srv, if (!conn && !is_safe && srv->curr_safe_nb > 0) { conn = srv_lookup_conn(&srv->per_thr[tid].safe_conns, hash); if (conn) { - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); is_safe = 1; } } @@ -1214,7 +1214,7 @@ static struct connection *conn_backend_get(struct stream *s, struct server *srv, conn = srv_lookup_conn(is_safe ? &srv->per_thr[i].safe_conns : &srv->per_thr[i].idle_conns, hash); while (conn) { if (conn->mux->takeover && conn->mux->takeover(conn, i) == 0) { - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); _HA_ATOMIC_INC(&activity[tid].fd_takeover); found = 1; break; @@ -1227,7 +1227,7 @@ static struct connection *conn_backend_get(struct stream *s, struct server *srv, conn = srv_lookup_conn(&srv->per_thr[i].safe_conns, hash); while (conn) { if (conn->mux->takeover && conn->mux->takeover(conn, i) == 0) { - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); _HA_ATOMIC_INC(&activity[tid].fd_takeover); found = 1; is_safe = 1; @@ -1504,7 +1504,7 @@ static int connect_server(struct stream *s) if (node) { conn_node = ebmb_entry(node, struct conn_hash_node, node); tokill_conn = conn_node->conn; - ebmb_delete(node); + conn_delete_from_tree(tokill_conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); /* Release the idle lock before calling mux->destroy. @@ -1535,7 +1535,7 @@ static int connect_server(struct stream *s) if (node) { conn_node = ebmb_entry(node, struct conn_hash_node, node); tokill_conn = conn_node->conn; - ebmb_delete(node); + conn_delete_from_tree(tokill_conn); } if (!tokill_conn) { @@ -1543,7 +1543,7 @@ static int connect_server(struct stream *s) if (node) { conn_node = ebmb_entry(node, struct conn_hash_node, node); tokill_conn = conn_node->conn; - ebmb_delete(node); + conn_delete_from_tree(tokill_conn); } } HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[i].idle_conns_lock); @@ -1568,7 +1568,7 @@ static int connect_server(struct stream *s) if (avail <= 1) { /* No more streams available, remove it from the list */ HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); - conn_delete_from_tree(&srv_conn->hash_node->node); + conn_delete_from_tree(srv_conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } diff --git a/src/connection.c b/src/connection.c index 8a7db31637..df6c345fbe 100644 --- a/src/connection.c +++ b/src/connection.c @@ -52,9 +52,9 @@ struct mux_stopping_data mux_stopping_data[MAX_THREADS]; /* disables sending of proxy-protocol-v2's LOCAL command */ static int pp2_never_send_local; -void conn_delete_from_tree(struct eb64_node *node) +void conn_delete_from_tree(struct connection *conn) { - eb64_delete(node); + eb64_delete(&conn->hash_node->node); } int conn_create_mux(struct connection *conn) @@ -168,7 +168,7 @@ int conn_notify_mux(struct connection *conn, int old_flags, int forced_wake) if (conn_in_list) { HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index a5a1924025..104668d250 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -2957,7 +2957,7 @@ struct task *fcgi_io_cb(struct task *t, void *ctx, unsigned int state) conn_in_list = conn_get_idle_flag(conn); if (conn_in_list) - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } else { @@ -3139,7 +3139,7 @@ struct task *fcgi_timeout_task(struct task *t, void *context, unsigned int state * to steal it from us. */ if (fconn->conn->flags & CO_FL_LIST_MASK) - conn_delete_from_tree(&fconn->conn->hash_node->node); + conn_delete_from_tree(fconn->conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } diff --git a/src/mux_h1.c b/src/mux_h1.c index 023bdd9d3a..b051e79e67 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -3672,7 +3672,7 @@ struct task *h1_io_cb(struct task *t, void *ctx, unsigned int state) */ conn_in_list = conn_get_idle_flag(conn); if (conn_in_list) - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } else { @@ -3794,7 +3794,7 @@ struct task *h1_timeout_task(struct task *t, void *context, unsigned int state) * to steal it from us. */ if (h1c->conn->flags & CO_FL_LIST_MASK) - conn_delete_from_tree(&h1c->conn->hash_node->node); + conn_delete_from_tree(h1c->conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } diff --git a/src/mux_h2.c b/src/mux_h2.c index deb2cc2973..7f99eded43 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -4094,7 +4094,7 @@ struct task *h2_io_cb(struct task *t, void *ctx, unsigned int state) */ conn_in_list = conn_get_idle_flag(conn); if (conn_in_list) - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } else { @@ -4223,7 +4223,7 @@ static int h2_process(struct h2c *h2c) /* connections in error must be removed from the idle lists */ if (conn->flags & CO_FL_LIST_MASK) { HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } } @@ -4231,7 +4231,7 @@ static int h2_process(struct h2c *h2c) /* connections in error must be removed from the idle lists */ if (conn->flags & CO_FL_LIST_MASK) { HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } } @@ -4323,7 +4323,7 @@ struct task *h2_timeout_task(struct task *t, void *context, unsigned int state) * to steal it from us. */ if (h2c->conn->flags & CO_FL_LIST_MASK) - conn_delete_from_tree(&h2c->conn->hash_node->node); + conn_delete_from_tree(h2c->conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } @@ -4375,7 +4375,7 @@ do_leave: /* in any case this connection must not be considered idle anymore */ if (h2c->conn->flags & CO_FL_LIST_MASK) { HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); - conn_delete_from_tree(&h2c->conn->hash_node->node); + conn_delete_from_tree(h2c->conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } diff --git a/src/server.c b/src/server.c index 0f5d9d0922..38b3a28dd2 100644 --- a/src/server.c +++ b/src/server.c @@ -5944,7 +5944,7 @@ void srv_release_conn(struct server *srv, struct connection *conn) /* Remove the connection from any tree (safe, idle or available) */ if (conn->hash_node) { HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); conn->flags &= ~CO_FL_LIST_MASK; HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } @@ -6018,7 +6018,7 @@ int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_saf _HA_ATOMIC_DEC(&srv->curr_used_conns); HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); if (is_safe) { conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST; diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 922c24cebe..c8c0638372 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -6285,7 +6285,7 @@ struct task *ssl_sock_io_cb(struct task *t, void *context, unsigned int state) conn = ctx->conn; conn_in_list = conn_get_idle_flag(conn); if (conn_in_list) - conn_delete_from_tree(&conn->hash_node->node); + conn_delete_from_tree(conn); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); } else { conn = ctx->conn;