diff options
author | Willy Tarreau <w@1wt.eu> | 2020-09-24 08:48:08 +0200 |
---|---|---|
committer | Willy Tarreau <w@1wt.eu> | 2020-10-07 18:44:08 +0200 |
commit | 2c2e783dc3853589e2af346c7f82a10c6bfdac0a (patch) | |
tree | 301d70fed72caac0ee24fe16ac116d58f170ce1c | |
parent | 5ec52697cc93b1d04be4146df3808d6b7323dba8 (diff) | |
download | haproxy-2c2e783dc3853589e2af346c7f82a10c6bfdac0a.tar.gz |
CLEANUP: peers: don't use the PR_ST* states to mark enabled/disabled
The enabled/disabled config options were stored into a "state" field
that is an integer but contained only PR_STNEW or PR_STSTOPPED, which
is a bit confusing, and causes a dependency with proxies. This was
renamed to "disabled" and is used as a boolean. The field was also
moved to the end of the struct to stop creating a hole and fill another
one.
-rw-r--r-- | include/haproxy/peers-t.h | 2 | ||||
-rw-r--r-- | src/cfgparse.c | 10 | ||||
-rw-r--r-- | src/peers.c | 4 |
3 files changed, 8 insertions, 8 deletions
diff --git a/include/haproxy/peers-t.h b/include/haproxy/peers-t.h index 0f8db66cc..41e94d45b 100644 --- a/include/haproxy/peers-t.h +++ b/include/haproxy/peers-t.h @@ -82,7 +82,6 @@ struct peer { struct peers { - int state; /* proxy state */ char *id; /* peer section name */ struct task *sync_task; /* main sync task */ struct sig_handler *sighandler; /* signal handler */ @@ -98,6 +97,7 @@ struct peers { unsigned int flags; /* current peers section resync state */ unsigned int resync_timeout; /* resync timeout timer */ int count; /* total of peers */ + int disabled; /* peers proxy disabled if >0 */ }; /* LRU cache for dictionaies */ diff --git a/src/cfgparse.c b/src/cfgparse.c index a711ed842..92d02cad2 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -730,7 +730,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) curpeers->conf.line = linenum; curpeers->last_change = now.tv_sec; curpeers->id = strdup(args[1]); - curpeers->state = PR_STNEW; + curpeers->disabled = 0; } else if (strcmp(args[0], "peer") == 0 || strcmp(args[0], "server") == 0) { /* peer or server definition */ @@ -902,10 +902,10 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) stktables_list = t; } else if (!strcmp(args[0], "disabled")) { /* disables this peers section */ - curpeers->state = PR_STSTOPPED; + curpeers->disabled = 1; } else if (!strcmp(args[0], "enabled")) { /* enables this peers section (used to revert a disabled default) */ - curpeers->state = PR_STNEW; + curpeers->disabled = 0; } else if (*args[0] != 0) { ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); @@ -2798,7 +2798,7 @@ int check_config_validity() curproxy->table->peers.p = NULL; cfgerr++; } - else if (curpeers->state == PR_STSTOPPED) { + else if (curpeers->disabled) { /* silently disable this peers section */ curproxy->table->peers.p = NULL; } @@ -3851,7 +3851,7 @@ out_uri_auth_compat: struct stktable *t; curpeers = *last; - if (curpeers->state == PR_STSTOPPED) { + if (curpeers->disabled) { /* the "disabled" keyword was present */ if (curpeers->peers_fe) stop_proxy(curpeers->peers_fe); diff --git a/src/peers.c b/src/peers.c index d76a1f876..8402cf329 100644 --- a/src/peers.c +++ b/src/peers.c @@ -3065,11 +3065,11 @@ static int peers_dump_head(struct buffer *msg, struct stream_interface *si, stru struct tm tm; get_localtime(peers->last_change, &tm); - chunk_appendf(msg, "%p: [%02d/%s/%04d:%02d:%02d:%02d] id=%s state=%d flags=0x%x resync_timeout=%s task_calls=%u\n", + chunk_appendf(msg, "%p: [%02d/%s/%04d:%02d:%02d:%02d] id=%s disabled=%d flags=0x%x resync_timeout=%s task_calls=%u\n", peers, tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec, - peers->id, peers->state, peers->flags, + peers->id, peers->disabled, peers->flags, peers->resync_timeout ? tick_is_expired(peers->resync_timeout, now_ms) ? "<PAST>" : human_time(TICKS_TO_MS(peers->resync_timeout - now_ms), |