]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: move session_list member in a union
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 3 May 2021 12:28:30 +0000 (14:28 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 5 May 2021 12:35:36 +0000 (14:35 +0200)
Move the session_list attach point in an anonymous union. This member is
only used for backend connections. This commit is in preparation for the
support of stopping frontend idling connections which will add another
member to the union.

This change means that a special care must be taken to be sure that only
backend connections manipulate the session_list. A few BUG_ON has been
added as special guard to prevent from misuse.

include/haproxy/connection-t.h
include/haproxy/connection.h
include/haproxy/session.h

index 2f3296d3b9a7c02c9394ce3aa64857be64a2299d..5314056073d462921d240231ea9f78aaf0e82cfc 100644 (file)
@@ -526,7 +526,9 @@ struct connection {
        /* second cache line */
        struct wait_event *subs; /* Task to wake when awaited events are ready */
        struct mt_list toremove_list; /* list for connection to clean up */
-       struct list session_list;     /* List of attached connections to a session */
+       union {
+               struct list session_list;  /* used by backend conns, list of attached connections to a session */
+       };
        union conn_handle handle;     /* connection handle at the socket layer */
        const struct netns_entry *proxy_netns;
 
index ae5f636c61eb3c3f581edcfb5e6b40fcb42a4087..296da89e54c69535d3e10472e20264a6e96be788 100644 (file)
@@ -343,6 +343,15 @@ static inline void cs_init(struct conn_stream *cs, struct connection *conn)
        cs->conn = conn;
 }
 
+/* returns 0 if the connection is valid and is a frontend connection, otherwise
+ * returns 1 indicating it's a backend connection. And uninitialized connection
+ * also returns 1 to better handle the usage in the middle of initialization.
+ */
+static inline int conn_is_back(const struct connection *conn)
+{
+       return !objt_listener(conn->target);
+}
+
 /* Initializes all required fields for a new connection. Note that it does the
  * minimum acceptable initialization for a connection that already exists and
  * is about to be reused. It also leaves the addresses untouched, which makes
@@ -362,7 +371,8 @@ static inline void conn_init(struct connection *conn, void *target)
        conn->destroy_cb = NULL;
        conn->proxy_netns = NULL;
        MT_LIST_INIT(&conn->toremove_list);
-       LIST_INIT(&conn->session_list);
+       if (conn_is_back(conn))
+               LIST_INIT(&conn->session_list);
        conn->subs = NULL;
        conn->src = NULL;
        conn->dst = NULL;
@@ -440,15 +450,6 @@ static inline void sockaddr_free(struct sockaddr_storage **sap)
        *sap = NULL;
 }
 
-/* returns 0 if the connection is valid and is a frontend connection, otherwise
- * returns 1 indicating it's a backend connection. And uninitialized connection
- * also returns 1 to better handle the usage in the middle of initialization.
- */
-static inline int conn_is_back(const struct connection *conn)
-{
-       return !objt_listener(conn->target);
-}
-
 /* Tries to allocate a new connection and initialized its main fields. The
  * connection is returned on success, NULL on failure. The connection must
  * be released using pool_free() or conn_free().
@@ -545,7 +546,7 @@ static inline void conn_free(struct connection *conn)
 {
        /* If the connection is owned by the session, remove it from its list
         */
-       if (LIST_INLIST(&conn->session_list)) {
+       if (conn_is_back(conn) && LIST_INLIST(&conn->session_list)) {
                session_unown_conn(conn->owner, conn);
        }
        else if (!(conn->flags & CO_FL_PRIVATE)) {
index 6b289e2b798e9241a06aa4a5364b46260ebf763c..1842b7aa72714cb984bfe11ba42be52ff02480f7 100644 (file)
@@ -116,6 +116,8 @@ static inline void session_unown_conn(struct session *sess, struct connection *c
 {
        struct sess_srv_list *srv_list = NULL;
 
+       BUG_ON(objt_listener(conn->target));
+
        /* WT: this currently is a workaround for an inconsistency between
         * the link status of the connection in the session list and the
         * connection's owner. This should be removed as soon as all this
@@ -151,6 +153,8 @@ static inline int session_add_conn(struct session *sess, struct connection *conn
        struct sess_srv_list *srv_list = 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))
                return 1;