]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: move idle tree insert in a dedicated function
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 25 Aug 2023 13:48:39 +0000 (15:48 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 25 Aug 2023 13:57:48 +0000 (15:57 +0200)
Define a new function _srv_add_idle(). This is a simple wrapper to
insert a connection in the server idle tree. This is reserved for simple
usage and require to idle_conns lock. In most cases,
srv_add_to_idle_list() should be used.

This patch does not have any functional change. However, it will help
with the next patch as idle connection will be always inserted in a list
as secondary storage along with idle/safe trees.

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

index 730493362d1dbc02a1999a7a85487b9cba54db9c..b5923af69b50d8353950255db3ddb6e44d16e089 100644 (file)
@@ -85,6 +85,7 @@ void srv_release_conn(struct server *srv, struct connection *conn);
 struct connection *srv_lookup_conn(struct eb_root *tree, uint64_t hash);
 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);
 struct task *srv_cleanup_toremove_conns(struct task *task, void *context, unsigned int state);
 
index df6c345fbe82a46af918ee2f851dfca4bd73eb94..46d942c4511e4eaa9e3728bf0243c3f7c7d0badd 100644 (file)
@@ -177,12 +177,8 @@ int conn_notify_mux(struct connection *conn, int old_flags, int forced_wake)
                        goto done;
 
                if (conn_in_list) {
-                       struct eb_root *root = (conn_in_list == CO_FL_SAFE_LIST) ?
-                               &srv->per_thr[tid].safe_conns :
-                               &srv->per_thr[tid].idle_conns;
-
                        HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-                       eb64_insert(root, &conn->hash_node->node);
+                       _srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
                        HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
                }
        }
index 104668d2507c544ef953fd0df413a136dc4053d4..ec2cb60dcf0921354adc919bd6998beefbe1a796 100644 (file)
@@ -2986,10 +2986,7 @@ struct task *fcgi_io_cb(struct task *t, void *ctx, unsigned int state)
                struct server *srv = objt_server(conn->target);
 
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-               if (conn_in_list == CO_FL_SAFE_LIST)
-                       eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
-               else
-                       eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
+               _srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
        }
        return t;
index b051e79e673c59c7e81377adb6ffac3909a611d3..9b68e25c24ccbbf5bba32790bdc52653cd91d935 100644 (file)
@@ -3701,10 +3701,7 @@ struct task *h1_io_cb(struct task *t, void *ctx, unsigned int state)
                struct server *srv = objt_server(conn->target);
 
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-               if (conn_in_list == CO_FL_SAFE_LIST)
-                       eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
-               else
-                       eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
+               _srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
        }
        return t;
index 7f99eded432e5295e7c6637648517b558cc0d989..6d5b43467d0a267690ce78629260a85a3653490c 100644 (file)
@@ -4123,10 +4123,7 @@ struct task *h2_io_cb(struct task *t, void *ctx, unsigned int state)
                struct server *srv = objt_server(conn->target);
 
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-               if (conn_in_list == CO_FL_SAFE_LIST)
-                       eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
-               else
-                       eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
+               _srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
        }
 
index 38b3a28dd226f05fdcd6f265adcd67b7d079d17a..a51d597d88bd71d30d9c4a8b592f6dd4deae1dc7 100644 (file)
@@ -5986,6 +5986,23 @@ struct connection *srv_lookup_conn_next(struct connection *conn)
        return next_conn;
 }
 
+/* Add <conn> in <srv> idle trees. Set <is_safe> if connection is deemed safe
+ * for reuse.
+ *
+ * This function is a simple wrapper for tree insert. It should only be used
+ * for internal usage or when removing briefly the connection to avoid takeover
+ * on it before reinserting it with this function. In other context, prefer to
+ * use the full feature srv_add_to_idle_list().
+ *
+ * Must be called with idle_conns_lock.
+ */
+void _srv_add_idle(struct server *srv, struct connection *conn, int is_safe)
+{
+       struct eb_root *tree = is_safe ? &srv->per_thr[tid].safe_conns :
+                                        &srv->per_thr[tid].idle_conns;
+       eb64_insert(tree, &conn->hash_node->node);
+}
+
 /* This adds an idle connection to the server's list if the connection is
  * reusable, not held by any owner anymore, but still has available streams.
  */
@@ -6022,11 +6039,11 @@ int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_saf
 
                if (is_safe) {
                        conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST;
-                       eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
+                       _srv_add_idle(srv, conn, 1);
                        _HA_ATOMIC_INC(&srv->curr_safe_nb);
                } else {
                        conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_IDLE_LIST;
-                       eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
+                       _srv_add_idle(srv, conn, 0);
                        _HA_ATOMIC_INC(&srv->curr_idle_nb);
                }
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
index c8c0638372e88d05ce5450ae02c2b42b3f9e85d2..9cc8166a595ea546d0e36cfe6a08c553165ef03a 100644 (file)
@@ -6345,10 +6345,7 @@ leave:
                struct server *srv = objt_server(conn->target);
 
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
-               if (conn_in_list == CO_FL_SAFE_LIST)
-                       eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
-               else
-                       eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
+               _srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
                HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
        }
        return t;