]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: lb: cleanups
authorMaxime Henrion <mhenrion@haproxy.com>
Mon, 27 Apr 2026 19:29:22 +0000 (15:29 -0400)
committerOlivier Houchard <cognet@ci0.org>
Tue, 28 Apr 2026 13:31:51 +0000 (15:31 +0200)
Remove exports for functions that are not called directly anymore, and
make them static. This involves some reordering to avoid the need for a
forward static declaration.

Also remove the old callback fields from the lbprm struct.

13 files changed:
include/haproxy/backend-t.h
include/haproxy/lb_chash.h
include/haproxy/lb_fas.h
include/haproxy/lb_fwlc.h
include/haproxy/lb_fwrr.h
include/haproxy/lb_map.h
include/haproxy/lb_ss.h
src/lb_chash.c
src/lb_fas.c
src/lb_fwlc.c
src/lb_fwrr.c
src/lb_map.c
src/lb_ss.c

index 8243c3cdf3c359cc12e5c9503d0048acd865e662..b966ff321a02da7f967a410202b6743f68291a06 100644 (file)
@@ -198,20 +198,6 @@ struct lbprm {
        __decl_thread(HA_RWLOCK_T lock);
        struct server *fbck;            /* first backup server when !PR_O_USE_ALL_BK, or NULL */
        const struct lb_ops *ops;       /* algo-specific operations; NULL = no LB algo selected */
-
-       /* Call backs for some actions. Any of them may be NULL (thus should be ignored).
-        * Those marked "srvlock" will need to be called with the server lock held.
-        * The other ones might take it themselves if needed.
-        */
-       void (*update_server_eweight)(struct server *);  /* to be called after eweight change // srvlock */
-       void (*set_server_status_up)(struct server *);   /* to be called after status changes to UP // srvlock */
-       void (*set_server_status_down)(struct server *); /* to be called after status changes to DOWN // srvlock */
-       void (*server_take_conn)(struct server *);       /* to be called when connection is assigned */
-       void (*server_drop_conn)(struct server *);       /* to be called when connection is dropped */
-       void (*server_requeue)(struct server *);         /* function used to place the server where it must be */
-       void (*proxy_deinit)(struct proxy *);            /* to be called when we're destroying the proxy */
-       void (*server_deinit)(struct server *);          /* to be called when we're destroying the server */
-       int (*server_init)(struct server *);             /* initialize a freshly added server (runtime); <0=fail. */
 };
 
 #endif /* _HAPROXY_BACKEND_T_H */
index c96285dffdc0839bab795d05e9d8cce8b81ccfb7..9ffb59c063d62e2218767227ce19525d9f90d565 100644 (file)
@@ -28,7 +28,6 @@
 
 struct proxy;
 struct server;
-int chash_init_server_tree(struct proxy *p);
 struct server *chash_get_next_server(struct proxy *p, struct server *srvtoavoid);
 struct server *chash_get_server_hash(struct proxy *p, unsigned int hash, const struct server *avoid);
 
index fb81b3a9368dea9b46ae2735761b6701f16c644d..55ef90a676a5082aa79df29843ac7642e58ef853 100644 (file)
@@ -29,7 +29,6 @@
 #include <haproxy/server-t.h>
 
 struct server *fas_get_next_server(struct proxy *p, struct server *srvtoavoid);
-int fas_init_server_tree(struct proxy *p);
 
 extern const struct lb_ops lb_fas_ops;
 
index d5dc0c471238380f674e5367f702432b5c97abee..fae30ada5ddc39ee87156f533e0d9d79798e15e1 100644 (file)
@@ -29,7 +29,6 @@
 #include <haproxy/server-t.h>
 
 struct server *fwlc_get_next_server(struct proxy *p, struct server *srvtoavoid);
-int fwlc_init_server_tree(struct proxy *p);
 
 extern const struct lb_ops lb_fwlc_ops;
 
index 0e37850a65a8edd97a002346a157ea9a7c03e555..2b3f5ad9cc0dc4df21773bb72afdcfa783912d01 100644 (file)
@@ -28,7 +28,6 @@
 #include <haproxy/proxy-t.h>
 #include <haproxy/server-t.h>
 
-int fwrr_init_server_groups(struct proxy *p);
 struct server *fwrr_get_next_server(struct proxy *p, struct server *srvtoavoid);
 
 extern const struct lb_ops lb_fwrr_ops;
index 67d5e341d90932d152c15b1fd5980adae2855510..c4f624600a18e2418bde412f1d16c5b4871701b2 100644 (file)
@@ -27,8 +27,6 @@
 #include <haproxy/proxy-t.h>
 #include <haproxy/server-t.h>
 
-void recalc_server_map(struct proxy *px);
-int init_server_map(struct proxy *p);
 struct server *map_get_server_rr(struct proxy *px, struct server *srvtoavoid);
 struct server *map_get_server_hash(struct proxy *px, unsigned int hash);
 
index 1696e7538ea995fc6a38dea91d8626e6a26d6a6f..063c7fd2d852beb673e15f74401fe3de6ce8ba3f 100644 (file)
@@ -27,8 +27,6 @@
 #include <haproxy/proxy-t.h>
 #include <haproxy/server-t.h>
 
-void recalc_server_ss(struct proxy *px);
-int init_server_ss(struct proxy *px);
 struct server *ss_get_server(struct proxy *px);
 
 extern const struct lb_ops lb_ss_ops;
index 60f92da8d52d77f87d2284c6d342cf0fc46fa07c..abbdcc64534a00081e0a2a371fa50cde544c69b9 100644 (file)
@@ -364,7 +364,7 @@ static void chash_update_server_weight(struct server *srv)
  * of Mirrokni, Thorup, and Zadimoghaddam (arxiv:1608.01350), adapted for use with
  * unequal server weights.
  */
-int chash_server_is_eligible(struct server *s)
+static int chash_server_is_eligible(struct server *s)
 {
        /* The total number of slots to allocate is the total number of outstanding requests
         * (including the one we're about to make) times the load-balance-factor, rounded up.
@@ -553,10 +553,10 @@ struct server *chash_get_next_server(struct proxy *p, struct server *srvtoavoid)
 }
 
 /* Allocates and initializes lb nodes for server <srv>. Returns < 0 on error.
- * This is called by chash_init_server_tree() as well as from srv_alloc_lb()
- * for runtime addition.
+ * This is called by chash_init_server_tree() as well as via the ops table
+ * from srv_alloc_lb() for runtime addition.
  */
-int chash_server_init(struct server *srv)
+static int chash_server_init(struct server *srv)
 {
        int node;
 
@@ -573,7 +573,7 @@ int chash_server_init(struct server *srv)
 }
 
 /* Releases the allocated lb_nodes for this server */
-void chash_server_deinit(struct server *srv)
+static void chash_server_deinit(struct server *srv)
 {
        ha_free(&srv->lb_nodes);
 }
@@ -584,7 +584,7 @@ void chash_server_deinit(struct server *srv)
  * uweight ratio.
  * Return 0 in case of success, -1 in case of allocation failure.
  */
-int chash_init_server_tree(struct proxy *p)
+static int chash_init_server_tree(struct proxy *p)
 {
        struct server *srv;
        struct eb_root init_head = EB_ROOT;
index add9eb7b8c0ecb001a4a2f2efb45c56f5737374b..9cf000cc671bed55403cb77d64f44142c22ae7a8 100644 (file)
@@ -255,7 +255,7 @@ static void fas_update_server_weight(struct server *srv)
  * weighted least-conns. It also sets p->lbprm.wdiv to the eweight to
  * uweight ratio. Both active and backup groups are initialized.
  */
-int fas_init_server_tree(struct proxy *p)
+static int fas_init_server_tree(struct proxy *p)
 {
        struct server *srv;
        struct eb_root init_head = EB_ROOT;
index 92bb6a34122869950f255c67aa818afa9a1680c5..394ce9ef861193882058448867ac3e4cb6a95b11 100644 (file)
@@ -709,7 +709,7 @@ static void fwlc_update_server_weight(struct server *srv)
  * weighted least-conns. It also sets p->lbprm.wdiv to the eweight to
  * uweight ratio. Both active and backup groups are initialized.
  */
-int fwlc_init_server_tree(struct proxy *p)
+static int fwlc_init_server_tree(struct proxy *p)
 {
        struct server *srv;
        struct eb_root init_head = EB_ROOT;
index 9ab6ceae82e355630be138639988a00804f29494..0b6113baf81b6cddf2265eaf3057f8321076a0f6 100644 (file)
@@ -293,7 +293,7 @@ static inline void fwrr_queue_by_weight(struct eb_root *root, struct server *s,
  * weighted round-robin. It also sets p->lbprm.wdiv to the eweight to uweight
  * ratio. Both active and backup groups are initialized.
  */
-int fwrr_init_server_groups(struct proxy *p)
+static int fwrr_init_server_groups(struct proxy *p)
 {
        struct server *srv;
        struct eb_root init_head = EB_ROOT;
index 1b74c217c407e4c5c156df899a2f369fb154128c..bb6ffb8f7efd6e3f1c6ff81f2e937e3770d139ef 100644 (file)
 #include <haproxy/queue.h>
 #include <haproxy/server-t.h>
 
-/* this function updates the map according to server <srv>'s new state.
- *
- * The server's lock must be held. The lbprm's lock will be used.
- */
-static void map_set_server_status_down(struct server *srv)
-{
-       struct proxy *p = srv->proxy;
-
-       if (!srv_lb_status_changed(srv))
-               return;
-
-       if (srv_willbe_usable(srv))
-               goto out_update_state;
-
-       /* FIXME: could be optimized since we know what changed */
-       HA_RWLOCK_WRLOCK(LBPRM_LOCK, &p->lbprm.lock);
-       recount_servers(p);
-       update_backend_weight(p);
-       recalc_server_map(p);
-       HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
- out_update_state:
-       srv_lb_commit_status(srv);
-}
-
-/* This function updates the map according to server <srv>'s new state.
- *
- * The server's lock must be held. The lbprm's lock will be used.
- */
-static void map_set_server_status_up(struct server *srv)
-{
-       struct proxy *p = srv->proxy;
-
-       if (!srv_lb_status_changed(srv))
-               return;
-
-       if (!srv_willbe_usable(srv))
-               goto out_update_state;
-
-       /* FIXME: could be optimized since we know what changed */
-       HA_RWLOCK_WRLOCK(LBPRM_LOCK, &p->lbprm.lock);
-       recount_servers(p);
-       update_backend_weight(p);
-       recalc_server_map(p);
-       HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
- out_update_state:
-       srv_lb_commit_status(srv);
-}
-
 /* This function recomputes the server map for proxy px. It relies on
  * px->lbprm.tot_wact, tot_wbck, tot_used, tot_weight, so it must be
  * called after recount_servers(). It also expects px->lbprm.map.srv
@@ -72,7 +24,7 @@ static void map_set_server_status_up(struct server *srv)
  *
  * The lbprm's lock must be held.
  */
-void recalc_server_map(struct proxy *px)
+static void recalc_server_map(struct proxy *px)
 {
        int o, tot, flag;
        struct server *cur, *best;
@@ -132,12 +84,60 @@ void recalc_server_map(struct proxy *px)
        }
 }
 
+/* this function updates the map according to server <srv>'s new state.
+ *
+ * The server's lock must be held. The lbprm's lock will be used.
+ */
+static void map_set_server_status_down(struct server *srv)
+{
+       struct proxy *p = srv->proxy;
+
+       if (!srv_lb_status_changed(srv))
+               return;
+
+       if (srv_willbe_usable(srv))
+               goto out_update_state;
+
+       /* FIXME: could be optimized since we know what changed */
+       HA_RWLOCK_WRLOCK(LBPRM_LOCK, &p->lbprm.lock);
+       recount_servers(p);
+       update_backend_weight(p);
+       recalc_server_map(p);
+       HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
+ out_update_state:
+       srv_lb_commit_status(srv);
+}
+
+/* This function updates the map according to server <srv>'s new state.
+ *
+ * The server's lock must be held. The lbprm's lock will be used.
+ */
+static void map_set_server_status_up(struct server *srv)
+{
+       struct proxy *p = srv->proxy;
+
+       if (!srv_lb_status_changed(srv))
+               return;
+
+       if (!srv_willbe_usable(srv))
+               goto out_update_state;
+
+       /* FIXME: could be optimized since we know what changed */
+       HA_RWLOCK_WRLOCK(LBPRM_LOCK, &p->lbprm.lock);
+       recount_servers(p);
+       update_backend_weight(p);
+       recalc_server_map(p);
+       HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
+ out_update_state:
+       srv_lb_commit_status(srv);
+}
+
 /* This function is responsible of building the server MAP for map-based LB
  * algorithms, allocating the map, and setting p->lbprm.wmult to the GCD of the
  * weights if applicable. It should be called only once per proxy, at config
  * time.
  */
-int init_server_map(struct proxy *p)
+static int init_server_map(struct proxy *p)
 {
        struct server *srv;
        int pgcd;
index 40edfbfe3e44f2cb47185722cfebcc2b65dc82f3..add9f19dd5d39a585b0a77a2a6e220ae062ca0e7 100644 (file)
 #include <haproxy/lb_ss.h>
 #include <haproxy/server-t.h>
 
+/* This function elects a new stick server for proxy px.
+ *
+ * The lbprm's lock must be held.
+ */
+static void recalc_server_ss(struct proxy *px)
+{
+       struct server *cur, *first;
+       int flag;
+
+       if (!px->lbprm.tot_used)
+               return; /* no server */
+
+       /* here we *know* that we have some servers */
+       if (px->srv_act)
+               flag = 0;
+       else
+               flag = SRV_F_BACKUP;
+
+       first = NULL;
+
+       for (cur = px->srv; cur; cur = cur->next) {
+               if ((cur->flags & SRV_F_BACKUP) == flag &&
+                   srv_willbe_usable(cur)) {
+                       first = cur;
+                       break;
+               }
+       }
+       px->lbprm.ss.srv = first;
+}
+
 /* this function updates the stick server according to server <srv>'s new state.
  *
  * The server's lock must be held. The lbprm's lock will be used.
@@ -110,40 +140,10 @@ static void ss_set_server_status_up(struct server *srv)
        srv_lb_commit_status(srv);
 }
 
-/* This function elects a new stick server for proxy px.
- *
- * The lbprm's lock must be held.
- */
-void recalc_server_ss(struct proxy *px)
-{
-       struct server *cur, *first;
-       int flag;
-
-       if (!px->lbprm.tot_used)
-               return; /* no server */
-
-       /* here we *know* that we have some servers */
-       if (px->srv_act)
-               flag = 0;
-       else
-               flag = SRV_F_BACKUP;
-
-       first = NULL;
-
-       for (cur = px->srv; cur; cur = cur->next) {
-               if ((cur->flags & SRV_F_BACKUP) == flag &&
-                   srv_willbe_usable(cur)) {
-                       first = cur;
-                       break;
-               }
-       }
-       px->lbprm.ss.srv = first;
-}
-
 /* This function is responsible for preparing sticky LB algorithm.
  * It should be called only once per proxy, at config time.
  */
-int init_server_ss(struct proxy *p)
+static int init_server_ss(struct proxy *p)
 {
        struct server *srv;