]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: do not return next server on srv_drop()
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 22 Jul 2026 08:14:35 +0000 (10:14 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 24 Jul 2026 07:32:58 +0000 (09:32 +0200)
Previously, srv_drop() returned the next server entry in the parent
proxy. This was used as convenience during server iteration. However,
the code has evolved several times to better deal with the server
deletion risk. Currently, srv_drop() return value is only used in a
single place.

Thus, this patch simplifies srv_drop() by removing its return value. As
a side effect, this will also reduce the modification required to
convert the proxy server list to a doubly linked struct list.

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

index 5662666a702baa107a5e83b205fc378048fce0db..6d47cb343ea73514dc990784cd7ca1e6e40445c9 100644 (file)
@@ -79,7 +79,7 @@ int srv_init_addr(void);
 struct server *cli_find_server(struct appctx *appctx, char *arg);
 struct server *new_server(struct proxy *proxy);
 void srv_take(struct server *srv);
-struct server *srv_drop(struct server *srv);
+void srv_drop(struct server *srv);
 void srv_free_params(struct server *srv);
 int srv_preinit(struct server *srv);
 int srv_set_ssl(struct server *s, int use_ssl);
index 7a87d79de69c577d01b956c2e5c2a640b7bcd1b6..a1906f25259b04e5a67e2d4516004395fd135512 100644 (file)
@@ -326,7 +326,7 @@ static inline void proxy_free_common(struct proxy *px)
  */
 void deinit_proxy(struct proxy *p)
 {
-       struct server *s;
+       struct server *s, *s_next;
        struct cap_hdr *h,*h_next;
        struct listener *l,*l_next;
        struct bind_conf *bind_conf, *bind_back;
@@ -414,7 +414,9 @@ void deinit_proxy(struct proxy *p)
                if (p->lbprm.ops && p->lbprm.ops->server_deinit)
                        p->lbprm.ops->server_deinit(s);
 
-               s = srv_drop(s);
+               s_next = s->next;
+               srv_drop(s);
+               s = s_next;
        }/* end while(s) */
 
        /* also free default-server parameters since some of them might have
index 1dc5e10012dc43165236081a31509ab20506740b..94a8e9772fb6f882ac75a5a88b088b87086070ff 100644 (file)
@@ -3260,20 +3260,14 @@ void srv_free_params(struct server *srv)
  *
  * A general rule is to assume that proxy may already be freed, so cleanup checks
  * must not depend on the proxy
- *
- * As a convenience, <srv.next> is returned if srv is not NULL. It may be useful
- * when calling srv_drop on the list of servers.
  */
-struct server *srv_drop(struct server *srv)
+void srv_drop(struct server *srv)
 {
-       struct server *next = NULL;
        struct proxy *px = NULL;
        int i __maybe_unused;
 
        if (!srv)
-               goto end;
-
-       next = srv->next;
+               return;
 
        /* If srv was deleted, a proxy refcount must be dropped. */
        if (srv->flags & SRV_F_DELETED)
@@ -3283,7 +3277,7 @@ struct server *srv_drop(struct server *srv)
         * server when reaching zero.
         */
        if (HA_ATOMIC_SUB_FETCH(&srv->refcount, 1))
-               goto end;
+               return;
 
        /* This BUG_ON() is invalid for now as server released on deinit will
         * trigger it as they are not properly removed from their tree.
@@ -3322,9 +3316,6 @@ struct server *srv_drop(struct server *srv)
        srv_free(&srv);
 
        proxy_drop(px);
-
- end:
-       return next;
 }
 
 /* Remove a server <srv> from a tracking list if <srv> is tracking another