]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: pass the server and thread to srv_migrate_conns_to_remove()
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Sep 2025 14:24:16 +0000 (16:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 07:23:46 +0000 (09:23 +0200)
We'll need to have access to the srv_per_thread element soon from this
function, and there's no particular reason for passing it list pointers
so let's pass the server and the thread so that it is autonomous. It
also makes the calling code simpler.

src/server.c

index 8cbda7ef89cb3f13dddb432d70d1f0509c6c97fc..dbd60cdbdf43d505c5942dadeee518a389ae8949 100644 (file)
@@ -7169,25 +7169,27 @@ struct task *srv_cleanup_toremove_conns(struct task *task, void *context, unsign
        return task;
 }
 
-/* Move <toremove_nb> count connections from <list> storage to <toremove_list>
- * list storage. -1 means moving all of them.
+/* Move <toremove_nb> count connections from server <srv> list storage
+ * ->idle_conn_list to the idle_conns list 'toremove_conns' for thread <thr>.
+ * -1 means moving all of them.
  *
  * Returns the number of connections moved.
  *
  * Must be called with idle_conns_lock held.
  */
-static int srv_migrate_conns_to_remove(struct list *list, struct mt_list *toremove_list, int toremove_nb)
+
+static int srv_migrate_conns_to_remove(struct server *srv, int thr, int toremove_nb)
 {
        struct connection *conn;
        int i = 0;
 
-       while (!LIST_ISEMPTY(list)) {
+       while (!LIST_ISEMPTY(&srv->per_thr[thr].idle_conn_list)) {
                if (toremove_nb != -1 && i >= toremove_nb)
                        break;
 
-               conn = LIST_ELEM(list->n, struct connection *, idle_list);
+               conn = LIST_ELEM(srv->per_thr[thr].idle_conn_list.n, struct connection *, idle_list);
                conn_delete_from_tree(conn);
-               MT_LIST_APPEND(toremove_list, &conn->toremove_list);
+               MT_LIST_APPEND(&idle_conns[thr].toremove_conns, &conn->toremove_list);
                i++;
        }
 
@@ -7212,7 +7214,7 @@ static void srv_cleanup_connections(struct server *srv)
                HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[i].idle_conns_lock);
 
                /* idle connections */
-               if (srv_migrate_conns_to_remove(&srv->per_thr[i].idle_conn_list, &idle_conns[i].toremove_conns, -1) > 0)
+               if (srv_migrate_conns_to_remove(srv, i, -1) > 0)
                        did_remove = 1;
 
                /* session attached connections */
@@ -7466,7 +7468,7 @@ struct task *srv_cleanup_idle_conns(struct task *task, void *context, unsigned i
                                   curr_idle + 1;
 
                        HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[i].idle_conns_lock);
-                       j = srv_migrate_conns_to_remove(&srv->per_thr[i].idle_conn_list, &idle_conns[i].toremove_conns, max_conn);
+                       j = srv_migrate_conns_to_remove(srv, i, max_conn);
                        if (j > 0)
                                did_remove = 1;
                        HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[i].idle_conns_lock);