From d46f437de69d5d4d84a207531a3ba6f8d3d697dc Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Fri, 9 Sep 2022 15:51:37 +0200 Subject: [PATCH] MINOR: proxy/listener: support for additional PAUSED state 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 | 1 + include/haproxy/proxy.h | 2 ++ src/listener.c | 4 ++++ src/proxy.c | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index 0a94d3ab7b..11d9d5763e 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -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; diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 1fc7a09828..01971531b7 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -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); diff --git a/src/listener.c b/src/listener.c index 98d384cda9..bddc29f40d 100644 --- a/src/listener.c +++ b/src/listener.c @@ -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); } diff --git a/src/proxy.c b/src/proxy.c index 7d5989a6ca..04431de282 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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 -- 2.39.5