]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: backend: refactor insertion in avail conns tree
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 25 Oct 2023 08:10:14 +0000 (10:10 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 25 Oct 2023 08:33:06 +0000 (10:33 +0200)
Define a new function srv_add_to_avail_list(). This function is used to
centralize connection insertion in available tree. It reuses a BUG_ON()
statement to ensure the connection is not present in the idle list.

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

index b5923af69b50d8353950255db3ddb6e44d16e089..8b523bf0619b75e50c25a2287da54da0feaeeb1e 100644 (file)
@@ -87,6 +87,7 @@ struct connection *srv_lookup_conn_next(struct connection *conn);
 
 void _srv_add_idle(struct server *srv, struct connection *conn, int is_safe);
 int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_safe);
+void srv_add_to_avail_list(struct server *srv, struct connection *conn);
 struct task *srv_cleanup_toremove_conns(struct task *task, void *context, unsigned int state);
 
 int srv_apply_track(struct server *srv, struct proxy *curproxy);
index 359bd499fedc6c9e6bea8bb69081b9343516efe9..a90dd905f649d28f224261e345f9ee1b4df22f73 100644 (file)
@@ -1276,8 +1276,7 @@ static struct connection *conn_backend_get(struct stream *s, struct server *srv,
                        session_add_conn(s->sess, conn, conn->target);
                }
                else {
-                       eb64_insert(&srv->per_thr[tid].avail_conns,
-                                   &conn->hash_node->node);
+                       srv_add_to_avail_list(srv, conn);
                }
        }
        return conn;
@@ -1781,7 +1780,7 @@ skip_reuse:
                        if (srv && reuse_mode == PR_O_REUSE_ALWS &&
                            !(srv_conn->flags & CO_FL_PRIVATE) &&
                            srv_conn->mux->avail_streams(srv_conn) > 0) {
-                               eb64_insert(&srv->per_thr[tid].avail_conns, &srv_conn->hash_node->node);
+                               srv_add_to_avail_list(srv, srv_conn);
                        }
                        else if (srv_conn->flags & CO_FL_PRIVATE ||
                                 (reuse_mode == PR_O_REUSE_SAFE &&
index a7ab6f6084f9f58d5d87a827ba2f78032b7d87bd..59893fbb58ea8e57fb43a969f347a608daecc967 100644 (file)
@@ -29,6 +29,7 @@
 #include <haproxy/proto_tcp.h>
 #include <haproxy/sample.h>
 #include <haproxy/sc_strm.h>
+#include <haproxy/server.h>
 #include <haproxy/session.h>
 #include <haproxy/ssl_sock.h>
 #include <haproxy/stconn.h>
@@ -107,8 +108,9 @@ int conn_create_mux(struct connection *conn)
                 * server list.
                 */
                if (srv && ((srv->proxy->options & PR_O_REUSE_MASK) == PR_O_REUSE_ALWS) &&
-                   !(conn->flags & CO_FL_PRIVATE) && conn->mux->avail_streams(conn) > 0)
-                       eb64_insert(&srv->per_thr[tid].avail_conns, &conn->hash_node->node);
+                   !(conn->flags & CO_FL_PRIVATE) && conn->mux->avail_streams(conn) > 0) {
+                       srv_add_to_avail_list(srv, conn);
+               }
                else if (conn->flags & CO_FL_PRIVATE) {
                        /* If it fail now, the same will be done in mux->detach() callback */
                        session_add_conn(sess, conn, conn->target);
index ac2f9cc385b32a27a0cb2f5becb1cc29310456e0..f14de49754f824c668c9ca8e5256ad9c3602718d 100644 (file)
@@ -32,6 +32,7 @@
 #include <haproxy/proxy.h>
 #include <haproxy/regex.h>
 #include <haproxy/sc_strm.h>
+#include <haproxy/server.h>
 #include <haproxy/session-t.h>
 #include <haproxy/stconn.h>
 #include <haproxy/stream.h>
@@ -3603,8 +3604,7 @@ static void fcgi_detach(struct sedesc *sd)
                        else if (!fconn->conn->hash_node->node.node.leaf_p &&
                                 fcgi_avail_streams(fconn->conn) > 0 && objt_server(fconn->conn->target) &&
                                 !LIST_INLIST(&fconn->conn->session_list)) {
-                               eb64_insert(&__objt_server(fconn->conn->target)->per_thr[tid].avail_conns,
-                                           &fconn->conn->hash_node->node);
+                               srv_add_to_avail_list(__objt_server(fconn->conn->target), fconn->conn);
                        }
                }
        }
index e6e1b6da857fca27b42f5b12bebb8ca31d164b7b..785fbd9cdc5147fc689a06a1435daaae95873689 100644 (file)
@@ -27,6 +27,7 @@
 #include <haproxy/mux_h2-t.h>
 #include <haproxy/net_helper.h>
 #include <haproxy/proxy.h>
+#include <haproxy/server.h>
 #include <haproxy/session-t.h>
 #include <haproxy/stats.h>
 #include <haproxy/stconn.h>
@@ -4651,8 +4652,7 @@ static void h2_detach(struct sedesc *sd)
                                else if (!h2c->conn->hash_node->node.node.leaf_p &&
                                         h2_avail_streams(h2c->conn) > 0 && objt_server(h2c->conn->target) &&
                                         !LIST_INLIST(&h2c->conn->session_list)) {
-                                       eb64_insert(&__objt_server(h2c->conn->target)->per_thr[tid].avail_conns,
-                                                   &h2c->conn->hash_node->node);
+                                       srv_add_to_avail_list(__objt_server(h2c->conn->target), h2c->conn);
                                }
                        }
                }
index 37e8beba0b802513052e13c649db29033776ae6f..4873c1438a135e605a894c9dbfc301844e79470a 100644 (file)
@@ -6136,6 +6136,16 @@ int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_saf
        return 0;
 }
 
+/* Insert <conn> connection in <srv> server available list. This is reserved
+ * for backend connection currently in used with usable streams left.
+ */
+void srv_add_to_avail_list(struct server *srv, struct connection *conn)
+{
+       /* connection cannot be in idle list if used as an avail idle conn. */
+       BUG_ON(LIST_INLIST(&conn->idle_list));
+       eb64_insert(&srv->per_thr[tid].avail_conns, &conn->hash_node->node);
+}
+
 struct task *srv_cleanup_idle_conns(struct task *task, void *context, unsigned int state)
 {
        struct server *srv;