]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: proxy: extract proxy runtime deletion in a specific function
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 30 Sep 2026 12:41:15 +0000 (14:41 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 14 Oct 2026 09:33:41 +0000 (11:33 +0200)
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.

include/haproxy/proxy.h
src/proxy.c

index 77589317d6bda8a7d69175e91ae63112d6c98e77..a6bf3b5c9d12e2fa7b01b7baf8b9e001973a0954 100644 (file)
@@ -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
index 0aaeafa7ac49e9c6b4ac545d5e9461d7c8d9bbed..7312adb114889c880c0d7ffda433076cb99fcbce 100644 (file)
@@ -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 <px> 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 <name>.\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 <name>.\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");