]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] backend: export some functions to recount servers
authorWilly Tarreau <w@1wt.eu>
Thu, 1 Oct 2009 07:17:05 +0000 (09:17 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 1 Oct 2009 07:17:05 +0000 (09:17 +0200)
Those functions will be used by new LB algorithms.

include/proto/backend.h
src/backend.c

index 4d37c7175bba56084cfbc6be1e2751bee4e54c62..69386b8382d49a11124d39f0241c8ff118315f89 100644 (file)
@@ -42,6 +42,22 @@ int be_downtime(struct proxy *px);
 void init_server_map(struct proxy *p);
 void fwrr_init_server_groups(struct proxy *p);
 void fwlc_init_server_tree(struct proxy *p);
+void recount_servers(struct proxy *px);
+void update_backend_weight(struct proxy *px);
+
+/* This function returns non-zero if a server with the given weight and state
+ * is usable for LB, otherwise zero.
+ */
+static inline int srv_is_usable(int state, int weight)
+{
+       if (!weight)
+               return 0;
+       if (state & SRV_GOINGDOWN)
+               return 0;
+       if (!(state & SRV_RUNNING))
+               return 0;
+       return 1;
+}
 
 /*
  * This function tries to find a running server with free connection slots for
@@ -90,26 +106,6 @@ static inline struct server *get_server_rr_with_conns(struct proxy *px, struct s
 }
 
 
-/*
- * This function tries to find a running server for the proxy <px> following
- * the round-robin method.
- * If any server is found, it will be returned and px->lbprm.map.rr_idx will be updated
- * to point to the next server. If no valid server is found, NULL is returned.
- */
-static inline struct server *get_server_rr(struct proxy *px)
-{
-       if (px->lbprm.tot_weight == 0)
-               return NULL;
-
-       if (px->lbprm.map.state & PR_MAP_RECALC)
-               recalc_server_map(px);
-
-       if (px->lbprm.map.rr_idx < 0 || px->lbprm.map.rr_idx >= px->lbprm.tot_weight)
-               px->lbprm.map.rr_idx = 0;
-       return px->lbprm.map.srv[px->lbprm.map.rr_idx++];
-}
-
-
 /*
  * This function tries to find a running server for the proxy <px> following
  * the source hash method. Depending on the number of active/backup servers,
index 05ce1ef21ba74d22836e3853b9b3ef9b31c312dd..648d79747850cc41d6773c481e438bfbab14804b 100644 (file)
@@ -44,20 +44,6 @@ static inline void fwrr_dequeue_srv(struct server *s);
 static void fwrr_get_srv(struct server *s);
 static void fwrr_queue_srv(struct server *s);
 
-/* This function returns non-zero if a server with the given weight and state
- * is usable for LB, otherwise zero.
- */
-static inline int srv_is_usable(int state, int weight)
-{
-       if (!weight)
-               return 0;
-       if (state & SRV_GOINGDOWN)
-               return 0;
-       if (!(state & SRV_RUNNING))
-               return 0;
-       return 1;
-}
-
 /*
  * This function recounts the number of usable active and backup servers for
  * proxy <p>. These numbers are returned into the p->srv_act and p->srv_bck.
@@ -65,7 +51,7 @@ static inline int srv_is_usable(int state, int weight)
  * it does not update tot_weight nor tot_used. Use update_backend_weight() for
  * this.
  */
-static void recount_servers(struct proxy *px)
+void recount_servers(struct proxy *px)
 {
        struct server *srv;
 
@@ -93,7 +79,7 @@ static void recount_servers(struct proxy *px)
  * after servers weights have been updated. It is designed to be used after
  * recount_servers() or equivalent.
  */
-static void update_backend_weight(struct proxy *px)
+void update_backend_weight(struct proxy *px)
 {
        if (px->srv_act) {
                px->lbprm.tot_weight = px->lbprm.tot_wact;