]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: rename private conns elements
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 14 Mar 2024 10:24:10 +0000 (11:24 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 14 Mar 2024 14:21:02 +0000 (15:21 +0100)
By default, backend connections are attached to a server instance. This
allows to implement connection reuse. However, in some particular cases,
connection cannot be shared accross several clients. These connections
are considered and private and are attached to the session instance
instead.

These private connections are also indexed by the target server to not
mix them. All of this is implemented via a dedicated structure
previously named struct sess_srv_list.

Rename it to better reflect its usage to struct sess_priv_conns. Also
rename its internal members and all of the associated functions.

This commit is only a renaming, thus no functional impact is expected.

include/haproxy/connection-t.h
include/haproxy/session-t.h
include/haproxy/session.h
src/backend.c
src/connection.c
src/mux_fcgi.c
src/mux_h2.c
src/session.c
src/trace.c

index 6cc62ee78888e993191a5b84392e6f762aec8e1f..3c65013bfbc0fde9d11bcf6e0f35cfab64b19e90 100644 (file)
@@ -547,7 +547,7 @@ struct connection {
                struct mt_list toremove_list; /* list element when idle connection is ready to be purged */
        };
        union {
-               struct list session_list;  /* used by backend conns, list of attached connections to a session */
+               struct list sess_el;       /* used by private backend conns, list elem into session */
                struct list stopping_list; /* used by frontend conns, attach point in mux stopping list */
        };
        union conn_handle handle;     /* connection handle at the socket layer */
index dff167ecb552e0acaa883d5207f4cc50b619e0a2..bf0079129a82e5b907cdd49b280d07836d11bf4b 100644 (file)
@@ -57,15 +57,16 @@ struct session {
        long t_idle;                    /* idle duration, -1 if never occurs */
        int idle_conns;                 /* Number of connections we're currently responsible for that we are not using */
        unsigned int flags;             /* session flags, SESS_FL_* */
-       struct list srv_list;           /* List of servers and the connections the session is currently responsible for */
+       struct list priv_conns;         /* list of private conns */
        struct sockaddr_storage *src; /* source address (pool), when known, otherwise NULL */
        struct sockaddr_storage *dst; /* destination address (pool), when known, otherwise NULL */
 };
 
-struct sess_srv_list {
-       void *target;
+/* List of private conns managed by a session, indexed by server */
+struct sess_priv_conns {
+       void *target;                   /* Server or dispatch used for indexing */
        struct list conn_list;          /* Head of the connections list */
-       struct list srv_list;           /* Next element of the server list */
+       struct list sess_el;            /* Element of session.priv_conns */
 };
 
 #endif /* _HAPROXY_SESSION_T_H */
index 5b080893e9b671ab35571b3f5aa40534f3aff871..90970e8e285288744a90dd4eb77a91719056aa29 100644 (file)
@@ -32,7 +32,7 @@
 #include <haproxy/stick_table.h>
 
 extern struct pool_head *pool_head_session;
-extern struct pool_head *pool_head_sess_srv_list;
+extern struct pool_head *pool_head_sess_priv_conns;
 
 struct session *session_new(struct proxy *fe, struct listener *li, enum obj_type *origin);
 void session_free(struct session *sess);
@@ -134,10 +134,12 @@ static inline void session_add_glitch_ctr(struct session *sess, uint inc)
                __session_add_glitch_ctr(sess, inc);
 }
 
-/* Remove the connection from the session list, and destroy the srv_list if it's now empty */
+/* Remove the connection from the session list, and destroy sess_priv_conns
+ * element if it's now empty.
+ */
 static inline void session_unown_conn(struct session *sess, struct connection *conn)
 {
-       struct sess_srv_list *srv_list = NULL;
+       struct sess_priv_conns *pconns = NULL;
 
        BUG_ON(objt_listener(conn->target));
 
@@ -148,56 +150,56 @@ static inline void session_unown_conn(struct session *sess, struct connection *c
         * conn->owner that points to a dead session, but in this case the
         * element is not linked.
         */
-       if (!LIST_INLIST(&conn->session_list))
+       if (!LIST_INLIST(&conn->sess_el))
                return;
 
        if (conn->flags & CO_FL_SESS_IDLE)
                sess->idle_conns--;
-       LIST_DEL_INIT(&conn->session_list);
+       LIST_DEL_INIT(&conn->sess_el);
        conn->owner = NULL;
-       list_for_each_entry(srv_list, &sess->srv_list, srv_list) {
-               if (srv_list->target == conn->target) {
-                       if (LIST_ISEMPTY(&srv_list->conn_list)) {
-                               LIST_DELETE(&srv_list->srv_list);
-                               pool_free(pool_head_sess_srv_list, srv_list);
+       list_for_each_entry(pconns, &sess->priv_conns, sess_el) {
+               if (pconns->target == conn->target) {
+                       if (LIST_ISEMPTY(&pconns->conn_list)) {
+                               LIST_DELETE(&pconns->sess_el);
+                               pool_free(pool_head_sess_priv_conns, pconns);
                        }
                        break;
                }
        }
 }
 
-/* Add the connection <conn> to the server list of the session <sess>. This
- * function is called only if the connection is private. Nothing is performed if
- * the connection is already in the session sever list or if the session does
- * not own the connection.
+/* 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 or if the session does not
+ * owned the connection.
  */
 static inline int session_add_conn(struct session *sess, struct connection *conn, void *target)
 {
-       struct sess_srv_list *srv_list = NULL;
+       struct sess_priv_conns *pconns = NULL;
        int found = 0;
 
        BUG_ON(objt_listener(conn->target));
 
        /* Already attach to the session or not the connection owner */
-       if (!LIST_ISEMPTY(&conn->session_list) || (conn->owner && conn->owner != sess))
+       if (!LIST_ISEMPTY(&conn->sess_el) || (conn->owner && conn->owner != sess))
                return 1;
 
-       list_for_each_entry(srv_list, &sess->srv_list, srv_list) {
-               if (srv_list->target == target) {
+       list_for_each_entry(pconns, &sess->priv_conns, sess_el) {
+               if (pconns->target == target) {
                        found = 1;
                        break;
                }
        }
        if (!found) {
                /* The session has no connection for the server, create a new entry */
-               srv_list = pool_alloc(pool_head_sess_srv_list);
-               if (!srv_list)
+               pconns = pool_alloc(pool_head_sess_priv_conns);
+               if (!pconns)
                        return 0;
-               srv_list->target = target;
-               LIST_INIT(&srv_list->conn_list);
-               LIST_APPEND(&sess->srv_list, &srv_list->srv_list);
+               pconns->target = target;
+               LIST_INIT(&pconns->conn_list);
+               LIST_APPEND(&sess->priv_conns, &pconns->sess_el);
        }
-       LIST_APPEND(&srv_list->conn_list, &conn->session_list);
+       LIST_APPEND(&pconns->conn_list, &conn->sess_el);
        return 1;
 }
 
@@ -230,11 +232,11 @@ static inline int session_check_idle_conn(struct session *sess, struct connectio
 static inline struct connection *session_get_conn(struct session *sess, void *target, int64_t hash)
 {
        struct connection *srv_conn = NULL;
-       struct sess_srv_list *srv_list;
+       struct sess_priv_conns *pconns;
 
-       list_for_each_entry(srv_list, &sess->srv_list, srv_list) {
-               if (srv_list->target == target) {
-                       list_for_each_entry(srv_conn, &srv_list->conn_list, session_list) {
+       list_for_each_entry(pconns, &sess->priv_conns, sess_el) {
+               if (pconns->target == target) {
+                       list_for_each_entry(srv_conn, &pconns->conn_list, sess_el) {
                                if ((srv_conn->hash_node && srv_conn->hash_node->node.key == hash) &&
                                    srv_conn->mux &&
                                    (srv_conn->mux->avail_streams(srv_conn) > 0) &&
index 4ef0087c35757d1de25e52e40ee3a4fcecfd2236..7dd8ceb767289d77648cddcf6be13c0367ea925a 100644 (file)
@@ -653,9 +653,9 @@ int assign_server(struct stream *s)
        if ((s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_HI &&
            ((s->sess->flags & SESS_FL_PREFER_LAST) ||
             (s->be->options & PR_O_PREF_LAST))) {
-               struct sess_srv_list *srv_list;
-               list_for_each_entry(srv_list, &s->sess->srv_list, srv_list) {
-                       struct server *tmpsrv = objt_server(srv_list->target);
+               struct sess_priv_conns *pconns;
+               list_for_each_entry(pconns, &s->sess->priv_conns, sess_el) {
+                       struct server *tmpsrv = objt_server(pconns->target);
 
                        if (tmpsrv && tmpsrv->proxy == s->be &&
                            ((s->sess->flags & SESS_FL_PREFER_LAST) ||
@@ -663,7 +663,7 @@ int assign_server(struct stream *s)
                              server_has_room(tmpsrv) || (
                              tmpsrv->queue.length + 1 < s->be->max_ka_queue))) &&
                            srv_currently_usable(tmpsrv)) {
-                               list_for_each_entry(conn, &srv_list->conn_list, session_list) {
+                               list_for_each_entry(conn, &pconns->conn_list, sess_el) {
                                        if (!(conn->flags & CO_FL_WAIT_XPRT)) {
                                                srv = tmpsrv;
                                                s->target = &srv->obj_type;
index 2f2726b322c26c55595b0b9e91ee2cd0553fdc71..bbeea5e35b8c89974c12c246d4572ffa6882ce37 100644 (file)
@@ -474,7 +474,7 @@ void conn_init(struct connection *conn, void *target)
        conn->proxy_netns = NULL;
        MT_LIST_INIT(&conn->toremove_list);
        if (conn_is_back(conn))
-               LIST_INIT(&conn->session_list);
+               LIST_INIT(&conn->sess_el);
        else
                LIST_INIT(&conn->stopping_list);
        LIST_INIT(&conn->tlv_list);
@@ -513,7 +513,7 @@ static void conn_backend_deinit(struct connection *conn)
 {
        /* If the connection is owned by the session, remove it from its list
         */
-       if (conn_is_back(conn) && LIST_INLIST(&conn->session_list)) {
+       if (conn_is_back(conn) && LIST_INLIST(&conn->sess_el)) {
                session_unown_conn(conn->owner, conn);
        }
        else if (!(conn->flags & CO_FL_PRIVATE)) {
index 0230e6b79d28abd4e730c2f8bde0198ac72599c4..d192cf9d1fd4337ad4e6963dae634ec26f7ba5b7 100644 (file)
@@ -3619,7 +3619,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)) {
+                                !LIST_INLIST(&fconn->conn->sess_el)) {
                                srv_add_to_avail_list(__objt_server(fconn->conn->target), fconn->conn);
                        }
                }
index 2a2a15d4ffdad34702134780bc0f65b4755558ce..d72fe63442eae3203c143e4bcdb461d50b1219cf 100644 (file)
@@ -4858,7 +4858,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)) {
+                                        !LIST_INLIST(&h2c->conn->sess_el)) {
                                        srv_add_to_avail_list(__objt_server(h2c->conn->target), h2c->conn);
                                }
                        }
index b85797a11b060d4a36c1918321c3539c072e9565..f54490e79f49cb2afb18c505cdf551aa3d895703 100644 (file)
@@ -27,8 +27,8 @@
 
 
 DECLARE_POOL(pool_head_session, "session", sizeof(struct session));
-DECLARE_POOL(pool_head_sess_srv_list, "session server list",
-               sizeof(struct sess_srv_list));
+DECLARE_POOL(pool_head_sess_priv_conns, "session priv conns list",
+             sizeof(struct sess_priv_conns));
 
 int conn_complete_session(struct connection *conn);
 
@@ -61,7 +61,7 @@ struct session *session_new(struct proxy *fe, struct listener *li, enum obj_type
                sess->t_idle = -1;
                _HA_ATOMIC_INC(&totalconn);
                _HA_ATOMIC_INC(&jobs);
-               LIST_INIT(&sess->srv_list);
+               LIST_INIT(&sess->priv_conns);
                sess->idle_conns = 0;
                sess->flags = SESS_FL_NONE;
                sess->src = NULL;
@@ -76,7 +76,7 @@ struct session *session_new(struct proxy *fe, struct listener *li, enum obj_type
 void session_free(struct session *sess)
 {
        struct connection *conn, *conn_back;
-       struct sess_srv_list *srv_list, *srv_list_back;
+       struct sess_priv_conns *pconns, *pconns_back;
 
        if (sess->listener)
                listener_release(sess->listener);
@@ -86,9 +86,9 @@ void session_free(struct session *sess)
        conn = objt_conn(sess->origin);
        if (conn != NULL && conn->mux)
                conn->mux->destroy(conn->ctx);
-       list_for_each_entry_safe(srv_list, srv_list_back, &sess->srv_list, srv_list) {
-               list_for_each_entry_safe(conn, conn_back, &srv_list->conn_list, session_list) {
-                       LIST_DEL_INIT(&conn->session_list);
+       list_for_each_entry_safe(pconns, pconns_back, &sess->priv_conns, sess_el) {
+               list_for_each_entry_safe(conn, conn_back, &pconns->conn_list, sess_el) {
+                       LIST_DEL_INIT(&conn->sess_el);
                        if (conn->mux) {
                                conn->owner = NULL;
                                conn->flags &= ~CO_FL_SESS_IDLE;
@@ -102,7 +102,7 @@ void session_free(struct session *sess)
                                conn_free(conn);
                        }
                }
-               pool_free(pool_head_sess_srv_list, srv_list);
+               pool_free(pool_head_sess_priv_conns, pconns);
        }
        sockaddr_free(&sess->src);
        sockaddr_free(&sess->dst);
index a233c0de1dafc2225cdf7412ec3ae03953bcfd6c..d3a0b95ce27c5f8635b705518d56af7a5139a371 100644 (file)
@@ -129,7 +129,7 @@ int __trace_enabled(enum trace_level level, uint64_t mask, struct trace_source *
 
        if (!sess && strm)
                sess = strm->sess;
-       else if (!sess && conn && LIST_INLIST(&conn->session_list))
+       else if (!sess && conn && LIST_INLIST(&conn->sess_el))
                sess = conn->owner;
        else if (!sess && check)
                sess = check->sess;