]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse/server: move (min/max)conn postparsing logic into dedicated function
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 8 Feb 2023 10:49:02 +0000 (11:49 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 8 Feb 2023 13:48:21 +0000 (14:48 +0100)
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
src/cfgparse.c

index 6dc905a179371101fc50385b78571f8e13145148..e5866a5528cb8b96380d13cde8a63ff9b2e620b7 100644 (file)
@@ -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 */
 
 /*
index 52b308697d09fc982ab7c2ee353142a967734a0f..60d007b4789454a835c9230b76ce35f99f052b36 100644 (file)
@@ -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