]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: simplify removal of idle conns from their trees
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 21 Aug 2023 12:24:17 +0000 (14:24 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 25 Aug 2023 13:57:48 +0000 (15:57 +0200)
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.

include/haproxy/connection.h
src/backend.c
src/connection.c
src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/server.c
src/ssl_sock.c

index 92b85afde4db530da5d5e8218f7990b3eff97fae..1d216571288660c58fe351c72b242777cf54885e 100644 (file)
@@ -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);
index a2deaed47d24679213beb4e3a9f274b364f5eafa..6be443a8bc03d3849e58173e332a0dec1e366ff9 100644 (file)
@@ -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);
                        }
 
index 8a7db3163727ed9f8ad362ddd1335a3123e9cbe6..df6c345fbe82a46af918ee2f851dfca4bd73eb94 100644 (file)
@@ -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);
                }
 
index a5a1924025ac05e9b532091a2d151d5470c57177..104668d2507c544ef953fd0df413a136dc4053d4 100644 (file)
@@ -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);
        }
index 023bdd9d3af05f1da230fadc9aa9eba878be8e62..b051e79e673c59c7e81377adb6ffac3909a611d3 100644 (file)
@@ -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);
        }
index deb2cc29734cc2caf0cf40a59187249dd9980292..7f99eded432e5295e7c6637648517b558cc0d989 100644 (file)
@@ -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);
        }
 
index 0f5d9d09222823829b7be86790317ffad7cdad64..38b3a28dd226f05fdcd6f265adcd67b7d079d17a 100644 (file)
@@ -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;
index 922c24cebe1d69ce1eb8bd60a72e0277223a52d0..c8c0638372e88d05ce5450ae02c2b42b3f9e85d2 100644 (file)
@@ -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;