mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-05-04 12:41:00 +02:00
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.
This commit is contained in:
parent
583a947123
commit
194bad6aaf
@ -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 */
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
100
src/lb_map.c
100
src/lb_map.c
@ -17,54 +17,6 @@
|
||||
#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;
|
||||
|
||||
62
src/lb_ss.c
62
src/lb_ss.c
@ -23,6 +23,36 @@
|
||||
#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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user