Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Fast Weighted Least Connection load balancing algorithm. |
| 3 | * |
| 4 | * Copyright 2000-2009 Willy Tarreau <w@1wt.eu> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 13 | #include <haproxy/api.h> |
Willy Tarreau | 8d2b777 | 2020-05-27 10:58:19 +0200 | [diff] [blame] | 14 | #include <import/eb32tree.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 15 | |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 16 | #include <types/server.h> |
| 17 | |
| 18 | #include <proto/backend.h> |
| 19 | #include <proto/queue.h> |
| 20 | |
| 21 | |
| 22 | /* Remove a server from a tree. It must have previously been dequeued. This |
| 23 | * function is meant to be called when a server is going down or has its |
| 24 | * weight disabled. |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 25 | * |
| 26 | * The server's lock and the lbprm's lock must be held. |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 27 | */ |
| 28 | static inline void fwlc_remove_from_tree(struct server *s) |
| 29 | { |
| 30 | s->lb_tree = NULL; |
| 31 | } |
| 32 | |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 33 | /* simply removes a server from a tree. |
| 34 | * |
| 35 | * The server's lock and the lbprm's lock must be held. |
| 36 | */ |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 37 | static inline void fwlc_dequeue_srv(struct server *s) |
| 38 | { |
| 39 | eb32_delete(&s->lb_node); |
| 40 | } |
| 41 | |
| 42 | /* Queue a server in its associated tree, assuming the weight is >0. |
Willy Tarreau | 1eb6c55 | 2018-12-14 08:33:28 +0100 | [diff] [blame] | 43 | * Servers are sorted by (#conns+1)/weight. To ensure maximum accuracy, |
| 44 | * we use (#conns+1)*SRV_EWGHT_MAX/eweight as the sorting key. The reason |
| 45 | * for using #conns+1 is to sort by weights in case the server is picked |
| 46 | * and not before it is picked. This provides a better load accuracy for |
| 47 | * low connection counts when weights differ and makes sure the round-robin |
Willy Tarreau | ed5ac9c | 2019-09-06 17:04:04 +0200 | [diff] [blame] | 48 | * applies between servers of highest weight first. However servers with no |
| 49 | * connection are always picked first so that under low loads, it's not |
| 50 | * always the single server with the highest weight that gets picked. |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 51 | * |
| 52 | * The server's lock and the lbprm's lock must be held. |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 53 | */ |
| 54 | static inline void fwlc_queue_srv(struct server *s) |
| 55 | { |
Willy Tarreau | ed5ac9c | 2019-09-06 17:04:04 +0200 | [diff] [blame] | 56 | s->lb_node.key = s->served ? (s->served + 1) * SRV_EWGHT_MAX / s->next_eweight : 0; |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 57 | eb32_insert(s->lb_tree, &s->lb_node); |
| 58 | } |
| 59 | |
| 60 | /* Re-position the server in the FWLC tree after it has been assigned one |
| 61 | * connection or after it has released one. Note that it is possible that |
| 62 | * the server has been moved out of the tree due to failed health-checks. |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 63 | * |
| 64 | * The server's lock must be held. The lbprm's lock will be used. |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 65 | */ |
| 66 | static void fwlc_srv_reposition(struct server *s) |
| 67 | { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 68 | HA_SPIN_LOCK(LBPRM_LOCK, &s->proxy->lbprm.lock); |
Christopher Faulet | 1ae2a88 | 2019-06-19 10:50:38 +0200 | [diff] [blame] | 69 | if (s->lb_tree) { |
| 70 | fwlc_dequeue_srv(s); |
| 71 | fwlc_queue_srv(s); |
| 72 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 73 | HA_SPIN_UNLOCK(LBPRM_LOCK, &s->proxy->lbprm.lock); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /* This function updates the server trees according to server <srv>'s new |
| 77 | * state. It should be called when server <srv>'s status changes to down. |
| 78 | * It is not important whether the server was already down or not. It is not |
| 79 | * important either that the new state is completely down (the caller may not |
| 80 | * know all the variables of a server's state). |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 81 | * |
| 82 | * The server's lock must be held. The lbprm's lock will be used. |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 83 | */ |
| 84 | static void fwlc_set_server_status_down(struct server *srv) |
| 85 | { |
| 86 | struct proxy *p = srv->proxy; |
| 87 | |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 88 | if (!srv_lb_status_changed(srv)) |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 89 | return; |
| 90 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 91 | if (srv_willbe_usable(srv)) |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 92 | goto out_update_state; |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 93 | HA_SPIN_LOCK(LBPRM_LOCK, &p->lbprm.lock); |
| 94 | |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 95 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 96 | if (!srv_currently_usable(srv)) |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 97 | /* server was already down */ |
| 98 | goto out_update_backend; |
| 99 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 100 | if (srv->flags & SRV_F_BACKUP) { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 101 | p->lbprm.tot_wbck -= srv->cur_eweight; |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 102 | p->srv_bck--; |
| 103 | |
| 104 | if (srv == p->lbprm.fbck) { |
| 105 | /* we lost the first backup server in a single-backup |
| 106 | * configuration, we must search another one. |
| 107 | */ |
| 108 | struct server *srv2 = p->lbprm.fbck; |
| 109 | do { |
| 110 | srv2 = srv2->next; |
| 111 | } while (srv2 && |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 112 | !((srv2->flags & SRV_F_BACKUP) && |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 113 | srv_willbe_usable(srv2))); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 114 | p->lbprm.fbck = srv2; |
| 115 | } |
| 116 | } else { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 117 | p->lbprm.tot_wact -= srv->cur_eweight; |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 118 | p->srv_act--; |
| 119 | } |
| 120 | |
| 121 | fwlc_dequeue_srv(srv); |
| 122 | fwlc_remove_from_tree(srv); |
| 123 | |
| 124 | out_update_backend: |
| 125 | /* check/update tot_used, tot_weight */ |
| 126 | update_backend_weight(p); |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 127 | HA_SPIN_UNLOCK(LBPRM_LOCK, &p->lbprm.lock); |
| 128 | |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 129 | out_update_state: |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 130 | srv_lb_commit_status(srv); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /* This function updates the server trees according to server <srv>'s new |
| 134 | * state. It should be called when server <srv>'s status changes to up. |
| 135 | * It is not important whether the server was already down or not. It is not |
| 136 | * important either that the new state is completely UP (the caller may not |
| 137 | * know all the variables of a server's state). This function will not change |
| 138 | * the weight of a server which was already up. |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 139 | * |
| 140 | * The server's lock must be held. The lbprm's lock will be used. |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 141 | */ |
| 142 | static void fwlc_set_server_status_up(struct server *srv) |
| 143 | { |
| 144 | struct proxy *p = srv->proxy; |
| 145 | |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 146 | if (!srv_lb_status_changed(srv)) |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 147 | return; |
| 148 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 149 | if (!srv_willbe_usable(srv)) |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 150 | goto out_update_state; |
| 151 | |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 152 | HA_SPIN_LOCK(LBPRM_LOCK, &p->lbprm.lock); |
| 153 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 154 | if (srv_currently_usable(srv)) |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 155 | /* server was already up */ |
| 156 | goto out_update_backend; |
| 157 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 158 | if (srv->flags & SRV_F_BACKUP) { |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 159 | srv->lb_tree = &p->lbprm.fwlc.bck; |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 160 | p->lbprm.tot_wbck += srv->next_eweight; |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 161 | p->srv_bck++; |
| 162 | |
| 163 | if (!(p->options & PR_O_USE_ALL_BK)) { |
| 164 | if (!p->lbprm.fbck) { |
| 165 | /* there was no backup server anymore */ |
| 166 | p->lbprm.fbck = srv; |
| 167 | } else { |
| 168 | /* we may have restored a backup server prior to fbck, |
| 169 | * in which case it should replace it. |
| 170 | */ |
| 171 | struct server *srv2 = srv; |
| 172 | do { |
| 173 | srv2 = srv2->next; |
| 174 | } while (srv2 && (srv2 != p->lbprm.fbck)); |
| 175 | if (srv2) |
| 176 | p->lbprm.fbck = srv; |
| 177 | } |
| 178 | } |
| 179 | } else { |
| 180 | srv->lb_tree = &p->lbprm.fwlc.act; |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 181 | p->lbprm.tot_wact += srv->next_eweight; |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 182 | p->srv_act++; |
| 183 | } |
| 184 | |
| 185 | /* note that eweight cannot be 0 here */ |
| 186 | fwlc_queue_srv(srv); |
| 187 | |
| 188 | out_update_backend: |
| 189 | /* check/update tot_used, tot_weight */ |
| 190 | update_backend_weight(p); |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 191 | HA_SPIN_UNLOCK(LBPRM_LOCK, &p->lbprm.lock); |
| 192 | |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 193 | out_update_state: |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 194 | srv_lb_commit_status(srv); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* This function must be called after an update to server <srv>'s effective |
| 198 | * weight. It may be called after a state change too. |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 199 | * |
| 200 | * The server's lock must be held. The lbprm's lock will be used. |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 201 | */ |
| 202 | static void fwlc_update_server_weight(struct server *srv) |
| 203 | { |
| 204 | int old_state, new_state; |
| 205 | struct proxy *p = srv->proxy; |
| 206 | |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 207 | if (!srv_lb_status_changed(srv)) |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 208 | return; |
| 209 | |
| 210 | /* If changing the server's weight changes its state, we simply apply |
| 211 | * the procedures we already have for status change. If the state |
| 212 | * remains down, the server is not in any tree, so it's as easy as |
| 213 | * updating its values. If the state remains up with different weights, |
| 214 | * there are some computations to perform to find a new place and |
| 215 | * possibly a new tree for this server. |
| 216 | */ |
| 217 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 218 | old_state = srv_currently_usable(srv); |
| 219 | new_state = srv_willbe_usable(srv); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 220 | |
| 221 | if (!old_state && !new_state) { |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 222 | srv_lb_commit_status(srv); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 223 | return; |
| 224 | } |
| 225 | else if (!old_state && new_state) { |
| 226 | fwlc_set_server_status_up(srv); |
| 227 | return; |
| 228 | } |
| 229 | else if (old_state && !new_state) { |
| 230 | fwlc_set_server_status_down(srv); |
| 231 | return; |
| 232 | } |
| 233 | |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 234 | HA_SPIN_LOCK(LBPRM_LOCK, &p->lbprm.lock); |
| 235 | |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 236 | if (srv->lb_tree) |
| 237 | fwlc_dequeue_srv(srv); |
| 238 | |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 239 | if (srv->flags & SRV_F_BACKUP) { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 240 | p->lbprm.tot_wbck += srv->next_eweight - srv->cur_eweight; |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 241 | srv->lb_tree = &p->lbprm.fwlc.bck; |
| 242 | } else { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 243 | p->lbprm.tot_wact += srv->next_eweight - srv->cur_eweight; |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 244 | srv->lb_tree = &p->lbprm.fwlc.act; |
| 245 | } |
| 246 | |
| 247 | fwlc_queue_srv(srv); |
| 248 | |
| 249 | update_backend_weight(p); |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 250 | HA_SPIN_UNLOCK(LBPRM_LOCK, &p->lbprm.lock); |
| 251 | |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 252 | srv_lb_commit_status(srv); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /* This function is responsible for building the trees in case of fast |
| 256 | * weighted least-conns. It also sets p->lbprm.wdiv to the eweight to |
| 257 | * uweight ratio. Both active and backup groups are initialized. |
| 258 | */ |
| 259 | void fwlc_init_server_tree(struct proxy *p) |
| 260 | { |
| 261 | struct server *srv; |
| 262 | struct eb_root init_head = EB_ROOT; |
| 263 | |
| 264 | p->lbprm.set_server_status_up = fwlc_set_server_status_up; |
| 265 | p->lbprm.set_server_status_down = fwlc_set_server_status_down; |
| 266 | p->lbprm.update_server_eweight = fwlc_update_server_weight; |
| 267 | p->lbprm.server_take_conn = fwlc_srv_reposition; |
| 268 | p->lbprm.server_drop_conn = fwlc_srv_reposition; |
| 269 | |
| 270 | p->lbprm.wdiv = BE_WEIGHT_SCALE; |
| 271 | for (srv = p->srv; srv; srv = srv->next) { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 272 | srv->next_eweight = (srv->uweight * p->lbprm.wdiv + p->lbprm.wmult - 1) / p->lbprm.wmult; |
Willy Tarreau | c5150da | 2014-05-13 19:27:31 +0200 | [diff] [blame] | 273 | srv_lb_commit_status(srv); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | recount_servers(p); |
| 277 | update_backend_weight(p); |
| 278 | |
| 279 | p->lbprm.fwlc.act = init_head; |
| 280 | p->lbprm.fwlc.bck = init_head; |
| 281 | |
| 282 | /* queue active and backup servers in two distinct groups */ |
| 283 | for (srv = p->srv; srv; srv = srv->next) { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 284 | if (!srv_currently_usable(srv)) |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 285 | continue; |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 286 | srv->lb_tree = (srv->flags & SRV_F_BACKUP) ? &p->lbprm.fwlc.bck : &p->lbprm.fwlc.act; |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 287 | fwlc_queue_srv(srv); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | /* Return next server from the FWLC tree in backend <p>. If the tree is empty, |
| 292 | * return NULL. Saturated servers are skipped. |
Willy Tarreau | 1b87748 | 2018-08-21 19:44:53 +0200 | [diff] [blame] | 293 | * |
| 294 | * The server's lock must be held. The lbprm's lock will be used. |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 295 | */ |
| 296 | struct server *fwlc_get_next_server(struct proxy *p, struct server *srvtoavoid) |
| 297 | { |
| 298 | struct server *srv, *avoided; |
| 299 | struct eb32_node *node; |
| 300 | |
| 301 | srv = avoided = NULL; |
| 302 | |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 303 | HA_SPIN_LOCK(LBPRM_LOCK, &p->lbprm.lock); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 304 | if (p->srv_act) |
| 305 | node = eb32_first(&p->lbprm.fwlc.act); |
Christopher Faulet | 5b51755 | 2017-06-09 14:17:53 +0200 | [diff] [blame] | 306 | else if (p->lbprm.fbck) { |
| 307 | srv = p->lbprm.fbck; |
| 308 | goto out; |
| 309 | } |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 310 | else if (p->srv_bck) |
| 311 | node = eb32_first(&p->lbprm.fwlc.bck); |
Christopher Faulet | 5b51755 | 2017-06-09 14:17:53 +0200 | [diff] [blame] | 312 | else { |
| 313 | srv = NULL; |
| 314 | goto out; |
| 315 | } |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 316 | |
| 317 | while (node) { |
| 318 | /* OK, we have a server. However, it may be saturated, in which |
| 319 | * case we don't want to reconsider it for now, so we'll simply |
| 320 | * skip it. Same if it's the server we try to avoid, in which |
| 321 | * case we simply remember it for later use if needed. |
| 322 | */ |
| 323 | struct server *s; |
| 324 | |
| 325 | s = eb32_entry(node, struct server, lb_node); |
| 326 | if (!s->maxconn || (!s->nbpend && s->served < srv_dynamic_maxconn(s))) { |
| 327 | if (s != srvtoavoid) { |
| 328 | srv = s; |
| 329 | break; |
| 330 | } |
| 331 | avoided = s; |
| 332 | } |
| 333 | node = eb32_next(node); |
| 334 | } |
| 335 | |
| 336 | if (!srv) |
| 337 | srv = avoided; |
Christopher Faulet | 5b51755 | 2017-06-09 14:17:53 +0200 | [diff] [blame] | 338 | out: |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 339 | HA_SPIN_UNLOCK(LBPRM_LOCK, &p->lbprm.lock); |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 340 | return srv; |
| 341 | } |
| 342 | |
| 343 | |
| 344 | /* |
| 345 | * Local variables: |
| 346 | * c-indent-level: 8 |
| 347 | * c-basic-offset: 8 |
| 348 | * End: |
| 349 | */ |