From 3e7a0bb70b2f1a81d17163f27132f2f44b71521e Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Wed, 8 Feb 2023 11:49:02 +0100 Subject: [PATCH] MINOR: cfgparse/server: move (min/max)conn postparsing logic into dedicated function In check_config_validity() function, we performed some consistency checks to adjust minconn/maxconn attributes for each declared server. We move this logic into a dedicated function named srv_minmax_conn_apply() to be able to perform those checks later in the process life when needed (ie: dynamic servers) --- include/haproxy/server.h | 20 ++++++++++++++++++++ src/cfgparse.c | 11 +---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/haproxy/server.h b/include/haproxy/server.h index 6dc905a17..e5866a552 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -281,6 +281,26 @@ static inline void srv_use_conn(struct server *srv, struct connection *conn) HA_ATOMIC_STORE(&srv->est_need_conns, curr); } +/* checks if minconn and maxconn are consistent to each other + * and automatically adjust them if it is not the case + * This logic was historically implemented in check_config_validity() + * at boot time, but with the introduction of dynamic servers + * this may be used at multiple places in the code now + */ +static inline void srv_minmax_conn_apply(struct server *srv) +{ + if (srv->minconn > srv->maxconn) { + /* Only 'minconn' was specified, or it was higher than or equal + * to 'maxconn'. Let's turn this into maxconn and clean it, as + * this will avoid further useless expensive computations. + */ + srv->maxconn = srv->minconn; + } else if (srv->maxconn && !srv->minconn) { + /* minconn was not specified, so we set it to maxconn */ + srv->minconn = srv->maxconn; + } +} + #endif /* _HAPROXY_SERVER_H */ /* diff --git a/src/cfgparse.c b/src/cfgparse.c index 52b308697..60d007b47 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3818,16 +3818,7 @@ out_uri_auth_compat: while (newsrv != NULL) { set_usermsgs_ctx(newsrv->conf.file, newsrv->conf.line, &newsrv->obj_type); - if (newsrv->minconn > newsrv->maxconn) { - /* Only 'minconn' was specified, or it was higher than or equal - * to 'maxconn'. Let's turn this into maxconn and clean it, as - * this will avoid further useless expensive computations. - */ - newsrv->maxconn = newsrv->minconn; - } else if (newsrv->maxconn && !newsrv->minconn) { - /* minconn was not specified, so we set it to maxconn */ - newsrv->minconn = newsrv->maxconn; - } + srv_minmax_conn_apply(newsrv); /* this will also properly set the transport layer for * prod and checks