mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-21 22:28:41 -04:00
MINOR: server: add helper function to detach server from proxy list
Remove some code duplication by introducing a basic helper function to detach a server from its parent proxy. It is supported to call the function even if the server is not yet listed in the proxy list. If the server is not yet listed in the proxy, the function will do nothing. In delete_server(), we previously performed some BUG_ON() to ensure that the detach always succeeded given that we were certain that the server was in the proxy list because it was retrieved through get_backend_server(). However this test is superfluous, we can safely assume that the operation will always succeed if get_backend_server() returned != NULL (we're under full thread isolation), and if it's not the case, then we have a bigger API issue anyway..
This commit is contained in:
parent
e128fc7ce1
commit
1822e8998b
1 changed files with 22 additions and 28 deletions
50
src/server.c
50
src/server.c
|
|
@ -2573,6 +2573,26 @@ struct server *srv_drop(struct server *srv)
|
|||
return next;
|
||||
}
|
||||
|
||||
/* Detach server from proxy list. It is supported to call this
|
||||
* even if the server is not yet in the list
|
||||
*/
|
||||
static void _srv_detach(struct server *srv)
|
||||
{
|
||||
struct proxy *be = srv->proxy;
|
||||
|
||||
if (be->srv == srv) {
|
||||
be->srv = srv->next;
|
||||
}
|
||||
else {
|
||||
struct server *prev;
|
||||
|
||||
for (prev = be->srv; prev && prev->next != srv; prev = prev->next)
|
||||
;
|
||||
if (prev)
|
||||
prev->next = srv->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove a server <srv> from a tracking list if <srv> is tracking another
|
||||
* server. No special care is taken if <srv> is tracked itself by another one :
|
||||
* this situation should be avoided by the caller.
|
||||
|
|
@ -5181,17 +5201,7 @@ out:
|
|||
free_check(&srv->agent);
|
||||
|
||||
/* remove the server from the proxy linked list */
|
||||
if (be->srv == srv) {
|
||||
be->srv = srv->next;
|
||||
}
|
||||
else {
|
||||
struct server *prev;
|
||||
for (prev = be->srv; prev && prev->next != srv; prev = prev->next)
|
||||
;
|
||||
if (prev)
|
||||
prev->next = srv->next;
|
||||
}
|
||||
|
||||
_srv_detach(srv);
|
||||
}
|
||||
|
||||
thread_release();
|
||||
|
|
@ -5288,23 +5298,7 @@ static int cli_parse_delete_server(char **args, char *payload, struct appctx *ap
|
|||
* The proxy servers list is currently not protected by a lock, so this
|
||||
* requires thread_isolate/release.
|
||||
*/
|
||||
|
||||
/* be->srv cannot be empty since we have already found the server with
|
||||
* get_backend_server */
|
||||
BUG_ON(!be->srv);
|
||||
if (be->srv == srv) {
|
||||
be->srv = srv->next;
|
||||
}
|
||||
else {
|
||||
struct server *next;
|
||||
for (next = be->srv; srv != next->next; next = next->next) {
|
||||
/* srv cannot be not found since we have already found
|
||||
* it with get_backend_server */
|
||||
BUG_ON(!next);
|
||||
}
|
||||
|
||||
next->next = srv->next;
|
||||
}
|
||||
_srv_detach(srv);
|
||||
|
||||
/* Some deleted servers could still point to us using their 'next',
|
||||
* update them as needed
|
||||
|
|
|
|||
Loading…
Reference in a new issue