[MINOR] Add active connection list to server
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.
diff --git a/include/proto/session.h b/include/proto/session.h
index c9195f6..810fe44 100644
--- a/include/proto/session.h
+++ b/include/proto/session.h
@@ -225,6 +225,21 @@
}
}
+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 */
/*
diff --git a/include/types/server.h b/include/types/server.h
index fb31215..cf0a0df 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -101,6 +101,7 @@
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 */
diff --git a/include/types/session.h b/include/types/session.h
index 2ac2232..7fde0aa 100644
--- a/include/types/session.h
+++ b/include/types/session.h
@@ -157,6 +157,7 @@
*/
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 */
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 2a08594..cd05d83 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -3922,6 +3922,7 @@
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 */
diff --git a/src/peers.c b/src/peers.c
index cdc8318..f253280 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -1185,7 +1185,7 @@
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;
diff --git a/src/proto_http.c b/src/proto_http.c
index 39b7f28..6c7c64a 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -7593,7 +7593,7 @@
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;
diff --git a/src/queue.c b/src/queue.c
index 48380fc..ea0bfb8 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -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 @@
/* 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);
diff --git a/src/session.c b/src/session.c
index f32ca9f..56d0c8f 100644
--- a/src/session.c
+++ b/src/session.c
@@ -201,7 +201,7 @@
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 @@
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);
}
}