]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy/listener: support for additional PAUSED state
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 9 Sep 2022 13:51:37 +0000 (15:51 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Sep 2022 15:23:01 +0000 (17:23 +0200)
This patch is a prerequisite for #1626.
Adding PAUSED state to the list of available proxy states.
The flag is set when the proxy is paused at runtime (pause_listener()).
It is cleared when the proxy is resumed (resume_listener()).

It should be backported to 2.6, 2.5 and 2.4

include/haproxy/proxy-t.h
include/haproxy/proxy.h
src/listener.c
src/proxy.c

index 0a94d3ab7b094558841c9d487e4e1f146e5c04d7..11d9d5763ec81fd3d52822ffeec802922818ec52 100644 (file)
@@ -211,6 +211,7 @@ enum PR_SRV_STATE_FILE {
 #define PR_FL_READY              0x04  /* The proxy is ready to be used (initialized and configured) */
 #define PR_FL_EXPLICIT_REF       0x08  /* The default proxy is explicitly referenced by another proxy */
 #define PR_FL_IMPLICIT_REF       0x10  /* The default proxy is implicitly referenced by another proxy */
+#define PR_FL_PAUSED             0x20  /* The proxy was paused at run time (reversible) */
 
 struct stream;
 
index 1fc7a09828434ff94afb2cd6e5e3c503bda2c969..01971531b7561bf0fa443711aae3ade4541ad184 100644 (file)
@@ -40,6 +40,8 @@ extern const struct cfg_opt cfg_opts[];
 extern const struct cfg_opt cfg_opts2[];
 
 struct task *manage_proxy(struct task *t, void *context, unsigned int state);
+void proxy_cond_pause(struct proxy *p);
+void proxy_cond_resume(struct proxy *p);
 void proxy_cond_disable(struct proxy *p);
 void soft_stop(void);
 int pause_proxy(struct proxy *p);
index 98d384cda91fd9d67e4ce6c21cb4145935a6a60a..bddc29f40d018ee3356fedce7e39132cc92dc37b 100644 (file)
@@ -481,6 +481,8 @@ int pause_listener(struct listener *l, int lpx)
        listener_set_state(l, LI_PAUSED);
 
        if (px && !px->li_ready) {
+               /* PROXY_LOCK is required */
+               proxy_cond_pause(px);
                ha_warning("Paused %s %s.\n", proxy_cap_str(px->cap), px->id);
                send_log(px, LOG_WARNING, "Paused %s %s.\n", proxy_cap_str(px->cap), px->id);
        }
@@ -540,6 +542,8 @@ int resume_listener(struct listener *l, int lpx)
 
   done:
        if (was_paused && !px->li_paused) {
+               /* PROXY_LOCK is required */
+               proxy_cond_resume(px);
                ha_warning("Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
                send_log(px, LOG_WARNING, "Resumed %s %s.\n", proxy_cap_str(px->cap), px->id);
        }
index 7d5989a6ca8381935616c1e5daa2b85b389476de..04431de28228233b50d9c02a641c3c615dcc6ad0 100644 (file)
@@ -1915,6 +1915,26 @@ struct proxy *parse_new_proxy(const char *name, unsigned int cap,
        return curproxy;
 }
 
+/* to be called under the proxy lock after pausing some listeners. This will
+ * automatically update the p->flags flag
+ */
+void proxy_cond_pause(struct proxy *p)
+{
+       if (p->li_ready)
+               return;
+       p->flags |= PR_FL_PAUSED;
+}
+
+/* to be called under the proxy lock after resuming some listeners. This will
+ * automatically update the p->flags flag
+ */
+void proxy_cond_resume(struct proxy *p)
+{
+       if (!p->li_ready)
+               return;
+       p->flags &= ~PR_FL_PAUSED;
+}
+
 /* to be called under the proxy lock after stopping some listeners. This will
  * automatically update the p->flags flag after stopping the last one, and
  * will emit a log indicating the proxy's condition. The function is idempotent