CLEANUP: server: rename server_find_by_name() to server_find()

This function doesn't just look at the name but also the ID when the
argument starts with a '#'. So the name is not correct and explains
why this function is not always used when the name only is needed,
and why the list-based findserver() is used instead. So let's just
call the function "server_find()", and rename its generation-id based
cousin "server_find_unique()".
This commit is contained in:
Willy Tarreau 2025-07-10 10:59:06 +02:00
parent 5e78ab33cd
commit 6ad9285796
7 changed files with 15 additions and 15 deletions

View File

@ -62,8 +62,8 @@ const char *srv_update_agent_addr_port(struct server *s, const char *addr, const
struct server *server_find_by_id(struct proxy *bk, int id); 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_id_unique(struct proxy *bk, int id, uint32_t rid);
struct server *findserver(struct proxy *px, const char *name); struct server *findserver(struct proxy *px, const char *name);
struct server *server_find_by_name(struct proxy *bk, const char *name); struct server *server_find(struct proxy *bk, const char *name);
struct server *server_find_by_name_unique(struct proxy *bk, const char *name, uint32_t rid); 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); struct server *server_find_best_match(struct proxy *bk, char *name, int id, int *diff);
void apply_server_state(void); void apply_server_state(void);
void srv_compute_all_admin_states(struct proxy *px); void srv_compute_all_admin_states(struct proxy *px);

View File

@ -3716,7 +3716,7 @@ sample_conv_srv_queue(const struct arg *args, struct sample *smp, void *private)
px = smp->px; px = smp->px;
} }
srv = server_find_by_name(px, smp->data.u.str.area); srv = server_find(px, smp->data.u.str.area);
if (!srv) if (!srv)
return 0; return 0;

View File

@ -1863,7 +1863,7 @@ int hlua_listable_servers_index(lua_State *L)
name = luaL_checkstring(L, 2); name = luaL_checkstring(L, 2);
/* Perform a server lookup in px list */ /* Perform a server lookup in px list */
srv = server_find_by_name(hlua_srv->px, name); srv = server_find(hlua_srv->px, name);
if (srv == NULL) { if (srv == NULL) {
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;

View File

@ -355,7 +355,7 @@ int rhttp_bind_listener(struct listener *listener, char *errmsg, int errlen)
snprintf(errmsg, errlen, "No such backend: '%s'.", name); snprintf(errmsg, errlen, "No such backend: '%s'.", name);
goto err; goto err;
} }
if (!(srv = server_find_by_name(be, ist0(sv_name)))) { if (!(srv = server_find(be, ist0(sv_name)))) {
snprintf(errmsg, errlen, "No such server: '%s/%s'.", ist0(be_name), ist0(sv_name)); snprintf(errmsg, errlen, "No such server: '%s/%s'.", ist0(be_name), ist0(sv_name));
goto err; goto err;
} }

View File

@ -4023,7 +4023,7 @@ struct server *findserver(struct proxy *px, const char *name)
* if <name> starts with a '#'. NULL is returned if no match is found. * if <name> starts with a '#'. NULL is returned if no match is found.
* the lookup is performed in the backend <bk> * the lookup is performed in the backend <bk>
*/ */
struct server *server_find_by_name(struct proxy *bk, const char *name) struct server *server_find(struct proxy *bk, const char *name)
{ {
struct server *curserver; struct server *curserver;
@ -4066,11 +4066,11 @@ struct server *server_find_by_name(struct proxy *bk, const char *name)
* a different server from the one we were expecting to match against at a given * a different server from the one we were expecting to match against at a given
* time. * time.
*/ */
struct server *server_find_by_name_unique(struct proxy *bk, const char *name, uint32_t rid) struct server *server_find_unique(struct proxy *bk, const char *name, uint32_t rid)
{ {
struct server *curserver; struct server *curserver;
curserver = server_find_by_name(bk, name); curserver = server_find(bk, name);
if (!curserver || curserver->rid != rid) if (!curserver || curserver->rid != rid)
return NULL; return NULL;
return curserver; return curserver;
@ -4090,7 +4090,7 @@ struct server *server_find_best_match(struct proxy *bk, char *name, int id, int
byname = byid = NULL; byname = byid = NULL;
if (name) { if (name) {
byname = server_find_by_name(bk, name); byname = server_find(bk, name);
if (byname && (!id || byname->puid == id)) if (byname && (!id || byname->puid == id))
return byname; return byname;
} }
@ -5334,7 +5334,7 @@ struct server *cli_find_server(struct appctx *appctx, char *arg)
cli_err(appctx, "No such backend.\n"); cli_err(appctx, "No such backend.\n");
return NULL; return NULL;
} }
if (!(sv = server_find_by_name(px, ist0(sv_name)))) { if (!(sv = server_find(px, ist0(sv_name)))) {
cli_err(appctx, "No such server.\n"); cli_err(appctx, "No such server.\n");
return NULL; return NULL;
} }
@ -5584,7 +5584,7 @@ static int cli_parse_get_weight(char **args, char *payload, struct appctx *appct
if (!(be = proxy_be_by_name(ist0(be_name)))) if (!(be = proxy_be_by_name(ist0(be_name))))
return cli_err(appctx, "No such backend.\n"); return cli_err(appctx, "No such backend.\n");
if (!(sv = server_find_by_name(be, ist0(sv_name)))) if (!(sv = server_find(be, ist0(sv_name))))
return cli_err(appctx, "No such server.\n"); return cli_err(appctx, "No such server.\n");
/* return server's effective weight at the moment */ /* return server's effective weight at the moment */
@ -6060,7 +6060,7 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
/* /*
* If a server with the same name is found, reject the new one. * If a server with the same name is found, reject the new one.
*/ */
if (server_find_by_name(be, sv_name)) { if (server_find(be, sv_name)) {
thread_release(); thread_release();
cli_err(appctx, "Already exists a server with the same name in backend.\n"); cli_err(appctx, "Already exists a server with the same name in backend.\n");
return 1; return 1;
@ -6291,7 +6291,7 @@ int srv_check_for_deletion(const char *bename, const char *svname, struct proxy
goto leave; goto leave;
} }
if (!(srv = server_find_by_name(be, svname))) { if (!(srv = server_find(be, svname))) {
msg = "No such server."; msg = "No such server.";
goto leave; goto leave;
} }

View File

@ -3850,7 +3850,7 @@ static int cli_parse_show_sess(char **args, char *payload, struct appctx *appctx
if (!(be = proxy_be_by_name(ist0(be_name)))) if (!(be = proxy_be_by_name(ist0(be_name))))
return cli_err(appctx, "No such backend.\n"); return cli_err(appctx, "No such backend.\n");
if (!(sv = server_find_by_name(be, ist0(sv_name)))) if (!(sv = server_find(be, ist0(sv_name))))
return cli_err(appctx, "No such server.\n"); return cli_err(appctx, "No such server.\n");
ctx->flags |= CLI_SHOWSESS_F_SERVER; ctx->flags |= CLI_SHOWSESS_F_SERVER;
ctx->filter = sv; ctx->filter = sv;

View File

@ -508,7 +508,7 @@ static int tcp_check_attach_srv(struct act_rule *rule, struct proxy *px, char **
memprintf(err, "attach-srv rule: no such backend '%s/%s'", ist0(be_name), ist0(sv_name)); memprintf(err, "attach-srv rule: no such backend '%s/%s'", ist0(be_name), ist0(sv_name));
return 0; return 0;
} }
if (!(srv = server_find_by_name(be, ist0(sv_name)))) { if (!(srv = server_find(be, ist0(sv_name)))) {
memprintf(err, "attach-srv rule: no such server '%s/%s'", ist0(be_name), ist0(sv_name)); memprintf(err, "attach-srv rule: no such server '%s/%s'", ist0(be_name), ist0(sv_name));
return 0; return 0;
} }