mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-05-06 01:37:59 +00:00
MEDIUM: server: Don't introduce a new server-state file version
This revert the commit 63e6cba12
("MEDIUM: server: add server-states version
2"), but keeping all recent features added to the server-sate file. Instead
of adding a 2nd version for the server-state file format to handle the 5 new
fields added during the 2.4 development, these fields are considered as
optionnal during the parsing. So it is possible to load a server-state file
from HAProxy 2.3. However, from 2.4, these new fields are always dumped in
the server-state file. But it should not be a problem to load it on the 2.3.
This patch seems a bit huge but the diff ignoring the space is much smaller.
The version 2 of the server-state file format is reserved for a real
refactoring to address all issues of the current format.
This commit is contained in:
parent
868a5757e5
commit
ea2cdf55e3
@ -101,9 +101,9 @@ enum srv_initaddr {
|
||||
} __attribute__((packed));
|
||||
|
||||
/* server-state-file version */
|
||||
#define SRV_STATE_FILE_VERSION 2
|
||||
#define SRV_STATE_FILE_VERSION 1
|
||||
#define SRV_STATE_FILE_VERSION_MIN 1
|
||||
#define SRV_STATE_FILE_VERSION_MAX 2
|
||||
#define SRV_STATE_FILE_VERSION_MAX 1
|
||||
#define SRV_STATE_FILE_FIELD_NAMES \
|
||||
"be_id " \
|
||||
"be_name " \
|
||||
@ -132,8 +132,8 @@ enum srv_initaddr {
|
||||
"srv_agent_port"
|
||||
|
||||
#define SRV_STATE_FILE_MAX_FIELDS 25
|
||||
#define SRV_STATE_FILE_NB_FIELDS_VERSION_1 20
|
||||
#define SRV_STATE_FILE_NB_FIELDS_VERSION_2 25
|
||||
#define SRV_STATE_FILE_MIN_FIELDS_VERSION_1 20
|
||||
#define SRV_STATE_FILE_MAX_FIELDS_VERSION_1 25
|
||||
#define SRV_STATE_LINE_MAXLEN 512
|
||||
|
||||
/* server flags -- 32 bits */
|
||||
|
61
src/server.c
61
src/server.c
@ -2598,7 +2598,7 @@ struct server *server_find_best_match(struct proxy *bk, char *name, int id, int
|
||||
}
|
||||
|
||||
/* Update a server state using the parameters available in the params list.
|
||||
*
|
||||
* The caller must provide a supported version
|
||||
* Grabs the server lock during operation.
|
||||
*/
|
||||
static void srv_update_state(struct server *srv, int version, char **params)
|
||||
@ -2636,10 +2636,11 @@ static void srv_update_state(struct server *srv, int version, char **params)
|
||||
msg = alloc_trash_chunk();
|
||||
if (!msg)
|
||||
goto end;
|
||||
|
||||
HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
|
||||
|
||||
if (version >= 1) {
|
||||
/* srv_addr: params[0]
|
||||
/* Only version 1 supported for now, don't check it. Fields are :
|
||||
* srv_addr: params[0]
|
||||
* srv_op_state: params[1]
|
||||
* srv_admin_state: params[2]
|
||||
* srv_uweight: params[3]
|
||||
@ -2655,6 +2656,11 @@ static void srv_update_state(struct server *srv, int version, char **params)
|
||||
* srv_fqdn: params[13]
|
||||
* srv_port: params[14]
|
||||
* srvrecord: params[15]
|
||||
* srv_use_ssl: params[16]
|
||||
* srv_check_port: params[17]
|
||||
* srv_check_addr: params[18]
|
||||
* srv_agent_addr: params[19]
|
||||
* srv_agent_port: params[20]
|
||||
*/
|
||||
|
||||
/* validating srv_op_state */
|
||||
@ -2986,15 +2992,8 @@ static void srv_update_state(struct server *srv, int version, char **params)
|
||||
if (port_st)
|
||||
srv->svc_port = port_svc;
|
||||
|
||||
}
|
||||
if (version >= 2) {
|
||||
/* srv_use_ssl: params[16]
|
||||
* srv_check_port: params[17]
|
||||
* srv_check_addr: params[18]
|
||||
* srv_agent_addr: params[19]
|
||||
* srv_agent_port: params[20]
|
||||
*/
|
||||
|
||||
if (params[16]) {
|
||||
#ifdef USE_OPENSSL
|
||||
use_ssl = strtol(params[16], &p, 10);
|
||||
|
||||
@ -3002,11 +3001,13 @@ static void srv_update_state(struct server *srv, int version, char **params)
|
||||
if (srv->ssl_ctx.ctx != NULL)
|
||||
ssl_sock_set_srv(srv, use_ssl);
|
||||
#endif
|
||||
}
|
||||
|
||||
port_st = NULL;
|
||||
if (strcmp(params[17], "0") != 0)
|
||||
if (params[17] && strcmp(params[17], "0") != 0)
|
||||
port_st = params[17];
|
||||
addr = NULL;
|
||||
if (strcmp(params[18], "-") != 0)
|
||||
if (params[18] && strcmp(params[18], "-") != 0)
|
||||
addr = params[18];
|
||||
if (addr || port_st) {
|
||||
warning = update_server_check_addr_port(srv, addr, port_st);
|
||||
@ -3017,10 +3018,10 @@ static void srv_update_state(struct server *srv, int version, char **params)
|
||||
}
|
||||
|
||||
port_st = NULL;
|
||||
if (strcmp(params[17], "0") != 0)
|
||||
if (params[20] && strcmp(params[20], "0") != 0)
|
||||
port_st = params[20];
|
||||
addr = NULL;
|
||||
if (strcmp(params[19], "-") != 0)
|
||||
if (params[19] && strcmp(params[19], "-") != 0)
|
||||
addr = params[19];
|
||||
if (addr || port_st) {
|
||||
warning = update_server_agent_addr_port(srv, addr, port_st);
|
||||
@ -3029,7 +3030,6 @@ static void srv_update_state(struct server *srv, int version, char **params)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
|
||||
@ -3073,6 +3073,7 @@ static int srv_state_get_version(FILE *f) {
|
||||
* parses server state line stored in <buf> and supposedly in version <version>.
|
||||
* Set <params> and <srv_params> accordingly.
|
||||
* In case of error, params[0] is set to NULL.
|
||||
* The caller must provide a supported version
|
||||
*/
|
||||
static void srv_state_parse_line(char *buf, const int version, char **params, char **srv_params)
|
||||
{
|
||||
@ -3140,20 +3141,16 @@ static void srv_state_parse_line(char *buf, const int version, char **params, ch
|
||||
* srv_fqdn: params[17] => srv_params[13]
|
||||
* srv_port: params[18] => srv_params[14]
|
||||
* srvrecord: params[19] => srv_params[15]
|
||||
* v2
|
||||
* srv_use_ssl: params[20] => srv_params[16]
|
||||
* srv_check_port: params[21] => srv_params[17]
|
||||
* srv_check_addr: params[22] => srv_params[18]
|
||||
* srv_agent_addr: params[23] => srv_params[19]
|
||||
* srv_agent_port: params[24] => srv_params[20]
|
||||
*
|
||||
* srv_use_ssl: params[20] => srv_params[16] (optional field)
|
||||
* srv_check_port: params[21] => srv_params[17] (optional field)
|
||||
* srv_check_addr: params[22] => srv_params[18] (optional field)
|
||||
* srv_agent_addr: params[23] => srv_params[19] (optional field)
|
||||
* srv_agent_port: params[24] => srv_params[20] (optional field)
|
||||
*/
|
||||
if ((version == 1 && arg >= 4 && arg <= 19) ||
|
||||
(version == 2 && arg >= 4)) {
|
||||
srv_params[srv_arg] = cur;
|
||||
++srv_arg;
|
||||
}
|
||||
params[arg] = cur;
|
||||
++arg;
|
||||
if ((version == 1 && arg >= 4))
|
||||
srv_params[srv_arg++] = cur;
|
||||
params[arg++] = cur;
|
||||
|
||||
/* Search end of the current field: first space or \0 */
|
||||
/* Search begining of the current field */
|
||||
@ -3168,8 +3165,9 @@ static void srv_state_parse_line(char *buf, const int version, char **params, ch
|
||||
end:
|
||||
/* if line is incomplete line, then ignore it.
|
||||
* otherwise, update useful flags */
|
||||
if ((version == 1 && arg < SRV_STATE_FILE_NB_FIELDS_VERSION_1) ||
|
||||
(version == 2 && arg < SRV_STATE_FILE_NB_FIELDS_VERSION_2))
|
||||
if (version == 1 &&
|
||||
arg < SRV_STATE_FILE_MIN_FIELDS_VERSION_1 &&
|
||||
arg > SRV_STATE_FILE_MAX_FIELDS_VERSION_1)
|
||||
params[0] = NULL;
|
||||
}
|
||||
|
||||
@ -3453,7 +3451,6 @@ void apply_server_state(void)
|
||||
* otherwise, update useful flags */
|
||||
switch (version) {
|
||||
case 1:
|
||||
case 2:
|
||||
bk_f_forced_id = (atoi(params[15]) & PR_O_FORCED_ID);
|
||||
check_id = (atoi(params[0]) == curproxy->uuid);
|
||||
check_name = (strcmp(curproxy->id, params[1]) == 0);
|
||||
|
Loading…
Reference in New Issue
Block a user