From: Amaury Denoyelle Date: Wed, 30 Sep 2026 12:41:15 +0000 (+0200) Subject: MINOR: proxy: extract proxy runtime deletion in a specific function X-Git-Tag: v3.5-dev9~7 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=1525e169e4957edb73827b7e3f18f063038f1614;p=haproxy.git MINOR: proxy: extract proxy runtime deletion in a specific function A new function be_unregister() is created, with content extracted from the main body of "delete backend" CLI parser. This is necessary to support different methods for backend deletion. --- diff --git a/include/haproxy/proxy.h b/include/haproxy/proxy.h index 77589317d..a6bf3b5c9 100644 --- a/include/haproxy/proxy.h +++ b/include/haproxy/proxy.h @@ -104,6 +104,7 @@ int proxy_init_per_thr(struct proxy *px); int proxy_finalize(struct proxy *px, int *err_code); int be_check_for_deletion(const char *bename, struct proxy **pb, const char **pm); +void be_unregister(struct proxy *px); /* * This function returns a string containing the type of the proxy in a format diff --git a/src/proxy.c b/src/proxy.c index 0aaeafa7a..7312adb11 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -5433,32 +5433,21 @@ int be_check_for_deletion(const char *bename, struct proxy **pb, const char **pm return ret; } -/* Handler for "delete backend". Runs under thread isolation. Always returns 1. */ -static int cli_parse_delete_backend(char **args, char *payload, struct appctx *appctx, void *private) +/* Removes from its attach point in the process. + * + * This operation is mandatory prior the runtime removal of a backend. Once + * detached, the backend is flagged for deletion. + * + * This function cannot fail. This operation is not thread-safe and must only + * be called under thread isolation. + */ +void be_unregister(struct proxy *px) { struct event_hdl_cb_data_proxy e_cb_data; struct watcher *px_watch; - struct proxy *px; - const char *msg; - char *be_name; - int ret; - - if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) - return 1; - - if (*args[3]) { - cli_err(appctx, "Usage: del backend .\n"); - return 1; - } - thread_isolate_full(); - - be_name = args[2]; - ret = be_check_for_deletion(be_name, &px, &msg); - if (ret <= 0) { - cli_err(appctx, msg); - goto out; - } + /* must be a plain backend, not a frontend nor a listen */ + BUG_ON((px->cap & PR_CAP_LISTEN) != PR_CAP_BE); while (!MT_LIST_ISEMPTY(&px->watcher_list)) { px_watch = MT_LIST_NEXT(&px->watcher_list, struct watcher *, el); @@ -5481,7 +5470,34 @@ static int cli_parse_delete_backend(char **args, char *payload, struct appctx *a /* backend deletion cannot fail anymore, time to publish the PROXY_DEL event */ _proxy_event_hdl_prepare(&e_cb_data, px); _proxy_event_hdl_publish(EVENT_HDL_SUB_PROXY_DEL, e_cb_data, px); +} + +/* Handler for "delete backend". Runs under thread isolation. Always returns 1. */ +static int cli_parse_delete_backend(char **args, char *payload, struct appctx *appctx, void *private) +{ + struct proxy *px; + const char *msg; + char *be_name; + int ret; + + if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) + return 1; + + if (*args[3]) { + cli_err(appctx, "Usage: del backend .\n"); + return 1; + } + + thread_isolate_full(); + + be_name = args[2]; + ret = be_check_for_deletion(be_name, &px, &msg); + if (ret <= 0) { + cli_err(appctx, msg); + goto out; + } + be_unregister(px); thread_release(); ha_notice("Backend deleted.\n");