mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-28 15:42:30 +00:00
MINOR: checks: Simplify functions to get step id and comment
The loop to find the id corresponding to the current rule in tcpcheck_get_step_id() function has been simplified. And tcpcheck_get_step_comment() function now only relies on the current rule to find the rigth comment string. The step id is no longer used. To do so, we iterate backward from the current step to find the first COMMENT rule immediately preceedding the expect rule chain.
This commit is contained in:
parent
efab6c61d9
commit
3c29aa6393
72
src/checks.c
72
src/checks.c
@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
static int httpchk_expect(struct server *s, int done);
|
static int httpchk_expect(struct server *s, int done);
|
||||||
static int tcpcheck_get_step_id(struct check *);
|
static int tcpcheck_get_step_id(struct check *);
|
||||||
static char * tcpcheck_get_step_comment(struct check *, int);
|
static char *tcpcheck_get_step_comment(struct check *);
|
||||||
static int tcpcheck_main(struct check *);
|
static int tcpcheck_main(struct check *);
|
||||||
static void __event_srv_chk_w(struct conn_stream *cs);
|
static void __event_srv_chk_w(struct conn_stream *cs);
|
||||||
static int wake_srv_chk(struct conn_stream *cs);
|
static int wake_srv_chk(struct conn_stream *cs);
|
||||||
@ -664,7 +664,7 @@ static void chk_report_conn_err(struct check *check, int errno_bck, int expired)
|
|||||||
chunk_appendf(chk, " (send)");
|
chunk_appendf(chk, " (send)");
|
||||||
}
|
}
|
||||||
|
|
||||||
comment = tcpcheck_get_step_comment(check, step);
|
comment = tcpcheck_get_step_comment(check);
|
||||||
if (comment)
|
if (comment)
|
||||||
chunk_appendf(chk, " comment: '%s'", comment);
|
chunk_appendf(chk, " comment: '%s'", comment);
|
||||||
}
|
}
|
||||||
@ -2710,58 +2710,56 @@ static int httpchk_expect(struct server *s, int done)
|
|||||||
*/
|
*/
|
||||||
static int tcpcheck_get_step_id(struct check *check)
|
static int tcpcheck_get_step_id(struct check *check)
|
||||||
{
|
{
|
||||||
struct tcpcheck_rule *cur = NULL, *next = NULL;
|
struct tcpcheck_rule *cur;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
/* not even started anything yet => step 0 = initial connect */
|
/* not even started anything yet => step 0 = initial connect */
|
||||||
if (!check->current_step)
|
if (!check->current_step)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cur = check->last_started_step;
|
/* no last started step => first step */
|
||||||
|
if (!check->last_started_step)
|
||||||
/* no step => first step */
|
|
||||||
if (cur == NULL)
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* increment i until current step */
|
list_for_each_entry(cur, check->tcpcheck_rules, list) {
|
||||||
list_for_each_entry(next, check->tcpcheck_rules, list) {
|
if (cur->list.p == &check->last_started_step->list)
|
||||||
if (next->list.p == &cur->list)
|
|
||||||
break;
|
break;
|
||||||
++i;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return the latest known comment before (including) the given stepid
|
* return the latest known comment for the current rule, the comment attached to
|
||||||
* returns NULL if no comment found
|
* it or the COMMENT rule immediately preceedding the expect rule chain, if any.
|
||||||
|
* returns NULL if no comment found.
|
||||||
*/
|
*/
|
||||||
static char * tcpcheck_get_step_comment(struct check *check, int stepid)
|
static char *tcpcheck_get_step_comment(struct check *check)
|
||||||
{
|
{
|
||||||
struct tcpcheck_rule *cur = NULL;
|
struct tcpcheck_rule *cur;
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
/* not even started anything yet, return latest comment found before any action */
|
/* not even started anything yet, return latest comment found before any action */
|
||||||
if (!check->current_step) {
|
if (!check->current_step || !check->last_started_step) {
|
||||||
list_for_each_entry(cur, check->tcpcheck_rules, list) {
|
cur = LIST_NEXT(check->tcpcheck_rules, typeof(cur), list);
|
||||||
if (cur->action == TCPCHK_ACT_COMMENT)
|
if (cur->action == TCPCHK_ACT_COMMENT)
|
||||||
ret = cur->comment;
|
ret = cur->comment;
|
||||||
else
|
goto return_comment;
|
||||||
goto return_comment;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 1;
|
if (check->last_started_step->comment) {
|
||||||
list_for_each_entry(cur, check->tcpcheck_rules, list) {
|
ret = check->last_started_step->comment;
|
||||||
if (cur->comment)
|
goto return_comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur = LIST_PREV(&check->last_started_step->list, typeof(cur), list);
|
||||||
|
list_for_each_entry_from_rev(cur, check->tcpcheck_rules, list) {
|
||||||
|
if (cur->action == TCPCHK_ACT_COMMENT) {
|
||||||
ret = cur->comment;
|
ret = cur->comment;
|
||||||
|
break;
|
||||||
if (i >= stepid)
|
}
|
||||||
goto return_comment;
|
else if (cur->action != TCPCHK_ACT_EXPECT)
|
||||||
|
break;
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return_comment:
|
return_comment:
|
||||||
@ -2919,7 +2917,7 @@ static int tcpcheck_main(struct check *check)
|
|||||||
if (!cs) {
|
if (!cs) {
|
||||||
step = tcpcheck_get_step_id(check);
|
step = tcpcheck_get_step_id(check);
|
||||||
chunk_printf(&trash, "TCPCHK error allocating connection at step %d", step);
|
chunk_printf(&trash, "TCPCHK error allocating connection at step %d", step);
|
||||||
comment = tcpcheck_get_step_comment(check, step);
|
comment = tcpcheck_get_step_comment(check);
|
||||||
if (comment)
|
if (comment)
|
||||||
chunk_appendf(&trash, " comment: '%s'", comment);
|
chunk_appendf(&trash, " comment: '%s'", comment);
|
||||||
set_server_check_status(check, HCHK_STATUS_SOCKERR,
|
set_server_check_status(check, HCHK_STATUS_SOCKERR,
|
||||||
@ -3044,7 +3042,7 @@ static int tcpcheck_main(struct check *check)
|
|||||||
step = tcpcheck_get_step_id(check);
|
step = tcpcheck_get_step_id(check);
|
||||||
chunk_printf(&trash, "TCPCHK error establishing connection at step %d: %s",
|
chunk_printf(&trash, "TCPCHK error establishing connection at step %d: %s",
|
||||||
step, strerror(errno));
|
step, strerror(errno));
|
||||||
comment = tcpcheck_get_step_comment(check, step);
|
comment = tcpcheck_get_step_comment(check);
|
||||||
if (comment)
|
if (comment)
|
||||||
chunk_appendf(&trash, " comment: '%s'", comment);
|
chunk_appendf(&trash, " comment: '%s'", comment);
|
||||||
set_server_check_status(check, HCHK_STATUS_L4CON,
|
set_server_check_status(check, HCHK_STATUS_L4CON,
|
||||||
@ -3055,7 +3053,7 @@ static int tcpcheck_main(struct check *check)
|
|||||||
case SF_ERR_INTERNAL:
|
case SF_ERR_INTERNAL:
|
||||||
step = tcpcheck_get_step_id(check);
|
step = tcpcheck_get_step_id(check);
|
||||||
chunk_printf(&trash, "TCPCHK error establishing connection at step %d", step);
|
chunk_printf(&trash, "TCPCHK error establishing connection at step %d", step);
|
||||||
comment = tcpcheck_get_step_comment(check, step);
|
comment = tcpcheck_get_step_comment(check);
|
||||||
if (comment)
|
if (comment)
|
||||||
chunk_appendf(&trash, " comment: '%s'", comment);
|
chunk_appendf(&trash, " comment: '%s'", comment);
|
||||||
set_server_check_status(check, HCHK_STATUS_SOCKERR,
|
set_server_check_status(check, HCHK_STATUS_SOCKERR,
|
||||||
@ -3159,7 +3157,7 @@ static int tcpcheck_main(struct check *check)
|
|||||||
/* empty response */
|
/* empty response */
|
||||||
step = tcpcheck_get_step_id(check);
|
step = tcpcheck_get_step_id(check);
|
||||||
chunk_printf(&trash, "TCPCHK got an empty response at step %d", step);
|
chunk_printf(&trash, "TCPCHK got an empty response at step %d", step);
|
||||||
comment = tcpcheck_get_step_comment(check, step);
|
comment = tcpcheck_get_step_comment(check);
|
||||||
if (comment)
|
if (comment)
|
||||||
chunk_appendf(&trash, " comment: '%s'", comment);
|
chunk_appendf(&trash, " comment: '%s'", comment);
|
||||||
set_server_check_status(check, HCHK_STATUS_L7RSP,
|
set_server_check_status(check, HCHK_STATUS_L7RSP,
|
||||||
@ -3257,7 +3255,7 @@ static int tcpcheck_main(struct check *check)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
comment = tcpcheck_get_step_comment(check, step);
|
comment = tcpcheck_get_step_comment(check);
|
||||||
if (comment)
|
if (comment)
|
||||||
chunk_appendf(&trash, " comment: '%s'", comment);
|
chunk_appendf(&trash, " comment: '%s'", comment);
|
||||||
set_server_check_status(check, HCHK_STATUS_L7RSP,
|
set_server_check_status(check, HCHK_STATUS_L7RSP,
|
||||||
|
Loading…
Reference in New Issue
Block a user