mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 21:31:28 +02:00
MINOR: server: add server_get_next_id() to find next free server ID
This was previously achieved via the generic get_next_id() but we'll soon get rid of generic ID trees so let's have a dedicated server_get_next_id(). As a bonus it reduces the exposure of the tree's root outside of the functions.
This commit is contained in:
parent
23605eddb1
commit
0b0aefe19b
@ -66,6 +66,7 @@ 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);
|
||||
uint server_get_next_id(const struct proxy *px, uint from);
|
||||
void apply_server_state(void);
|
||||
void srv_compute_all_admin_states(struct proxy *px);
|
||||
int srv_set_addr_via_libc(struct server *srv, int *err_code);
|
||||
|
@ -3726,7 +3726,7 @@ out_uri_auth_compat:
|
||||
/* server ID not set, use automatic numbering with first
|
||||
* spare entry starting with next_svid.
|
||||
*/
|
||||
next_id = get_next_id(&curproxy->conf.used_server_id, next_id);
|
||||
next_id = server_get_next_id(curproxy, next_id);
|
||||
newsrv->conf.id.key = newsrv->puid = next_id;
|
||||
eb32_insert(&curproxy->conf.used_server_id, &newsrv->conf.id);
|
||||
}
|
||||
|
19
src/server.c
19
src/server.c
@ -866,6 +866,23 @@ static const char *srv_find_best_kw(const char *word)
|
||||
return best_ptr;
|
||||
}
|
||||
|
||||
/* This function returns the first unused server ID greater than or equal to
|
||||
* <from> in the proxy <px>. Zero is returned if no spare one is found (should
|
||||
* never happen).
|
||||
*/
|
||||
uint server_get_next_id(const struct proxy *px, uint from)
|
||||
{
|
||||
const struct eb32_node *used;
|
||||
|
||||
do {
|
||||
used = eb32_lookup_ge((struct eb_root *)&px->conf.used_server_id, from);
|
||||
if (!used || used->key > from)
|
||||
return from; /* available */
|
||||
from++;
|
||||
} while (from);
|
||||
return from;
|
||||
}
|
||||
|
||||
/* Parse the "backup" server keyword */
|
||||
static int srv_parse_backup(char **args, int *cur_arg,
|
||||
struct proxy *curproxy, struct server *newsrv, char **err)
|
||||
@ -6228,7 +6245,7 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
|
||||
|
||||
/* generate the server id if not manually specified */
|
||||
if (!srv->puid) {
|
||||
next_id = get_next_id(&be->conf.used_server_id, 1);
|
||||
next_id = server_get_next_id(be, 1);
|
||||
if (!next_id) {
|
||||
ha_alert("Cannot attach server : no id left in proxy\n");
|
||||
goto out;
|
||||
|
Loading…
x
Reference in New Issue
Block a user