]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: peers: don't use the PR_ST* states to mark enabled/disabled
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Sep 2020 06:48:08 +0000 (08:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 09:27:30 +0000 (11:27 +0200)
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.

include/haproxy/peers-t.h
src/cfgparse.c
src/peers.c

index 0f8db66cc38e768c2724664840417ca0429d94ab..41e94d45b4fee1bc83d96b4fb80f27fbc9fd9b1e 100644 (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 */
index a711ed842fc80ce9d6491b51b9067843c072faf9..92d02cad2b15c4571c89405b9b40bdbe815bf28e 100644 (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);
index d76a1f87650e054b858deddb54bcb568b3315eb4..8402cf3299f2d6fa03037e753186a21048aff667 100644 (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),