]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: finish to set up servers outside of the proxy setup loop
authorWilly Tarreau <w@1wt.eu>
Fri, 5 Mar 2021 09:48:42 +0000 (10:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 5 Mar 2021 14:00:24 +0000 (15:00 +0100)
Till now servers were only initialized as part of the proxy setup loop,
which doesn't cover peers, tcp log, dns, lua etc. Let's move this part
out of this loop and instead iterate over all registered servers. This
way we're certain to visit them all.

The patch looks big but it's just a move of a large block with the
corresponding reindent (as can be checked with diff -b). It relies
on the two previous ones ("MINOR: server: add a global list of all
known servers and" and "CLEANUP: lua: set a dummy file name and line
number on the dummy servers").

src/cfgparse.c

index 5910513934e109b840e17f65db29c03ce9dbeea7..c3c1ea97a8a872d50e1c084361f13b40d23c5f13 100644 (file)
@@ -3235,81 +3235,84 @@ out_uri_auth_compat:
                        /* update the mux */
                        newsrv->mux_proto = mux_ent;
                }
+       }
 
-               /* initialize idle conns lists */
-               for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
-                       int i;
+       /***********************************************************/
+       /* At this point, target names have already been resolved. */
+       /***********************************************************/
 
-                       newsrv->available_conns_tree = calloc(global.nbthread, sizeof(*newsrv->available_conns_tree));
+       /* we must finish to initialize certain things on the servers */
 
-                       if (!newsrv->available_conns_tree) {
-                               ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
-                                        newsrv->conf.file, newsrv->conf.line, newsrv->id);
-                               cfgerr++;
-                               continue;
-                       }
+       list_for_each_entry(newsrv, &servers_list, global_list) {
+               /* initialize idle conns lists */
+               int i;
 
-                       for (i = 0; i < global.nbthread; i++)
-                               newsrv->available_conns_tree[i] = EB_ROOT;
+               newsrv->available_conns_tree = calloc(global.nbthread, sizeof(*newsrv->available_conns_tree));
 
-                       if (newsrv->max_idle_conns != 0) {
-                               if (idle_conn_task == NULL) {
-                                       idle_conn_task = task_new(MAX_THREADS_MASK);
-                                       if (!idle_conn_task)
-                                               goto err;
+               if (!newsrv->available_conns_tree) {
+                       ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
+                                newsrv->conf.file, newsrv->conf.line, newsrv->id);
+                       cfgerr++;
+                       continue;
+               }
 
-                                       idle_conn_task->process = srv_cleanup_idle_conns;
-                                       idle_conn_task->context = NULL;
-
-                                       for (i = 0; i < global.nbthread; i++) {
-                                               idle_conns[i].cleanup_task = task_new(1UL << i);
-                                               if (!idle_conns[i].cleanup_task)
-                                                       goto err;
-                                               idle_conns[i].cleanup_task->process = srv_cleanup_toremove_conns;
-                                               idle_conns[i].cleanup_task->context = NULL;
-                                               HA_SPIN_INIT(&idle_conns[i].idle_conns_lock);
-                                               MT_LIST_INIT(&idle_conns[i].toremove_conns);
-                                       }
-                               }
+               for (i = 0; i < global.nbthread; i++)
+                       newsrv->available_conns_tree[i] = EB_ROOT;
 
-                               newsrv->idle_conns_tree = calloc((unsigned short)global.nbthread, sizeof(*newsrv->idle_conns_tree));
-                               if (!newsrv->idle_conns_tree) {
-                                       ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
-                                                newsrv->conf.file, newsrv->conf.line, newsrv->id);
-                                       cfgerr++;
-                                       continue;
-                               }
+               if (newsrv->max_idle_conns != 0) {
+                       if (idle_conn_task == NULL) {
+                               idle_conn_task = task_new(MAX_THREADS_MASK);
+                               if (!idle_conn_task)
+                                       goto err;
 
-                               for (i = 0; i < global.nbthread; i++)
-                                       newsrv->idle_conns_tree[i] = EB_ROOT;
+                               idle_conn_task->process = srv_cleanup_idle_conns;
+                               idle_conn_task->context = NULL;
 
-                               newsrv->safe_conns_tree = calloc(global.nbthread, sizeof(*newsrv->safe_conns_tree));
-                               if (!newsrv->safe_conns_tree) {
-                                       ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
-                                                newsrv->conf.file, newsrv->conf.line, newsrv->id);
-                                       cfgerr++;
-                                       continue;
+                               for (i = 0; i < global.nbthread; i++) {
+                                       idle_conns[i].cleanup_task = task_new(1UL << i);
+                                       if (!idle_conns[i].cleanup_task)
+                                               goto err;
+                                       idle_conns[i].cleanup_task->process = srv_cleanup_toremove_conns;
+                                       idle_conns[i].cleanup_task->context = NULL;
+                                       HA_SPIN_INIT(&idle_conns[i].idle_conns_lock);
+                                       MT_LIST_INIT(&idle_conns[i].toremove_conns);
                                }
+                       }
 
-                               for (i = 0; i < global.nbthread; i++)
-                                       newsrv->safe_conns_tree[i] = EB_ROOT;
-
-                               newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
-                               if (!newsrv->curr_idle_thr)
-                                       goto err;
+                       newsrv->idle_conns_tree = calloc((unsigned short)global.nbthread, sizeof(*newsrv->idle_conns_tree));
+                       if (!newsrv->idle_conns_tree) {
+                               ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
+                                        newsrv->conf.file, newsrv->conf.line, newsrv->id);
+                               cfgerr++;
                                continue;
-                       err:
-                               ha_alert("parsing [%s:%d] : failed to allocate idle connection tasks for server '%s'.\n",
+                       }
+
+                       for (i = 0; i < global.nbthread; i++)
+                               newsrv->idle_conns_tree[i] = EB_ROOT;
+
+                       newsrv->safe_conns_tree = calloc(global.nbthread, sizeof(*newsrv->safe_conns_tree));
+                       if (!newsrv->safe_conns_tree) {
+                               ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
                                         newsrv->conf.file, newsrv->conf.line, newsrv->id);
                                cfgerr++;
                                continue;
                        }
+
+                       for (i = 0; i < global.nbthread; i++)
+                               newsrv->safe_conns_tree[i] = EB_ROOT;
+
+                       newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
+                       if (!newsrv->curr_idle_thr)
+                               goto err;
+                       continue;
+               err:
+                       ha_alert("parsing [%s:%d] : failed to allocate idle connection tasks for server '%s'.\n",
+                                newsrv->conf.file, newsrv->conf.line, newsrv->id);
+                       cfgerr++;
+                       continue;
                }
        }
 
-       /***********************************************************/
-       /* At this point, target names have already been resolved. */
-       /***********************************************************/
 
        /* Check multi-process mode compatibility */