__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 */
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);
#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;
#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;
#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;
#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);
#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;
* 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.
}
/* 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;
}
/* 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);
}
* 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;
* 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;
* 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;
* 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;
#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
*
* 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;
}
}
+/* 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;
#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.
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;