From: Simon Horman Date: Tue, 21 Jun 2011 05:34:57 +0000 (+0900) Subject: [MINOR] Add active connection list to server X-Git-Tag: v1.5-dev8~207 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=af5149539739ca64070a4ebe636a2f26a72dd528;p=thirdparty%2Fhaproxy.git [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 c9195f6448..810fe44c5a 100644 --- a/include/proto/session.h +++ b/include/proto/session.h @@ -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 */ /* diff --git a/include/types/server.h b/include/types/server.h index fb312157ed..cf0a0df06a 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -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 */ diff --git a/include/types/session.h b/include/types/session.h index 2ac22329c9..7fde0aa713 100644 --- a/include/types/session.h +++ b/include/types/session.h @@ -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 */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 2a08594440..cd05d83807 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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 */ diff --git a/src/peers.c b/src/peers.c index cdc83184cb..f253280414 100644 --- a/src/peers.c +++ b/src/peers.c @@ -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; diff --git a/src/proto_http.c b/src/proto_http.c index 39b7f289f8..6c7c64a703 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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; diff --git a/src/queue.c b/src/queue.c index 48380fcd8e..ea0bfb833b 100644 --- a/src/queue.c +++ b/src/queue.c @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -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); diff --git a/src/session.c b/src/session.c index f32ca9f501..56d0c8f8bf 100644 --- a/src/session.c +++ b/src/session.c @@ -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); } }