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);
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) {
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) {
/* 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;
#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,
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 */
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;
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;
{
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;
if (!(from->cap & PR_CAP_FE))
return;
- if (from->state == PR_STSTOPPED)
+ if (from->disabled)
return;
/* default_backend */
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.
* 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)) {
* 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 */
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 */
* 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 */
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) {
/* stop disabled proxies */
for (px = proxies_list; px; px = px->next) {
- if (px->state == PR_STSTOPPED)
+ if (px->disabled)
stop_proxy(px);
}
/* 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);
/* 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);
}
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.
}
/* 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);
}
}
/* 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);
}
}
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.
}
/* if the proxy shouldn't be in the master, we stop it */
if (!listen_in_master)
- curproxy->state = PR_STSTOPPED;
+ curproxy->disabled = 1;
}
}
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);
}
}
*/
/* 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) {
* 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);
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);
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) {
}
}
- if (p->state != PR_STSTOPPED) {
+ if (!p->disabled) {
stop_proxy(p);
}
p = p->next;
{
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);
if (l->state >= LI_ASSIGNED)
delete_listener(l);
}
- p->state = PR_STSTOPPED;
+ p->disabled = 1;
}
/*
}
}
if (!nostop)
- p->state = PR_STSTOPPED;
+ p->disabled = 1;
HA_SPIN_UNLOCK(PROXY_LOCK, &p->lock);
}
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);
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))
* 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
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",
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)
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)
return NULL;
}
- if (px->state == PR_STSTOPPED) {
+ if (px->disabled) {
cli_err(appctx, "Proxy is disabled.\n");
return NULL;
}
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);
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;
}
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++;
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);
}
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);