CLEANUP: server: simplify server_find_by_id()

At a few places we're seeing some open-coding of the same function, likely
because it looks overkill for what it's supposed to do, due to extraneous
tests that are not needed (e.g. check of the backend's PR_CAP_BE etc).
Let's just remove all these superfluous tests and inline it so that it
feels more suitable for use everywhere it's needed.
This commit is contained in:
Willy Tarreau 2025-07-09 16:35:27 +02:00
parent c8f0b69587
commit fda04994d9
2 changed files with 12 additions and 26 deletions

View File

@ -59,7 +59,6 @@ const char *srv_update_addr_port(struct server *s, const char *addr, const char
const char *server_inetaddr_updater_by_to_str(enum server_inetaddr_updater_by by);
const char *srv_update_check_addr_port(struct server *s, const char *addr, const char *port);
const char *srv_update_agent_addr_port(struct server *s, const char *addr, const char *port);
struct server *server_find_by_id(struct proxy *bk, int id);
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(struct proxy *bk, const char *name);
@ -344,6 +343,18 @@ static inline void srv_detach(struct server *srv)
}
}
/* Returns a pointer to the first server matching id <id> in backend <bk>.
* NULL is returned if no match is found.
*/
static inline struct server *server_find_by_id(struct proxy *bk, int id)
{
struct eb32_node *eb32;
eb32 = eb32_lookup(&bk->conf.used_server_id, id);
return eb32 ? container_of(eb32, struct server, conf.id) : NULL;
}
static inline int srv_is_quic(const struct server *srv)
{
#ifdef USE_QUIC

View File

@ -3958,31 +3958,6 @@ int parse_server(const char *file, int linenum, char **args,
return err_code;
}
/* Returns a pointer to the first server matching either id <id>.
* NULL is returned if no match is found.
* the lookup is performed in the backend <bk>
*/
struct server *server_find_by_id(struct proxy *bk, int id)
{
struct eb32_node *eb32;
struct server *curserver;
if (!bk || (id ==0))
return NULL;
/* <bk> has no backend capabilities, so it can't have a server */
if (!(bk->cap & PR_CAP_BE))
return NULL;
curserver = NULL;
eb32 = eb32_lookup(&bk->conf.used_server_id, id);
if (eb32)
curserver = container_of(eb32, struct server, conf.id);
return curserver;
}
/*
* This function finds a server with matching "<puid> x <rid>" within
* selected backend <bk>.