From 194bad6aaf32734e7548a5b0b4c20215b98b5b21 Mon Sep 17 00:00:00 2001 From: Maxime Henrion Date: Mon, 27 Apr 2026 15:29:22 -0400 Subject: [PATCH] MINOR: lb: cleanups 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. --- include/haproxy/backend-t.h | 14 ----- include/haproxy/lb_chash.h | 1 - include/haproxy/lb_fas.h | 1 - include/haproxy/lb_fwlc.h | 1 - include/haproxy/lb_fwrr.h | 1 - include/haproxy/lb_map.h | 2 - include/haproxy/lb_ss.h | 2 - src/lb_chash.c | 12 ++--- src/lb_fas.c | 2 +- src/lb_fwlc.c | 2 +- src/lb_fwrr.c | 2 +- src/lb_map.c | 100 ++++++++++++++++++------------------ src/lb_ss.c | 62 +++++++++++----------- 13 files changed, 90 insertions(+), 112 deletions(-) diff --git a/include/haproxy/backend-t.h b/include/haproxy/backend-t.h index 8243c3cdf..b966ff321 100644 --- a/include/haproxy/backend-t.h +++ b/include/haproxy/backend-t.h @@ -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 */ diff --git a/include/haproxy/lb_chash.h b/include/haproxy/lb_chash.h index c96285dff..9ffb59c06 100644 --- a/include/haproxy/lb_chash.h +++ b/include/haproxy/lb_chash.h @@ -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); diff --git a/include/haproxy/lb_fas.h b/include/haproxy/lb_fas.h index fb81b3a93..55ef90a67 100644 --- a/include/haproxy/lb_fas.h +++ b/include/haproxy/lb_fas.h @@ -29,7 +29,6 @@ #include 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; diff --git a/include/haproxy/lb_fwlc.h b/include/haproxy/lb_fwlc.h index d5dc0c471..fae30ada5 100644 --- a/include/haproxy/lb_fwlc.h +++ b/include/haproxy/lb_fwlc.h @@ -29,7 +29,6 @@ #include 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; diff --git a/include/haproxy/lb_fwrr.h b/include/haproxy/lb_fwrr.h index 0e37850a6..2b3f5ad9c 100644 --- a/include/haproxy/lb_fwrr.h +++ b/include/haproxy/lb_fwrr.h @@ -28,7 +28,6 @@ #include #include -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; diff --git a/include/haproxy/lb_map.h b/include/haproxy/lb_map.h index 67d5e341d..c4f624600 100644 --- a/include/haproxy/lb_map.h +++ b/include/haproxy/lb_map.h @@ -27,8 +27,6 @@ #include #include -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); diff --git a/include/haproxy/lb_ss.h b/include/haproxy/lb_ss.h index 1696e7538..063c7fd2d 100644 --- a/include/haproxy/lb_ss.h +++ b/include/haproxy/lb_ss.h @@ -27,8 +27,6 @@ #include #include -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; diff --git a/src/lb_chash.c b/src/lb_chash.c index 60f92da8d..abbdcc645 100644 --- a/src/lb_chash.c +++ b/src/lb_chash.c @@ -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 . 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; diff --git a/src/lb_fas.c b/src/lb_fas.c index add9eb7b8..9cf000cc6 100644 --- a/src/lb_fas.c +++ b/src/lb_fas.c @@ -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; diff --git a/src/lb_fwlc.c b/src/lb_fwlc.c index 92bb6a341..394ce9ef8 100644 --- a/src/lb_fwlc.c +++ b/src/lb_fwlc.c @@ -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; diff --git a/src/lb_fwrr.c b/src/lb_fwrr.c index 9ab6ceae8..0b6113baf 100644 --- a/src/lb_fwrr.c +++ b/src/lb_fwrr.c @@ -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; diff --git a/src/lb_map.c b/src/lb_map.c index 1b74c217c..bb6ffb8f7 100644 --- a/src/lb_map.c +++ b/src/lb_map.c @@ -17,54 +17,6 @@ #include #include -/* this function updates the map according to server '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 '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 '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 '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; diff --git a/src/lb_ss.c b/src/lb_ss.c index 40edfbfe3..add9f19dd 100644 --- a/src/lb_ss.c +++ b/src/lb_ss.c @@ -23,6 +23,36 @@ #include #include +/* 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 '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;