From d166894fef055fee323216733c92945739c3ae97 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 6 Jan 2026 16:36:44 +0100 Subject: [PATCH] MINOR: server: refactor srv_detach() Correct documentation for srv_detach() which previously stated that this function could be called for a server even if not stored in its proxy list. In fact there is a BUG_ON() which detects this case. --- include/haproxy/server.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/include/haproxy/server.h b/include/haproxy/server.h index ba4e6c104..cffc400db 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -350,28 +350,26 @@ static inline int srv_is_transparent(const struct server *srv) (srv->flags & SRV_F_MAPPORTS); } -/* Detach server from proxy list. It is supported to call this - * even if the server is not yet in the list - * Must be called under thread isolation or when it is safe to assume - * that the parent proxy doesn't is not skimming through the server list +/* Detach server from its parent proxy list. + * + * Must be called under thread isolation. */ static inline void srv_detach(struct server *srv) { struct proxy *px = srv->proxy; + struct server *prev; - if (px->srv == srv) + if (px->srv == srv) { px->srv = srv->next; + } else { - struct server *prev; - for (prev = px->srv; prev && prev->next != srv; prev = prev->next) ; - - BUG_ON(!prev); - + BUG_ON(!prev); /* Server instance not found in proxy list ? */ prev->next = srv->next; } - /* reset the proxy's ready_srv if it was this one */ + + /* Reset the proxy's ready_srv if it was this one. */ HA_ATOMIC_CAS(&px->ready_srv, &srv, NULL); }