return 1;
}
+/* This function commits the current server state and weight onto the previous
+ * ones in order to detect future changes.
+ */
+static inline void srv_lb_commit_status(struct server *srv)
+{
+ srv->prev_state = srv->state;
+ srv->prev_eweight = srv->eweight;
+}
+
+/* This function returns true when a server has experienced a change since last
+ * commit on its state or weight, otherwise zero.
+ */
+static inline int srv_lb_status_changed(const struct server *srv)
+{
+ return (srv->state != srv->prev_state ||
+ srv->eweight != srv->prev_eweight);
+}
+
#endif /* _PROTO_BACKEND_H */
/*
{
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (srv_is_usable(srv->state, srv->eweight))
/* check/update tot_used, tot_weight */
update_backend_weight(p);
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function updates the server trees according to server <srv>'s new
{
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (!srv_is_usable(srv->state, srv->eweight))
/* check/update tot_used, tot_weight */
update_backend_weight(p);
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function must be called after an update to server <srv>'s effective
int old_state, new_state;
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
/* If changing the server's weight changes its state, we simply apply
new_state = srv_is_usable(srv->state, srv->eweight);
if (!old_state && !new_state) {
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
return;
}
else if (!old_state && new_state) {
p->lbprm.tot_wact += srv->eweight - srv->prev_eweight;
update_backend_weight(p);
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/*
p->lbprm.wdiv = BE_WEIGHT_SCALE;
for (srv = p->srv; srv; srv = srv->next) {
srv->eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
- srv->prev_eweight = srv->eweight;
- srv->prev_state = srv->state;
+ srv_lb_commit_status(srv);
}
recount_servers(p);
{
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (srv_is_usable(srv->state, srv->eweight))
/* check/update tot_used, tot_weight */
update_backend_weight(p);
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function updates the server trees according to server <srv>'s new
{
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (!srv_is_usable(srv->state, srv->eweight))
/* check/update tot_used, tot_weight */
update_backend_weight(p);
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function must be called after an update to server <srv>'s effective
int old_state, new_state;
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
/* If changing the server's weight changes its state, we simply apply
new_state = srv_is_usable(srv->state, srv->eweight);
if (!old_state && !new_state) {
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
return;
}
else if (!old_state && new_state) {
fas_queue_srv(srv);
update_backend_weight(p);
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function is responsible for building the trees in case of fast
p->lbprm.wdiv = BE_WEIGHT_SCALE;
for (srv = p->srv; srv; srv = srv->next) {
srv->eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
- srv->prev_eweight = srv->eweight;
- srv->prev_state = srv->state;
+ srv_lb_commit_status(srv);
}
recount_servers(p);
{
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (srv_is_usable(srv->state, srv->eweight))
/* check/update tot_used, tot_weight */
update_backend_weight(p);
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function updates the server trees according to server <srv>'s new
{
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (!srv_is_usable(srv->state, srv->eweight))
/* check/update tot_used, tot_weight */
update_backend_weight(p);
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function must be called after an update to server <srv>'s effective
int old_state, new_state;
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
/* If changing the server's weight changes its state, we simply apply
new_state = srv_is_usable(srv->state, srv->eweight);
if (!old_state && !new_state) {
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
return;
}
else if (!old_state && new_state) {
fwlc_queue_srv(srv);
update_backend_weight(p);
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function is responsible for building the trees in case of fast
p->lbprm.wdiv = BE_WEIGHT_SCALE;
for (srv = p->srv; srv; srv = srv->next) {
srv->eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
- srv->prev_eweight = srv->eweight;
- srv->prev_state = srv->state;
+ srv_lb_commit_status(srv);
}
recount_servers(p);
struct proxy *p = srv->proxy;
struct fwrr_group *grp;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (srv_is_usable(srv->state, srv->eweight))
/* check/update tot_used, tot_weight */
update_backend_weight(p);
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function updates the server trees according to server <srv>'s new
struct proxy *p = srv->proxy;
struct fwrr_group *grp;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (!srv_is_usable(srv->state, srv->eweight))
/* check/update tot_used, tot_weight */
update_backend_weight(p);
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function must be called after an update to server <srv>'s effective
struct proxy *p = srv->proxy;
struct fwrr_group *grp;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
/* If changing the server's weight changes its state, we simply apply
new_state = srv_is_usable(srv->state, srv->eweight);
if (!old_state && !new_state) {
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
return;
}
else if (!old_state && new_state) {
}
update_backend_weight(p);
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* Remove a server from a tree. It must have previously been dequeued. This
p->lbprm.wdiv = BE_WEIGHT_SCALE;
for (srv = p->srv; srv; srv = srv->next) {
srv->eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
- srv->prev_eweight = srv->eweight;
- srv->prev_state = srv->state;
+ srv_lb_commit_status(srv);
}
recount_servers(p);
{
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (srv_is_usable(srv->state, srv->eweight))
update_backend_weight(p);
p->lbprm.map.state |= LB_MAP_RECALC;
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function updates the map according to server <srv>'s new state */
{
struct proxy *p = srv->proxy;
- if (srv->state == srv->prev_state &&
- srv->eweight == srv->prev_eweight)
+ if (!srv_lb_status_changed(srv))
return;
if (!srv_is_usable(srv->state, srv->eweight))
update_backend_weight(p);
p->lbprm.map.state |= LB_MAP_RECALC;
out_update_state:
- srv->prev_state = srv->state;
- srv->prev_eweight = srv->eweight;
+ srv_lb_commit_status(srv);
}
/* This function recomputes the server map for proxy px. It relies on
act = bck = 0;
for (srv = p->srv; srv; srv = srv->next) {
srv->eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult;
- srv->prev_eweight = srv->eweight;
- srv->prev_state = srv->state;
+ srv_lb_commit_status(srv);
+
if (srv->state & SRV_BACKUP)
bck += srv->eweight;
else
else
curproxy->srv_act++;
- newsrv->prev_state = newsrv->state;
+ srv_lb_commit_status(newsrv);
}
}
return 0;