diff options
author | Willy Tarreau <w@1wt.eu> | 2020-09-24 08:39:22 +0200 |
---|---|---|
committer | Willy Tarreau <w@1wt.eu> | 2020-10-07 18:45:00 +0200 |
commit | c00e580cb8d8257a401e31442d3758cd72d77d9e (patch) | |
tree | 6dc1caf3cef863fd4cd5e34d4392bfd9c284b729 | |
parent | 2c2e783dc3853589e2af346c7f82a10c6bfdac0a (diff) | |
download | haproxy-c00e580cb8d8257a401e31442d3758cd72d77d9e.tar.gz |
MEDIUM: proxy: replace proxy->state with proxy->disabled
The remaining proxy states were only used to distinguish an enabled
proxy from a disabled one. Due to the initialization order, both
PR_STNEW and PR_STREADY were equivalent after startup, and they
would only differ from PR_STSTOPPED when the proxy is disabled or
shutdown (which is effectively another way to disable it).
Now we just have a "disabled" field which allows to distinguish them.
It's becoming obvious that start_proxies() is only used to print a
greeting message now, that we'd rather get rid of. Probably that
zombify_proxy() and stop_proxy() should be merged once their
differences move to the right place.
-rw-r--r-- | contrib/prometheus-exporter/service-prometheus.c | 8 | ||||
-rw-r--r-- | include/haproxy/backend.h | 2 | ||||
-rw-r--r-- | include/haproxy/proxy-t.h | 9 | ||||
-rw-r--r-- | src/cfgparse-listen.c | 6 | ||||
-rw-r--r-- | src/cfgparse.c | 8 | ||||
-rw-r--r-- | src/check.c | 2 | ||||
-rw-r--r-- | src/cli.c | 1 | ||||
-rw-r--r-- | src/extcheck.c | 2 | ||||
-rw-r--r-- | src/haproxy.c | 8 | ||||
-rw-r--r-- | src/mux_fcgi.c | 2 | ||||
-rw-r--r-- | src/mux_h1.c | 4 | ||||
-rw-r--r-- | src/mux_h2.c | 2 | ||||
-rw-r--r-- | src/mworker.c | 2 | ||||
-rw-r--r-- | src/proxy.c | 34 | ||||
-rw-r--r-- | src/server.c | 2 | ||||
-rw-r--r-- | src/stats.c | 8 | ||||
-rw-r--r-- | src/stick_table.c | 2 | ||||
-rw-r--r-- | src/stream.c | 2 |
18 files changed, 46 insertions, 58 deletions
diff --git a/contrib/prometheus-exporter/service-prometheus.c b/contrib/prometheus-exporter/service-prometheus.c index ba1619f47..b6c38eb57 100644 --- a/contrib/prometheus-exporter/service-prometheus.c +++ b/contrib/prometheus-exporter/service-prometheus.c @@ -1546,12 +1546,12 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx) px = appctx->ctx.stats.obj1; /* skip the disabled proxies, global frontend and non-networked ones */ - if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_FE)) + if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_FE)) goto next_px; switch (appctx->st2) { case ST_F_STATUS: - metric = mkf_u32(FO_STATUS, px->state == PR_STREADY ? 1 : 0); + metric = mkf_u32(FO_STATUS, !px->disabled); break; case ST_F_SCUR: metric = mkf_u32(0, px->feconn); @@ -1731,7 +1731,7 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) px = appctx->ctx.stats.obj1; /* skip the disabled proxies, global frontend and non-networked ones */ - if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE)) + if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE)) goto next_px; switch (appctx->st2) { @@ -1976,7 +1976,7 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx) px = appctx->ctx.stats.obj1; /* skip the disabled proxies, global frontend and non-networked ones */ - if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE)) + if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE)) goto next_px; while (appctx->ctx.stats.obj2) { diff --git a/include/haproxy/backend.h b/include/haproxy/backend.h index f6b25e7be..8a763bfbd 100644 --- a/include/haproxy/backend.h +++ b/include/haproxy/backend.h @@ -52,7 +52,7 @@ int be_lastsession(const struct proxy *be); /* Returns number of usable servers in backend */ static inline int be_usable_srv(struct proxy *be) { - if (be->state == PR_STSTOPPED) + if (be->disabled) return 0; else if (be->srv_act) return be->srv_act; diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index aa8038dd1..a17537aa5 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -42,13 +42,6 @@ #include <haproxy/thread-t.h> #include <haproxy/uri_auth-t.h> -/* values for proxy->state */ -enum pr_state { - PR_STNEW = 0, /* proxy has not been initialized yet */ - PR_STREADY, /* proxy has been initialized and is ready */ - PR_STSTOPPED, /* proxy is stopped (end of a restart) */ -} __attribute__((packed)); - /* values for proxy->mode */ enum pr_mode { PR_MODE_TCP = 0, @@ -252,7 +245,7 @@ struct error_snapshot { struct proxy { enum obj_type obj_type; /* object type == OBJ_TYPE_PROXY */ - enum pr_state state; /* proxy state, one of PR_* */ + char disabled; /* non-zero if disabled or shutdown */ enum pr_mode mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */ char cap; /* supported capabilities (PR_CAP_*) */ unsigned int maxconn; /* max # of active streams on the frontend */ diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index c2db644c8..b53b16235 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -237,7 +237,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) memcpy(&curproxy->defsrv, &defproxy.defsrv, sizeof(curproxy->defsrv)); curproxy->defsrv.id = "default-server"; - curproxy->state = defproxy.state; + curproxy->disabled = defproxy.disabled; curproxy->options = defproxy.options; curproxy->options2 = defproxy.options2; curproxy->no_options = defproxy.no_options; @@ -775,12 +775,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) else if (!strcmp(args[0], "disabled")) { /* disables this proxy */ if (alertif_too_many_args(0, file, linenum, args, &err_code)) goto out; - curproxy->state = PR_STSTOPPED; + curproxy->disabled = 1; } else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */ if (alertif_too_many_args(0, file, linenum, args, &err_code)) goto out; - curproxy->state = PR_STNEW; + curproxy->disabled = 0; } else if (!strcmp(args[0], "bind-process")) { /* enable this proxy only on some processes */ int cur_arg = 1; diff --git a/src/cfgparse.c b/src/cfgparse.c index 92d02cad2..0bc4b82a2 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -414,7 +414,7 @@ void init_default_instance() { init_new_proxy(&defproxy); defproxy.mode = PR_MODE_TCP; - defproxy.state = PR_STNEW; + defproxy.disabled = 0; defproxy.maxconn = cfg_maxpconn; defproxy.conn_retries = CONN_RETRIES; defproxy.redispatch_after = 0; @@ -2117,7 +2117,7 @@ void propagate_processes(struct proxy *from, struct proxy *to) if (!(from->cap & PR_CAP_FE)) return; - if (from->state == PR_STSTOPPED) + if (from->disabled) return; /* default_backend */ @@ -2234,7 +2234,7 @@ int check_config_validity() next_pxid++; - if (curproxy->state == PR_STSTOPPED) { + if (curproxy->disabled) { /* ensure we don't keep listeners uselessly bound. We * can't disable their listeners yet (fdtab not * allocated yet) but let's skip them. @@ -3949,7 +3949,7 @@ out_uri_auth_compat: * other proxies. */ for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { - if (curproxy->state == PR_STSTOPPED || !curproxy->table) + if (curproxy->disabled || !curproxy->table) continue; if (!stktable_init(curproxy->table)) { diff --git a/src/check.c b/src/check.c index 8d3cd6f93..88c78ed62 100644 --- a/src/check.c +++ b/src/check.c @@ -859,7 +859,7 @@ static struct task *process_chk_conn(struct task *t, void *context, unsigned sho * is disabled. */ if (((check->state & (CHK_ST_ENABLED | CHK_ST_PAUSED)) != CHK_ST_ENABLED) || - proxy->state == PR_STSTOPPED) + proxy->disabled) goto reschedule; /* we'll initiate a new check */ @@ -2428,7 +2428,6 @@ int mworker_cli_proxy_create() proxies_list = mworker_proxy; mworker_proxy->id = strdup("MASTER"); mworker_proxy->mode = PR_MODE_CLI; - mworker_proxy->state = PR_STNEW; mworker_proxy->last_change = now.tv_sec; mworker_proxy->cap = PR_CAP_LISTEN; /* this is a listen section */ mworker_proxy->maxconn = 10; /* default to 10 concurrent connections */ diff --git a/src/extcheck.c b/src/extcheck.c index dd7c94240..96d61c94e 100644 --- a/src/extcheck.c +++ b/src/extcheck.c @@ -495,7 +495,7 @@ struct task *process_chk_proc(struct task *t, void *context, unsigned short stat * is disabled. */ if (((check->state & (CHK_ST_ENABLED | CHK_ST_PAUSED)) != CHK_ST_ENABLED) || - s->proxy->state == PR_STSTOPPED) + s->proxy->disabled) goto reschedule; /* we'll initiate a new check */ diff --git a/src/haproxy.c b/src/haproxy.c index aa865f0f8..23cfa246e 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2010,7 +2010,7 @@ static void init(int argc, char **argv) break; for (px = proxies_list; px; px = px->next) - if (px->state != PR_STSTOPPED && px->li_all) + if (!px->disabled && px->li_all) break; if (pr || px) { @@ -2340,7 +2340,7 @@ static void init(int argc, char **argv) /* stop disabled proxies */ for (px = proxies_list; px; px = px->next) { - if (px->state == PR_STSTOPPED) + if (px->disabled) stop_proxy(px); } @@ -3511,7 +3511,7 @@ int main(int argc, char **argv) /* we might have to unbind some proxies from some processes */ px = proxies_list; while (px != NULL) { - if (px->bind_proc && px->state != PR_STSTOPPED) { + if (px->bind_proc && !px->disabled) { if (!(px->bind_proc & (1UL << proc))) { if (global.tune.options & GTUNE_SOCKET_TRANSFER) zombify_proxy(px); @@ -3525,7 +3525,7 @@ int main(int argc, char **argv) /* we might have to unbind some log forward proxies from some processes */ px = cfg_log_forward; while (px != NULL) { - if (px->bind_proc && px->state != PR_STSTOPPED) { + if (px->bind_proc && !px->disabled) { if (!(px->bind_proc & (1UL << proc))) { if (global.tune.options & GTUNE_SOCKET_TRANSFER) zombify_proxy(px); diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 7be05b6e8..694710ca2 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -2990,7 +2990,7 @@ static int fcgi_process(struct fcgi_conn *fconn) } fcgi_send(fconn); - if (unlikely(fconn->proxy->state == PR_STSTOPPED)) { + if (unlikely(fconn->proxy->disabled)) { /* frontend is stopping, reload likely in progress, let's try * to announce a graceful shutdown if not yet done. We don't * care if it fails, it will be tried again later. diff --git a/src/mux_h1.c b/src/mux_h1.c index a7fed2a6f..23cc72f1f 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -888,7 +888,7 @@ static void h1_set_cli_conn_mode(struct h1s *h1s, struct h1m *h1m) } /* If KAL, check if the frontend is stopping. If yes, switch in CLO mode */ - if (h1s->flags & H1S_F_WANT_KAL && fe->state == PR_STSTOPPED) { + if (h1s->flags & H1S_F_WANT_KAL && fe->disabled) { h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO; TRACE_STATE("stopping, set close mode", H1_EV_RX_DATA|H1_EV_RX_HDRS|H1_EV_TX_DATA|H1_EV_TX_HDRS, h1s->h1c->conn, h1s); } @@ -952,7 +952,7 @@ static void h1_set_srv_conn_mode(struct h1s *h1s, struct h1m *h1m) } /* If KAL, check if the backend is stopping. If yes, switch in CLO mode */ - if (h1s->flags & H1S_F_WANT_KAL && be->state == PR_STSTOPPED) { + if (h1s->flags & H1S_F_WANT_KAL && be->disabled) { h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO; TRACE_STATE("stopping, set close mode", H1_EV_RX_DATA|H1_EV_RX_HDRS|H1_EV_TX_DATA|H1_EV_TX_HDRS, h1s->h1c->conn, h1s); } diff --git a/src/mux_h2.c b/src/mux_h2.c index d145b8a97..9d7ea5616 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -3597,7 +3597,7 @@ static int h2_process(struct h2c *h2c) } h2_send(h2c); - if (unlikely(h2c->proxy->state == PR_STSTOPPED)) { + if (unlikely(h2c->proxy->disabled)) { /* frontend is stopping, reload likely in progress, let's try * to announce a graceful shutdown if not yet done. We don't * care if it fails, it will be tried again later. diff --git a/src/mworker.c b/src/mworker.c index d6365e120..2ef7e7dd7 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -437,7 +437,7 @@ void mworker_cleanlisteners() } /* if the proxy shouldn't be in the master, we stop it */ if (!listen_in_master) - curproxy->state = PR_STSTOPPED; + curproxy->disabled = 1; } } diff --git a/src/proxy.c b/src/proxy.c index bae8c1410..7bcfa9578 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1052,10 +1052,8 @@ void start_proxies(void) struct proxy *curproxy; for (curproxy = proxies_list; curproxy != NULL; curproxy = curproxy->next) { - if (curproxy->state != PR_STNEW) - continue; /* already initialized */ - - curproxy->state = PR_STREADY; + if (curproxy->disabled) + continue; send_log(curproxy, LOG_NOTICE, "Proxy %s started.\n", curproxy->id); } } @@ -1078,7 +1076,7 @@ struct task *manage_proxy(struct task *t, void *context, unsigned short state) */ /* first, let's check if we need to stop the proxy */ - if (unlikely(stopping && p->state != PR_STSTOPPED)) { + if (unlikely(stopping && !p->disabled)) { int t; t = tick_remain(now_ms, p->stop_time); if (t == 0) { @@ -1102,7 +1100,7 @@ struct task *manage_proxy(struct task *t, void *context, unsigned short state) * be in neither list. Any entry being dumped will have ref_cnt > 0. * However we protect tables that are being synced to peers. */ - if (unlikely(stopping && p->state == PR_STSTOPPED && p->table && p->table->current)) { + if (unlikely(stopping && p->disabled && p->table && p->table->current)) { if (!p->table->syncing) { stktable_trash_oldest(p->table, p->table->current); pool_gc(NULL); @@ -1230,7 +1228,7 @@ void soft_stop(void) p = proxies_list; tv_update_date(0,1); /* else, the old time before select will be used */ while (p) { - if (p->state != PR_STSTOPPED) { + if (!p->disabled) { ha_warning("Stopping %s %s in %d ms.\n", proxy_cap_str(p->cap), p->id, p->grace); send_log(p, LOG_WARNING, "Stopping %s %s in %d ms.\n", proxy_cap_str(p->cap), p->id, p->grace); p->stop_time = tick_add(now_ms, p->grace); @@ -1257,7 +1255,7 @@ void soft_stop(void) p = cfg_log_forward; while (p) { /* Zombie proxy, let's close the file descriptors */ - if (p->state == PR_STSTOPPED && + if (p->disabled && !LIST_ISEMPTY(&p->conf.listeners) && LIST_ELEM(p->conf.listeners.n, struct listener *, by_fe)->state > LI_ASSIGNED) { @@ -1269,7 +1267,7 @@ void soft_stop(void) } } - if (p->state != PR_STSTOPPED) { + if (!p->disabled) { stop_proxy(p); } p = p->next; @@ -1288,7 +1286,7 @@ int pause_proxy(struct proxy *p) { struct listener *l; - if (!(p->cap & PR_CAP_FE) || p->state == PR_STSTOPPED || !p->li_ready) + if (!(p->cap & PR_CAP_FE) || p->disabled || !p->li_ready) return 1; ha_warning("Pausing %s %s.\n", proxy_cap_str(p->cap), p->id); @@ -1318,7 +1316,7 @@ void zombify_proxy(struct proxy *p) if (l->state >= LI_ASSIGNED) delete_listener(l); } - p->state = PR_STSTOPPED; + p->disabled = 1; } /* @@ -1352,7 +1350,7 @@ void stop_proxy(struct proxy *p) } } if (!nostop) - p->state = PR_STSTOPPED; + p->disabled = 1; HA_SPIN_UNLOCK(PROXY_LOCK, &p->lock); } @@ -1367,7 +1365,7 @@ int resume_proxy(struct proxy *p) struct listener *l; int fail; - if (p->state == PR_STSTOPPED || !p->li_paused) + if (p->disabled || !p->li_paused) return 1; ha_warning("Enabling %s %s.\n", proxy_cap_str(p->cap), p->id); @@ -1685,7 +1683,7 @@ void proxy_adjust_all_maxconn() struct switching_rule *swrule1, *swrule2; for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { - if (curproxy->state == PR_STSTOPPED) + if (curproxy->disabled) continue; if (!(curproxy->cap & PR_CAP_FE)) @@ -1729,7 +1727,7 @@ void proxy_adjust_all_maxconn() * loop above because cross-references are not yet fully resolved. */ for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { - if (curproxy->state == PR_STSTOPPED) + if (curproxy->disabled) continue; /* If <fullconn> is not set, let's set it to 10% of the sum of @@ -2187,7 +2185,7 @@ static int cli_parse_shutdown_frontend(char **args, char *payload, struct appctx if (!px) return 1; - if (px->state == PR_STSTOPPED) + if (px->disabled) return cli_msg(appctx, LOG_NOTICE, "Frontend was already shut down.\n"); ha_warning("Proxy %s stopped (cumulated conns: FE: %lld, BE: %lld).\n", @@ -2215,7 +2213,7 @@ static int cli_parse_disable_frontend(char **args, char *payload, struct appctx if (!px) return 1; - if (px->state == PR_STSTOPPED) + if (px->disabled) return cli_msg(appctx, LOG_NOTICE, "Frontend was previously shut down, cannot disable.\n"); if (!px->li_ready) @@ -2247,7 +2245,7 @@ static int cli_parse_enable_frontend(char **args, char *payload, struct appctx * if (!px) return 1; - if (px->state == PR_STSTOPPED) + if (px->disabled) return cli_err(appctx, "Frontend was previously shut down, cannot enable.\n"); if (px->li_ready == px->li_all) diff --git a/src/server.c b/src/server.c index 4de4543b0..45b0f4121 100644 --- a/src/server.c +++ b/src/server.c @@ -4246,7 +4246,7 @@ struct server *cli_find_server(struct appctx *appctx, char *arg) return NULL; } - if (px->state == PR_STSTOPPED) { + if (px->disabled) { cli_err(appctx, "Proxy is disabled.\n"); return NULL; } diff --git a/src/stats.c b/src/stats.c index 132011d27..033ed16e9 100644 --- a/src/stats.c +++ b/src/stats.c @@ -1629,7 +1629,7 @@ int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len) stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); stats[ST_F_DCON] = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn); stats[ST_F_DSES] = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess); - stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : "STOP"); + stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->disabled ? "STOP" : "OPEN"); stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); @@ -3044,9 +3044,7 @@ static int stats_dump_proxies(struct stream_interface *si, px = appctx->ctx.stats.obj1; /* skip the disabled proxies, global frontend and non-networked ones */ - if (px->state != PR_STSTOPPED && px->uuid > 0 - && (px->cap & (PR_CAP_FE | PR_CAP_BE))) { - + if (!px->disabled && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE))) { if (stats_dump_proxy_to_buffer(si, htx, px, uri) == 0) return 0; } @@ -3458,7 +3456,7 @@ static int stats_process_http_post(struct stream_interface *si) total_servers++; break; case ST_ADM_ACTION_SHUTDOWN: - if (px->state != PR_STSTOPPED) { + if (!px->disabled) { srv_shutdown_streams(sv, SF_ERR_KILLED); altered_servers++; total_servers++; diff --git a/src/stick_table.c b/src/stick_table.c index 69bd7adc5..ff93e397c 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -640,7 +640,7 @@ int stktable_init(struct stktable *t) t->exp_task->process = process_table_expire; t->exp_task->context = (void *)t; } - if (t->peers.p && t->peers.p->peers_fe && t->peers.p->peers_fe->state != PR_STSTOPPED) { + if (t->peers.p && t->peers.p->peers_fe && !t->peers.p->peers_fe->disabled) { peers_register_table(t->peers.p, t); } diff --git a/src/stream.c b/src/stream.c index b298d7b79..bcb9acf78 100644 --- a/src/stream.c +++ b/src/stream.c @@ -702,7 +702,7 @@ static void stream_free(struct stream *s) pool_free(pool_head_stream, s); /* We may want to free the maximum amount of pools if the proxy is stopping */ - if (fe && unlikely(fe->state == PR_STSTOPPED)) { + if (fe && unlikely(fe->disabled)) { pool_flush(pool_head_buffer); pool_flush(pool_head_http_txn); pool_flush(pool_head_requri); |