]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: server: refactor srv_detach()
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 6 Jan 2026 15:36:44 +0000 (16:36 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 26 Feb 2026 17:24:36 +0000 (18:24 +0100)
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

index ba4e6c10430001be0e24eaee7a69590d30b0e358..cffc400dbc264c97fae4e088fb1155095a3ecf84 100644 (file)
@@ -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 <srv> 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);
 }