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.
This commit is contained in:
Amaury Denoyelle 2023-08-21 14:24:17 +02:00
parent f20f85f4d7
commit 77ac8eb4a6
8 changed files with 24 additions and 24 deletions

View 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); const struct mux_ops *force_mux_ops);
int conn_install_mux_chk(struct connection *conn, void *ctx, struct session *sess); 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); void conn_init(struct connection *conn, void *target);
struct connection *conn_new(void *target); struct connection *conn_new(void *target);

View 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); 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); conn = srv_lookup_conn(is_safe ? &srv->per_thr[tid].safe_conns : &srv->per_thr[tid].idle_conns, hash);
if (conn) 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 /* If we failed to pick a connection from the idle list, let's try again with
* the safe list. * 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) { if (!conn && !is_safe && srv->curr_safe_nb > 0) {
conn = srv_lookup_conn(&srv->per_thr[tid].safe_conns, hash); conn = srv_lookup_conn(&srv->per_thr[tid].safe_conns, hash);
if (conn) { if (conn) {
conn_delete_from_tree(&conn->hash_node->node); conn_delete_from_tree(conn);
is_safe = 1; 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); conn = srv_lookup_conn(is_safe ? &srv->per_thr[i].safe_conns : &srv->per_thr[i].idle_conns, hash);
while (conn) { while (conn) {
if (conn->mux->takeover && conn->mux->takeover(conn, i) == 0) { 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); _HA_ATOMIC_INC(&activity[tid].fd_takeover);
found = 1; found = 1;
break; 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); conn = srv_lookup_conn(&srv->per_thr[i].safe_conns, hash);
while (conn) { while (conn) {
if (conn->mux->takeover && conn->mux->takeover(conn, i) == 0) { 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); _HA_ATOMIC_INC(&activity[tid].fd_takeover);
found = 1; found = 1;
is_safe = 1; is_safe = 1;
@ -1504,7 +1504,7 @@ static int connect_server(struct stream *s)
if (node) { if (node) {
conn_node = ebmb_entry(node, struct conn_hash_node, node); conn_node = ebmb_entry(node, struct conn_hash_node, node);
tokill_conn = conn_node->conn; 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
/* Release the idle lock before calling mux->destroy. /* Release the idle lock before calling mux->destroy.
@ -1535,7 +1535,7 @@ static int connect_server(struct stream *s)
if (node) { if (node) {
conn_node = ebmb_entry(node, struct conn_hash_node, node); conn_node = ebmb_entry(node, struct conn_hash_node, node);
tokill_conn = conn_node->conn; tokill_conn = conn_node->conn;
ebmb_delete(node); conn_delete_from_tree(tokill_conn);
} }
if (!tokill_conn) { if (!tokill_conn) {
@ -1543,7 +1543,7 @@ static int connect_server(struct stream *s)
if (node) { if (node) {
conn_node = ebmb_entry(node, struct conn_hash_node, node); conn_node = ebmb_entry(node, struct conn_hash_node, node);
tokill_conn = conn_node->conn; 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); 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) { if (avail <= 1) {
/* No more streams available, remove it from the list */ /* No more streams available, remove it from the list */
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} }

View File

@ -52,9 +52,9 @@ struct mux_stopping_data mux_stopping_data[MAX_THREADS];
/* disables sending of proxy-protocol-v2's LOCAL command */ /* disables sending of proxy-protocol-v2's LOCAL command */
static int pp2_never_send_local; 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) 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) { if (conn_in_list) {
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} }

View 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); conn_in_list = conn_get_idle_flag(conn);
if (conn_in_list) 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} else { } else {
@ -3139,7 +3139,7 @@ struct task *fcgi_timeout_task(struct task *t, void *context, unsigned int state
* to steal it from us. * to steal it from us.
*/ */
if (fconn->conn->flags & CO_FL_LIST_MASK) 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} }

View 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); conn_in_list = conn_get_idle_flag(conn);
if (conn_in_list) 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} else { } else {
@ -3794,7 +3794,7 @@ struct task *h1_timeout_task(struct task *t, void *context, unsigned int state)
* to steal it from us. * to steal it from us.
*/ */
if (h1c->conn->flags & CO_FL_LIST_MASK) 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} }

View 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); conn_in_list = conn_get_idle_flag(conn);
if (conn_in_list) 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} else { } else {
@ -4223,7 +4223,7 @@ static int h2_process(struct h2c *h2c)
/* connections in error must be removed from the idle lists */ /* connections in error must be removed from the idle lists */
if (conn->flags & CO_FL_LIST_MASK) { if (conn->flags & CO_FL_LIST_MASK) {
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); 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); 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 */ /* connections in error must be removed from the idle lists */
if (conn->flags & CO_FL_LIST_MASK) { if (conn->flags & CO_FL_LIST_MASK) {
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); 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); 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. * to steal it from us.
*/ */
if (h2c->conn->flags & CO_FL_LIST_MASK) 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); 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 */ /* in any case this connection must not be considered idle anymore */
if (h2c->conn->flags & CO_FL_LIST_MASK) { if (h2c->conn->flags & CO_FL_LIST_MASK) {
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} }

View 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) */ /* Remove the connection from any tree (safe, idle or available) */
if (conn->hash_node) { if (conn->hash_node) {
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); 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; conn->flags &= ~CO_FL_LIST_MASK;
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); 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_ATOMIC_DEC(&srv->curr_used_conns);
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock); 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) { if (is_safe) {
conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST; conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST;

View File

@ -6285,7 +6285,7 @@ struct task *ssl_sock_io_cb(struct task *t, void *context, unsigned int state)
conn = ctx->conn; conn = ctx->conn;
conn_in_list = conn_get_idle_flag(conn); conn_in_list = conn_get_idle_flag(conn);
if (conn_in_list) 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); HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
} else { } else {
conn = ctx->conn; conn = ctx->conn;