]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: server: simplify server_find_by_id()
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Jul 2025 14:35:27 +0000 (16:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 15 Jul 2025 08:30:28 +0000 (10:30 +0200)
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.

include/haproxy/server.h
src/server.c

index 50768e79f41dc063a0c41f10170453e48623dd2c..b1b1588eb32ef391f65904649c0a0defebc29409 100644 (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
index c0a0bd5520c31182c7b27872fefbc2ffecc3290c..f92787483ae48132dae05ecab41ca4f0a1002ba9 100644 (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>.