MINOR: session: remove redundant target argument from session_add_conn()

session_add_conn() uses three argument : connection and session
instances, plus a void pointer labelled as target. Typically, it
represents the server, but can also be a backend instance (for example
on dispatch).

In fact, this argument is redundant as <target> is already a member of
the connection. This commit simplifies session_add_conn() by removing
it. A BUG_ON() on target is extended to ensure it is never NULL.
This commit is contained in:
Amaury Denoyelle 2025-07-24 11:53:13 +02:00
parent 668c2cfb09
commit ec1ab8d171
9 changed files with 20 additions and 16 deletions

View File

@ -171,17 +171,21 @@ static inline void session_unown_conn(struct session *sess, struct connection *c
}
}
/* Add the connection <conn> to the private conns list of session <sess>. This
* function is called only if the connection is private. Nothing is performed
* if the connection is already in the session list.
/* Add the connection <conn> to the private conns list of session <sess>. Each
* connection is indexed by their respective target in the session. Nothing is
* performed if the connection is already in the session list.
*
* Returns true if conn is inserted or already present else false if a failure
* occurs during insertion.
*/
static inline int session_add_conn(struct session *sess, struct connection *conn, void *target)
static inline int session_add_conn(struct session *sess, struct connection *conn)
{
struct sess_priv_conns *pconns = NULL;
struct server *srv = objt_server(conn->target);
int found = 0;
BUG_ON(objt_listener(conn->target));
/* Connection target is used to index it in the session. Only BE conns are expected in session list. */
BUG_ON(!conn->target || objt_listener(conn->target));
/* A connection cannot be attached already to another session. */
BUG_ON(conn->owner && conn->owner != sess);
@ -191,7 +195,7 @@ static inline int session_add_conn(struct session *sess, struct connection *conn
return 1;
list_for_each_entry(pconns, &sess->priv_conns, sess_el) {
if (pconns->target == target) {
if (pconns->target == conn->target) {
found = 1;
break;
}
@ -201,7 +205,7 @@ static inline int session_add_conn(struct session *sess, struct connection *conn
pconns = pool_alloc(pool_head_sess_priv_conns);
if (!pconns)
return 0;
pconns->target = target;
pconns->target = conn->target;
LIST_INIT(&pconns->conn_list);
LIST_APPEND(&sess->priv_conns, &pconns->sess_el);

View File

@ -1425,7 +1425,7 @@ struct connection *conn_backend_get(int reuse_mode,
if (reuse_mode == PR_O_REUSE_SAFE && conn->mux->flags & MX_FL_HOL_RISK) {
/* attach the connection to the session private list */
conn->owner = sess;
session_add_conn(sess, conn, conn->target);
session_add_conn(sess, conn);
}
else {
srv_add_to_avail_list(srv, conn);
@ -2159,7 +2159,7 @@ int connect_server(struct stream *s)
(reuse_mode == PR_O_REUSE_SAFE &&
srv_conn->mux->flags & MX_FL_HOL_RISK)) {
/* If it fail now, the same will be done in mux->detach() callback */
session_add_conn(s->sess, srv_conn, srv_conn->target);
session_add_conn(s->sess, srv_conn);
}
}
}

View File

@ -117,7 +117,7 @@ int conn_create_mux(struct connection *conn, int *closed_connection)
}
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);
session_add_conn(sess, conn);
}
return 0;
fail:

View File

@ -1641,7 +1641,7 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
conn_set_owner(srv_conn, sess, NULL);
conn_set_private(srv_conn);
/* If it fail now, the same will be done in mux->detach() callback */
session_add_conn(srv_conn->owner, srv_conn, srv_conn->target);
session_add_conn(srv_conn->owner, srv_conn);
break;
}
}

View File

@ -3723,7 +3723,7 @@ static void fcgi_detach(struct sedesc *sd)
(fconn->flags & FCGI_CF_KEEP_CONN)) {
if (fconn->conn->flags & CO_FL_PRIVATE) {
/* Add the connection in the session serverlist, if not already done */
if (!session_add_conn(sess, fconn->conn, fconn->conn->target)) {
if (!session_add_conn(sess, fconn->conn)) {
fconn->conn->owner = NULL;
if (eb_is_empty(&fconn->streams_by_id)) {
/* let's kill the connection right away */

View File

@ -1138,7 +1138,7 @@ static int h1s_finish_detach(struct h1s *h1s)
if (h1c->conn->flags & CO_FL_PRIVATE) {
/* Add the connection in the session server list, if not already done */
if (!session_add_conn(sess, h1c->conn, h1c->conn->target)) {
if (!session_add_conn(sess, h1c->conn)) {
h1c->conn->owner = NULL;
h1c->conn->mux->destroy(h1c);
goto released;

View File

@ -5533,7 +5533,7 @@ static void h2_detach(struct sedesc *sd)
if (h2c->conn->flags & CO_FL_PRIVATE) {
/* Add the connection in the session server list, if not already done */
if (!session_add_conn(sess, h2c->conn, h2c->conn->target)) {
if (!session_add_conn(sess, h2c->conn)) {
h2c->conn->owner = NULL;
if (eb_is_empty(&h2c->streams_by_id)) {
h2c->conn->mux->destroy(h2c);

View File

@ -3788,7 +3788,7 @@ static void qmux_strm_detach(struct sedesc *sd)
* conn will be closed if idle, or insert will be
* retried on next detach.
*/
if (!session_add_conn(sess, conn, conn->target)) {
if (!session_add_conn(sess, conn)) {
TRACE_ERROR("error during connection insert into session list", QMUX_EV_STRM_END, conn);
conn->owner = NULL;
if (!qcc->nb_sc)

View File

@ -2977,7 +2977,7 @@ static void spop_detach(struct sedesc *sd)
if (!(spop_conn->flags & (SPOP_CF_RCVD_SHUT|SPOP_CF_ERR_PENDING|SPOP_CF_ERROR))) {
if (spop_conn->conn->flags & CO_FL_PRIVATE) {
/* Add the connection in the session server list, if not already done */
if (!session_add_conn(sess, spop_conn->conn, spop_conn->conn->target)) {
if (!session_add_conn(sess, spop_conn->conn)) {
spop_conn->conn->owner = NULL;
if (eb_is_empty(&spop_conn->streams_by_id)) {
spop_conn->conn->mux->destroy(spop_conn);