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.
This commit is contained in:
Willy Tarreau 2020-09-24 08:48:08 +02:00
parent b50bf046e8
commit 1ad64acf6c
3 changed files with 8 additions and 8 deletions

View File

@ -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 */

View File

@ -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);

View File

@ -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),