]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] Add active connection list to server
authorSimon Horman <horms@verge.net.au>
Tue, 21 Jun 2011 05:34:57 +0000 (14:34 +0900)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 Jun 2011 20:00:12 +0000 (22:00 +0200)
The motivation for this is to allow iteration of all the connections
of a server without the expense of iterating over the global list
of connections.

The first use of this will be to implement an option to close connections
associated with a server when is is marked as being down or in maintenance
mode.

include/proto/session.h
include/types/server.h
include/types/session.h
src/cfgparse.c
src/peers.c
src/proto_http.c
src/queue.c
src/session.c

index c9195f644816a311806ee66aeca1b6bc18aa86ca..810fe44c5a6a402daa3cbe0ddcde4c2b8aea8fd3 100644 (file)
@@ -225,6 +225,21 @@ static void inline session_inc_http_err_ctr(struct session *s)
        }
 }
 
+static void inline session_add_srv_conn(struct session *sess, struct server *srv)
+{
+       sess->srv_conn = srv;
+       LIST_ADD(&srv->actconns, &sess->by_srv);
+}
+
+static void inline session_del_srv_conn(struct session *sess)
+{
+       if (!sess->srv_conn)
+               return;
+
+       sess->srv_conn = NULL;
+       LIST_DEL(&sess->by_srv);
+}
+
 #endif /* _PROTO_SESSION_H */
 
 /*
index fb312157eda3bba2eb3135bc4f5775a48490cf2f..cf0a0df06a3e9d4ad8934fe6791b2e696a32733d 100644 (file)
@@ -101,6 +101,7 @@ struct server {
        struct srvcounters counters;            /* statistics counters */
 
        struct list pendconns;                  /* pending connections */
+       struct list actconns;                   /* active connections */
        struct task *check;                     /* the task associated to the health check processing */
 
        struct sockaddr_storage addr;           /* the address to connect to */
index 2ac22329c979e668b32cefb63dd0b9935d7463f0..7fde0aa713c6d38f9dd2a9a1c2cb599b550cddff 100644 (file)
@@ -157,6 +157,7 @@ enum {
  */
 struct session {
        struct list list;                       /* position in global sessions list */
+       struct list by_srv;                     /* position in server session list */
        struct list back_refs;                  /* list of users tracking this session */
        struct task *task;                      /* the task associated with this session */
        /* application specific below */
index 2a085944407063fab110de0b0dece11fd6c456ca..cd05d83807c6dfd0d7841a21ae2fc90cdc230cc7 100644 (file)
@@ -3922,6 +3922,7 @@ stats_error_parsing:
                        newsrv->conf.file = file;
                        newsrv->conf.line = linenum;
 
+                       LIST_INIT(&newsrv->actconns);
                        LIST_INIT(&newsrv->pendconns);
                        do_check = 0;
                        newsrv->state = SRV_RUNNING; /* early server setup */
index cdc83184cb06837f5ca03d497717a29ab178dbdb..f2532804140e4dc3e8c9b4c822cbec8f67c4afd7 100644 (file)
@@ -1185,7 +1185,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
        stream_sock_prepare_interface(&s->si[1]);
        s->si[1].release = NULL;
 
-       s->srv_conn = NULL;
+       session_del_srv_conn(s);
        clear_target(&s->target);
        s->pend_pos = NULL;
 
index 39b7f289f8b44a338e8a9030e4367da3c8c15a45..6c7c64a703fe49d5e2c135c81fb66c0255f50063 100644 (file)
@@ -7593,7 +7593,7 @@ void http_reset_txn(struct session *s)
 
        s->be = s->fe;
        s->logs.logwait = s->fe->to_log;
-       s->srv_conn = NULL;
+       session_del_srv_conn(s);
        clear_target(&s->target);
        /* re-init store persistence */
        s->store_count = 0;
index 48380fcd8e86b448cdb95535f1cd678a4c69dab6..ea0bfb833b262055ceae0dfde9f4e7df284ca036 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <proto/queue.h>
 #include <proto/server.h>
+#include <proto/session.h>
 #include <proto/stream_interface.h>
 #include <proto/task.h>
 
@@ -122,7 +123,7 @@ struct session *pendconn_get_next_sess(struct server *srv, struct proxy *px)
        /* we want to note that the session has now been assigned a server */
        sess->flags |= SN_ASSIGNED;
        set_target_server(&sess->target, srv);
-       sess->srv_conn = srv;
+       session_add_srv_conn(sess, srv);
        srv->served++;
        if (px->lbprm.server_take_conn)
                px->lbprm.server_take_conn(srv);
index f32ca9f501b1528ab7d0e60328e9122ba825dfcf..56d0c8f8bf6b7376c9ad82b634fff71893c09575 100644 (file)
@@ -201,7 +201,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
        if (likely(s->fe->options2 & PR_O2_INDEPSTR))
                s->si[1].flags |= SI_FL_INDEP_STR;
 
-       s->srv_conn = NULL;
+       session_del_srv_conn(s);
        clear_target(&s->target);
        s->pend_pos = NULL;
 
@@ -2140,14 +2140,14 @@ void sess_change_server(struct session *sess, struct server *newsrv)
                sess->srv_conn->served--;
                if (sess->srv_conn->proxy->lbprm.server_drop_conn)
                        sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn);
-               sess->srv_conn = NULL;
+               session_del_srv_conn(sess);
        }
 
        if (newsrv) {
                newsrv->served++;
                if (newsrv->proxy->lbprm.server_take_conn)
                        newsrv->proxy->lbprm.server_take_conn(newsrv);
-               sess->srv_conn = newsrv;
+               session_add_srv_conn(sess, newsrv);
        }
 }