mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 21:31:28 +02:00
MEDIUM: server: split srv_init() in srv_preinit() + srv_postinit()
We actually need more granularity to split srv postparsing init tasks: Some of them are required to be run BEFORE the config is checked, and some of them AFTER the config is checked. Thus we push the logic from 368d0136 ("MEDIUM: server: add and use srv_init() function") a little bit further and split the function in two distinct ones, one of them executed under check_config_validity() and the other one using REGISTER_POST_SERVER_CHECK() hook. SRV_F_CHECKED flag was removed because it is no longer needed, srv_preinit() is only called once, and so is srv_postinit().
This commit is contained in:
parent
9736221e90
commit
cdb97cb73e
@ -171,7 +171,7 @@ enum srv_init_state {
|
|||||||
#define SRV_F_DEFSRV_USE_SSL 0x4000 /* default-server uses SSL */
|
#define SRV_F_DEFSRV_USE_SSL 0x4000 /* default-server uses SSL */
|
||||||
#define SRV_F_DELETED 0x8000 /* srv is deleted but not yet purged */
|
#define SRV_F_DELETED 0x8000 /* srv is deleted but not yet purged */
|
||||||
#define SRV_F_STRICT_MAXCONN 0x10000 /* maxconn is to be strictly enforced, as a limit of outbound connections */
|
#define SRV_F_STRICT_MAXCONN 0x10000 /* maxconn is to be strictly enforced, as a limit of outbound connections */
|
||||||
#define SRV_F_CHECKED 0x20000 /* set once server was postparsed */
|
/* unused: 0x20000 */
|
||||||
|
|
||||||
/* configured server options for send-proxy (server->pp_opts) */
|
/* configured server options for send-proxy (server->pp_opts) */
|
||||||
#define SRV_PP_V1 0x0001 /* proxy protocol version 1 */
|
#define SRV_PP_V1 0x0001 /* proxy protocol version 1 */
|
||||||
|
@ -74,7 +74,7 @@ struct server *new_server(struct proxy *proxy);
|
|||||||
void srv_take(struct server *srv);
|
void srv_take(struct server *srv);
|
||||||
struct server *srv_drop(struct server *srv);
|
struct server *srv_drop(struct server *srv);
|
||||||
void srv_free_params(struct server *srv);
|
void srv_free_params(struct server *srv);
|
||||||
int srv_init(struct server *srv);
|
int srv_preinit(struct server *srv);
|
||||||
void srv_set_ssl(struct server *s, int use_ssl);
|
void srv_set_ssl(struct server *s, int use_ssl);
|
||||||
const char *srv_adm_st_chg_cause(enum srv_adm_st_chg_cause cause);
|
const char *srv_adm_st_chg_cause(enum srv_adm_st_chg_cause cause);
|
||||||
const char *srv_op_st_chg_cause(enum srv_op_st_chg_cause cause);
|
const char *srv_op_st_chg_cause(enum srv_op_st_chg_cause cause);
|
||||||
|
@ -2824,7 +2824,7 @@ int check_config_validity()
|
|||||||
* as some of the fields may be accessed soon
|
* as some of the fields may be accessed soon
|
||||||
*/
|
*/
|
||||||
MT_LIST_FOR_EACH_ENTRY_LOCKED(newsrv, &servers_list, global_list, back) {
|
MT_LIST_FOR_EACH_ENTRY_LOCKED(newsrv, &servers_list, global_list, back) {
|
||||||
err_code |= srv_init(newsrv);
|
err_code |= srv_preinit(newsrv);
|
||||||
if (err_code & ERR_CODE)
|
if (err_code & ERR_CODE)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
45
src/server.c
45
src/server.c
@ -3363,7 +3363,7 @@ static int _srv_parse_tmpl_init(struct server *srv, struct proxy *px)
|
|||||||
* This function is expected to be called after _srv_parse_init() initialization
|
* This function is expected to be called after _srv_parse_init() initialization
|
||||||
* but only when the effective server's proxy mode is known, which is not always
|
* but only when the effective server's proxy mode is known, which is not always
|
||||||
* the case during parsing time, in which case the function will be called during
|
* the case during parsing time, in which case the function will be called during
|
||||||
* postparsing thanks to the srv_init() below.
|
* postparsing thanks to the srv_postinit() below.
|
||||||
*
|
*
|
||||||
* Returns ERR_NONE on success else a combination or ERR_CODE.
|
* Returns ERR_NONE on success else a combination or ERR_CODE.
|
||||||
*/
|
*/
|
||||||
@ -3427,7 +3427,27 @@ static int _srv_check_proxy_mode(struct server *srv, char postparse)
|
|||||||
|
|
||||||
return err_code;
|
return err_code;
|
||||||
}
|
}
|
||||||
/* Finish initializing the server after parsing
|
|
||||||
|
/* Finish initializing the server after parsing and before config checks
|
||||||
|
*
|
||||||
|
* Returns ERR_NONE on success else a combination or ERR_CODE.
|
||||||
|
*/
|
||||||
|
static int srv_init_per_thr(struct server *srv);
|
||||||
|
int srv_preinit(struct server *srv)
|
||||||
|
{
|
||||||
|
int err_code = ERR_NONE;
|
||||||
|
|
||||||
|
if (srv_init_per_thr(srv) == -1) {
|
||||||
|
ha_alert("error during per-thread init for %s/%s server\n", srv->proxy->id, srv->id);
|
||||||
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return err_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finish initializing the server after parsing and config checks
|
||||||
*
|
*
|
||||||
* We must be careful that checks / postinits performed within this function
|
* We must be careful that checks / postinits performed within this function
|
||||||
* don't depend or conflict with other postcheck functions that are registered
|
* don't depend or conflict with other postcheck functions that are registered
|
||||||
@ -3437,14 +3457,10 @@ static int _srv_check_proxy_mode(struct server *srv, char postparse)
|
|||||||
*/
|
*/
|
||||||
static int init_srv_requeue(struct server *srv);
|
static int init_srv_requeue(struct server *srv);
|
||||||
static int init_srv_slowstart(struct server *srv);
|
static int init_srv_slowstart(struct server *srv);
|
||||||
static int srv_init_per_thr(struct server *srv);
|
int srv_postinit(struct server *srv)
|
||||||
int srv_init(struct server *srv)
|
|
||||||
{
|
{
|
||||||
int err_code = ERR_NONE;
|
int err_code = ERR_NONE;
|
||||||
|
|
||||||
if (srv->flags & SRV_F_CHECKED)
|
|
||||||
return ERR_NONE; // nothing to do
|
|
||||||
|
|
||||||
err_code |= _srv_check_proxy_mode(srv, 1);
|
err_code |= _srv_check_proxy_mode(srv, 1);
|
||||||
|
|
||||||
if (err_code & ERR_CODE)
|
if (err_code & ERR_CODE)
|
||||||
@ -3474,12 +3490,6 @@ int srv_init(struct server *srv)
|
|||||||
if (err_code & ERR_CODE)
|
if (err_code & ERR_CODE)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (srv_init_per_thr(srv) == -1) {
|
|
||||||
ha_alert("error during per-thread init for %s/%s server\n", srv->proxy->id, srv->id);
|
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize idle conns lists */
|
/* initialize idle conns lists */
|
||||||
if (srv->max_idle_conns != 0) {
|
if (srv->max_idle_conns != 0) {
|
||||||
srv->curr_idle_thr = ha_aligned_zalloc(64, global.nbthread * sizeof(*srv->curr_idle_thr));
|
srv->curr_idle_thr = ha_aligned_zalloc(64, global.nbthread * sizeof(*srv->curr_idle_thr));
|
||||||
@ -3492,11 +3502,9 @@ int srv_init(struct server *srv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (!(err_code & ERR_CODE))
|
|
||||||
srv->flags |= SRV_F_CHECKED;
|
|
||||||
return err_code;
|
return err_code;
|
||||||
}
|
}
|
||||||
REGISTER_POST_SERVER_CHECK(srv_init);
|
REGISTER_POST_SERVER_CHECK(srv_postinit);
|
||||||
|
|
||||||
/* Allocate a new server pointed by <srv> and try to parse the first arguments
|
/* Allocate a new server pointed by <srv> and try to parse the first arguments
|
||||||
* in <args> as an address for a server or an address-range for a template or
|
* in <args> as an address for a server or an address-range for a template or
|
||||||
@ -6181,7 +6189,10 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct
|
|||||||
srv->agent.state &= ~CHK_ST_ENABLED;
|
srv->agent.state &= ~CHK_ST_ENABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
errcode = srv_init(srv);
|
errcode = srv_preinit(srv);
|
||||||
|
if (errcode)
|
||||||
|
goto out;
|
||||||
|
errcode = srv_postinit(srv);
|
||||||
if (errcode)
|
if (errcode)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user