MINOR: proxy: disabled takes a stopping and a disabled state
authorWilliam Lallemand <wlallemand@haproxy.org>
Tue, 3 Aug 2021 09:58:03 +0000 (11:58 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Tue, 3 Aug 2021 12:17:45 +0000 (14:17 +0200)
This patch splits the disabled state of a proxy into a PR_DISABLED and a
PR_STOPPED state.

The first one is set when the proxy is disabled in the configuration
file, and the second one is set upon a stop_proxy().

include/haproxy/proxy-t.h
src/cfgparse-listen.c
src/cfgparse.c
src/mworker.c
src/proxy.c

index f2a3e7d..a34752b 100644 (file)
@@ -200,6 +200,11 @@ enum PR_SRV_STATE_FILE {
  */
 #define PR_RE_EARLY_ERROR         0x00010000 /* Retry if we failed at sending early data */
 #define PR_RE_JUNK_REQUEST        0x00020000 /* We received an incomplete or garbage response */
+
+/* disabled state */
+#define PR_DISABLED               0x1  /* The proxy was disabled in the configuration (not at runtime) */
+#define PR_STOPPED                0x2  /* The proxy was stopped */
+
 struct stream;
 
 struct http_snapshot {
@@ -254,7 +259,7 @@ struct error_snapshot {
 
 struct proxy {
        enum obj_type obj_type;                 /* object type == OBJ_TYPE_PROXY */
-       char disabled;                          /* non-zero if disabled or shutdown */
+       char disabled;                          /* bit field PR_DISABLED | PR_STOPPED */
        enum pr_mode mode;                      /* mode = PR_MODE_TCP, PR_MODE_HTTP, ... */
        char cap;                               /* supported capabilities (PR_CAP_*) */
        unsigned int maxconn;                   /* max # of active streams on the frontend */
index bdbb603..790566a 100644 (file)
@@ -593,7 +593,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
        else if (strcmp(args[0], "disabled") == 0) {  /* disables this proxy */
                if (alertif_too_many_args(0, file, linenum, args, &err_code))
                        goto out;
-               curproxy->disabled = 1;
+               curproxy->disabled = PR_DISABLED;
        }
        else if (strcmp(args[0], "enabled") == 0) {  /* enables this proxy (used to revert a disabled default) */
                if (alertif_too_many_args(0, file, linenum, args, &err_code))
index 3ac31fc..f7eac97 100644 (file)
@@ -1018,7 +1018,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                stktables_list = t;
        }
        else if (strcmp(args[0], "disabled") == 0) {  /* disables this peers section */
-               curpeers->disabled = 1;
+               curpeers->disabled = PR_DISABLED;
        }
        else if (strcmp(args[0], "enabled") == 0) {  /* enables this peers section (used to revert a disabled default) */
                curpeers->disabled = 0;
index 7842db3..ca1cc74 100644 (file)
@@ -443,7 +443,7 @@ void mworker_cleanlisteners()
                }
                /* if the proxy shouldn't be in the master, we stop it */
                if (!listen_in_master)
-                       curproxy->disabled = 1;
+                       curproxy->disabled = PR_DISABLED;
        }
 }
 
index 245c22b..237f297 100644 (file)
@@ -1801,7 +1801,7 @@ void proxy_cond_disable(struct proxy *p)
        if (p->li_ready + p->li_paused > 0)
                return;
 
-       p->disabled = 1;
+       p->disabled = PR_STOPPED;
 
        /* Note: syslog proxies use their own loggers so while it's somewhat OK
         * to report them being stopped as a warning, we must not spam their log
@@ -2050,7 +2050,7 @@ void stop_proxy(struct proxy *p)
 
        if (!p->disabled && !p->li_ready) {
                /* might be just a backend */
-               p->disabled = 1;
+               p->disabled |= PR_STOPPED;
        }
 
        HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock);