mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 07:07:04 +02:00
CLEANUP: server: add server_find_by_addr()
Server lookup by address requires locking and manipulation of the tree from user code. Let's provide server_find_by_addr() which does that for us.
This commit is contained in:
parent
fda04994d9
commit
616c10f608
@ -61,6 +61,7 @@ const char *srv_update_check_addr_port(struct server *s, const char *addr, const
|
||||
const char *srv_update_agent_addr_port(struct server *s, const char *addr, const char *port);
|
||||
struct server *server_find_by_id_unique(struct proxy *bk, int id, uint32_t rid);
|
||||
struct server *server_find_by_name(struct proxy *px, const char *name);
|
||||
struct server *server_find_by_addr(struct proxy *px, const char *addr);
|
||||
struct server *server_find(struct proxy *bk, const char *name);
|
||||
struct server *server_find_unique(struct proxy *bk, const char *name, uint32_t rid);
|
||||
struct server *server_find_best_match(struct proxy *bk, char *name, int id, int *diff);
|
||||
|
17
src/server.c
17
src/server.c
@ -3994,6 +3994,23 @@ struct server *server_find_by_name(struct proxy *px, const char *name)
|
||||
return cursrv;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function returns the server with a matching address within selected
|
||||
* proxy, or NULL if not found. The proxy lock is taken for reads during this
|
||||
* operation since we don't want the address to change under us.
|
||||
*/
|
||||
struct server *server_find_by_addr(struct proxy *px, const char *addr)
|
||||
{
|
||||
struct ebpt_node *node;
|
||||
struct server *cursrv;
|
||||
|
||||
HA_RWLOCK_RDLOCK(PROXY_LOCK, &px->lock);
|
||||
node = ebis_lookup(&px->used_server_addr, addr);
|
||||
cursrv = node ? container_of(node, struct server, addr_node) : NULL;
|
||||
HA_RWLOCK_RDUNLOCK(PROXY_LOCK, &px->lock);
|
||||
return cursrv;
|
||||
}
|
||||
|
||||
/* Returns a pointer to the first server matching either name <name>, or id
|
||||
* if <name> starts with a '#'. NULL is returned if no match is found.
|
||||
* the lookup is performed in the backend <bk>
|
||||
|
Loading…
Reference in New Issue
Block a user