mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-05-02 19:51:00 +02:00
MEDIUM: lb: use the LB ops tables
Remove manual initialization of the callbacks and use the ops field in the lbprm struct to invoke those callbacks.
This commit is contained in:
parent
16a4de0d5c
commit
583a947123
@ -2271,8 +2271,8 @@ int connect_server(struct stream *s)
|
||||
s->flags |= SF_CURR_SESS;
|
||||
count = _HA_ATOMIC_ADD_FETCH(&srv->cur_sess, 1);
|
||||
COUNTERS_UPDATE_MAX(&srv->counters.cur_sess_max, count);
|
||||
if (s->be->lbprm.server_take_conn)
|
||||
s->be->lbprm.server_take_conn(srv);
|
||||
if (s->be->lbprm.ops && s->be->lbprm.ops->server_take_conn)
|
||||
s->be->lbprm.ops->server_take_conn(srv);
|
||||
}
|
||||
|
||||
/* Now handle synchronously connected sockets. We know the stream connector
|
||||
|
||||
@ -589,14 +589,6 @@ int chash_init_server_tree(struct proxy *p)
|
||||
struct server *srv;
|
||||
struct eb_root init_head = EB_ROOT;
|
||||
|
||||
p->lbprm.set_server_status_up = chash_set_server_status_up;
|
||||
p->lbprm.set_server_status_down = chash_set_server_status_down;
|
||||
p->lbprm.update_server_eweight = chash_update_server_weight;
|
||||
p->lbprm.server_init = chash_server_init;
|
||||
p->lbprm.server_deinit = chash_server_deinit;
|
||||
p->lbprm.server_take_conn = NULL;
|
||||
p->lbprm.server_drop_conn = NULL;
|
||||
|
||||
p->lbprm.wdiv = BE_WEIGHT_SCALE;
|
||||
for (srv = p->srv; srv; srv = srv->next) {
|
||||
srv->next_eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
|
||||
|
||||
@ -260,12 +260,6 @@ int fas_init_server_tree(struct proxy *p)
|
||||
struct server *srv;
|
||||
struct eb_root init_head = EB_ROOT;
|
||||
|
||||
p->lbprm.set_server_status_up = fas_set_server_status_up;
|
||||
p->lbprm.set_server_status_down = fas_set_server_status_down;
|
||||
p->lbprm.update_server_eweight = fas_update_server_weight;
|
||||
p->lbprm.server_take_conn = fas_srv_reposition;
|
||||
p->lbprm.server_drop_conn = fas_srv_reposition;
|
||||
|
||||
p->lbprm.wdiv = BE_WEIGHT_SCALE;
|
||||
for (srv = p->srv; srv; srv = srv->next) {
|
||||
srv->next_eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
|
||||
|
||||
@ -714,15 +714,6 @@ int fwlc_init_server_tree(struct proxy *p)
|
||||
struct server *srv;
|
||||
struct eb_root init_head = EB_ROOT;
|
||||
|
||||
p->lbprm.set_server_status_up = fwlc_set_server_status_up;
|
||||
p->lbprm.set_server_status_down = fwlc_set_server_status_down;
|
||||
p->lbprm.update_server_eweight = fwlc_update_server_weight;
|
||||
p->lbprm.server_take_conn = fwlc_srv_reposition;
|
||||
p->lbprm.server_drop_conn = fwlc_srv_reposition;
|
||||
p->lbprm.server_requeue = fwlc_srv_reposition;
|
||||
p->lbprm.server_deinit = fwlc_server_deinit;
|
||||
p->lbprm.proxy_deinit = fwlc_proxy_deinit;
|
||||
|
||||
p->lbprm.wdiv = BE_WEIGHT_SCALE;
|
||||
for (srv = p->srv; srv; srv = srv->next) {
|
||||
srv->next_eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
|
||||
|
||||
@ -299,10 +299,6 @@ int fwrr_init_server_groups(struct proxy *p)
|
||||
struct eb_root init_head = EB_ROOT;
|
||||
int i, j;
|
||||
|
||||
p->lbprm.set_server_status_up = fwrr_set_server_status_up;
|
||||
p->lbprm.set_server_status_down = fwrr_set_server_status_down;
|
||||
p->lbprm.update_server_eweight = fwrr_update_server_weight;
|
||||
|
||||
p->lbprm.wdiv = BE_WEIGHT_SCALE;
|
||||
for (srv = p->srv; srv; srv = srv->next) {
|
||||
srv->next_eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
|
||||
|
||||
@ -143,10 +143,6 @@ int init_server_map(struct proxy *p)
|
||||
int pgcd;
|
||||
int act, bck;
|
||||
|
||||
p->lbprm.set_server_status_up = map_set_server_status_up;
|
||||
p->lbprm.set_server_status_down = map_set_server_status_down;
|
||||
p->lbprm.update_server_eweight = NULL;
|
||||
|
||||
if (!p->srv)
|
||||
return 0;
|
||||
|
||||
|
||||
@ -147,10 +147,6 @@ int init_server_ss(struct proxy *p)
|
||||
{
|
||||
struct server *srv;
|
||||
|
||||
p->lbprm.set_server_status_up = ss_set_server_status_up;
|
||||
p->lbprm.set_server_status_down = ss_set_server_status_down;
|
||||
p->lbprm.update_server_eweight = NULL;
|
||||
|
||||
if (!p->srv)
|
||||
return 0;
|
||||
|
||||
|
||||
31
src/proxy.c
31
src/proxy.c
@ -392,8 +392,8 @@ void deinit_proxy(struct proxy *p)
|
||||
list_for_each_entry(srvdf, &server_deinit_list, list)
|
||||
srvdf->fct(s);
|
||||
|
||||
if (p->lbprm.server_deinit)
|
||||
p->lbprm.server_deinit(s);
|
||||
if (p->lbprm.ops && p->lbprm.ops->server_deinit)
|
||||
p->lbprm.ops->server_deinit(s);
|
||||
|
||||
s = srv_drop(s);
|
||||
}/* end while(s) */
|
||||
@ -406,8 +406,8 @@ void deinit_proxy(struct proxy *p)
|
||||
srv_free(&p->defsrv);
|
||||
}
|
||||
|
||||
if (p->lbprm.proxy_deinit)
|
||||
p->lbprm.proxy_deinit(p);
|
||||
if (p->lbprm.ops && p->lbprm.ops->proxy_deinit)
|
||||
p->lbprm.ops->proxy_deinit(p);
|
||||
|
||||
list_for_each_entry_safe(l, l_next, &p->conf.listeners, by_fe) {
|
||||
guid_remove(&l->guid);
|
||||
@ -2615,46 +2615,45 @@ int proxy_finalize(struct proxy *px, int *err_code)
|
||||
case BE_LB_KIND_RR:
|
||||
if ((px->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) {
|
||||
px->lbprm.algo |= BE_LB_LKUP_MAP;
|
||||
init_server_map(px);
|
||||
px->lbprm.ops = &lb_map_ops;
|
||||
} else if ((px->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) {
|
||||
px->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
|
||||
if (chash_init_server_tree(px) < 0) {
|
||||
cfgerr++;
|
||||
}
|
||||
px->lbprm.ops = &lb_chash_ops;
|
||||
} else {
|
||||
px->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN;
|
||||
fwrr_init_server_groups(px);
|
||||
px->lbprm.ops = &lb_fwrr_ops;
|
||||
}
|
||||
break;
|
||||
|
||||
case BE_LB_KIND_CB:
|
||||
if ((px->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) {
|
||||
px->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN;
|
||||
fwlc_init_server_tree(px);
|
||||
px->lbprm.ops = &lb_fwlc_ops;
|
||||
} else {
|
||||
px->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN;
|
||||
fas_init_server_tree(px);
|
||||
px->lbprm.ops = &lb_fas_ops;
|
||||
}
|
||||
break;
|
||||
|
||||
case BE_LB_KIND_HI:
|
||||
if ((px->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) {
|
||||
px->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN;
|
||||
if (chash_init_server_tree(px) < 0) {
|
||||
cfgerr++;
|
||||
}
|
||||
px->lbprm.ops = &lb_chash_ops;
|
||||
} else {
|
||||
px->lbprm.algo |= BE_LB_LKUP_MAP;
|
||||
init_server_map(px);
|
||||
px->lbprm.ops = &lb_map_ops;
|
||||
}
|
||||
break;
|
||||
case BE_LB_KIND_SA:
|
||||
if ((px->lbprm.algo & BE_LB_PARM) == BE_LB_SA_SS) {
|
||||
px->lbprm.algo |= BE_LB_PROP_DYN;
|
||||
init_server_ss(px);
|
||||
px->lbprm.ops = &lb_ss_ops;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (px->lbprm.ops && px->lbprm.ops->proxy_init &&
|
||||
px->lbprm.ops->proxy_init(px) < 0)
|
||||
cfgerr++;
|
||||
HA_RWLOCK_INIT(&px->lbprm.lock);
|
||||
|
||||
if (px->options & PR_O_LOGASAP)
|
||||
|
||||
@ -508,8 +508,8 @@ int process_srv_queue(struct server *s)
|
||||
_HA_ATOMIC_SUB(&p->totpend, done);
|
||||
_HA_ATOMIC_ADD(&p->served, done);
|
||||
__ha_barrier_atomic_store();
|
||||
if (p->lbprm.server_take_conn)
|
||||
p->lbprm.server_take_conn(s);
|
||||
if (p->lbprm.ops && p->lbprm.ops->server_take_conn)
|
||||
p->lbprm.ops->server_take_conn(s);
|
||||
}
|
||||
if (s->served == 0 && p->served == 0 && !HA_ATOMIC_LOAD(&p->ready_srv)) {
|
||||
int i;
|
||||
|
||||
31
src/server.c
31
src/server.c
@ -191,9 +191,9 @@ static void _srv_set_inetaddr_port(struct server *srv,
|
||||
else
|
||||
srv->flags &= ~SRV_F_MAPPORTS;
|
||||
|
||||
if (srv->proxy->lbprm.update_server_eweight) {
|
||||
if (srv->proxy->lbprm.ops && srv->proxy->lbprm.ops->update_server_eweight) {
|
||||
/* some balancers (chash in particular) may use the addr in their routing decisions */
|
||||
srv->proxy->lbprm.update_server_eweight(srv);
|
||||
srv->proxy->lbprm.ops->update_server_eweight(srv);
|
||||
}
|
||||
|
||||
if (srv->log_target && srv->log_target->type == LOG_TARGET_DGRAM) {
|
||||
@ -2530,8 +2530,8 @@ struct task *server_requeue(struct task *t, void *context, unsigned int state)
|
||||
/* let's call the LB's requeue function. If it fails, it will itself
|
||||
* wake us up.
|
||||
*/
|
||||
if (srv->proxy->lbprm.server_requeue)
|
||||
srv->proxy->lbprm.server_requeue(srv);
|
||||
if (srv->proxy->lbprm.ops && srv->proxy->lbprm.ops->server_requeue)
|
||||
srv->proxy->lbprm.ops->server_requeue(srv);
|
||||
return t;
|
||||
}
|
||||
|
||||
@ -5960,7 +5960,7 @@ static int srv_alloc_lb(struct server *sv, struct proxy *be)
|
||||
sv->lb_nodes_tot = sv->uweight * BE_WEIGHT_SCALE;
|
||||
sv->lb_nodes_now = 0;
|
||||
|
||||
if (be->lbprm.server_init && be->lbprm.server_init(sv) < 0)
|
||||
if (be->lbprm.ops && be->lbprm.ops->server_init && be->lbprm.ops->server_init(sv) < 0)
|
||||
return 0; // typically out of memory
|
||||
|
||||
return 1;
|
||||
@ -6476,7 +6476,7 @@ int srv_check_for_deletion(const char *bename, const char *svname, struct proxy
|
||||
|
||||
/* Only servers in maintenance can be deleted. This ensures that the
|
||||
* server is not present anymore in the lb structures (through
|
||||
* lbprm.set_server_status_down).
|
||||
* lbprm.ops->set_server_status_down).
|
||||
*/
|
||||
if (!(srv->cur_admin & SRV_ADMF_MAINT)) {
|
||||
msg = "Only servers in maintenance mode can be deleted.";
|
||||
@ -6562,8 +6562,8 @@ static int cli_parse_delete_server(char **args, char *payload, struct appctx *ap
|
||||
if (srv->agent.state & CHK_ST_CONFIGURED)
|
||||
check_purge(&srv->agent);
|
||||
|
||||
if (srv->proxy->lbprm.server_deinit)
|
||||
srv->proxy->lbprm.server_deinit(srv);
|
||||
if (srv->proxy->lbprm.ops && srv->proxy->lbprm.ops->server_deinit)
|
||||
srv->proxy->lbprm.ops->server_deinit(srv);
|
||||
|
||||
while (!MT_LIST_ISEMPTY(&srv->watcher_list)) {
|
||||
srv_watch = MT_LIST_NEXT(&srv->watcher_list, struct watcher *, el);
|
||||
@ -6731,15 +6731,18 @@ static void srv_lb_propagate(struct server *s)
|
||||
{
|
||||
struct proxy *px = s->proxy;
|
||||
|
||||
if (px->lbprm.update_server_eweight)
|
||||
px->lbprm.update_server_eweight(s);
|
||||
if (!px->lbprm.ops)
|
||||
return;
|
||||
|
||||
if (px->lbprm.ops->update_server_eweight)
|
||||
px->lbprm.ops->update_server_eweight(s);
|
||||
else if (srv_willbe_usable(s)) {
|
||||
if (px->lbprm.set_server_status_up)
|
||||
px->lbprm.set_server_status_up(s);
|
||||
if (px->lbprm.ops->set_server_status_up)
|
||||
px->lbprm.ops->set_server_status_up(s);
|
||||
}
|
||||
else {
|
||||
if (px->lbprm.set_server_status_down)
|
||||
px->lbprm.set_server_status_down(s);
|
||||
if (px->lbprm.ops->set_server_status_down)
|
||||
px->lbprm.ops->set_server_status_down(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2931,15 +2931,15 @@ void sess_change_server(struct stream *strm, struct server *newsrv)
|
||||
stream_del_srv_conn(strm);
|
||||
_HA_ATOMIC_DEC(&oldsrv->served);
|
||||
__ha_barrier_atomic_store();
|
||||
if (oldsrv->proxy->lbprm.server_drop_conn)
|
||||
oldsrv->proxy->lbprm.server_drop_conn(oldsrv);
|
||||
if (oldsrv->proxy->lbprm.ops && oldsrv->proxy->lbprm.ops->server_drop_conn)
|
||||
oldsrv->proxy->lbprm.ops->server_drop_conn(oldsrv);
|
||||
}
|
||||
|
||||
if (newsrv) {
|
||||
_HA_ATOMIC_INC(&newsrv->proxy->served);
|
||||
__ha_barrier_atomic_store();
|
||||
if (newsrv->proxy->lbprm.server_take_conn)
|
||||
newsrv->proxy->lbprm.server_take_conn(newsrv);
|
||||
if (newsrv->proxy->lbprm.ops && newsrv->proxy->lbprm.ops->server_take_conn)
|
||||
newsrv->proxy->lbprm.ops->server_take_conn(newsrv);
|
||||
stream_add_srv_conn(strm, newsrv);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user