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.
diff --git a/include/haproxy/peers-t.h b/include/haproxy/peers-t.h
index 0f8db66..41e94d4 100644
--- a/include/haproxy/peers-t.h
+++ b/include/haproxy/peers-t.h
@@ -82,7 +82,6 @@
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 @@
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 a711ed8..92d02ca 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -730,7 +730,7 @@
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 @@
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 @@
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 @@
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 d76a1f8..8402cf3 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -3065,11 +3065,11 @@
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),