From: Willy Tarreau Date: Wed, 11 Dec 2013 19:36:34 +0000 (+0100) Subject: MINOR: checks: use check->state instead of srv->state & SRV_CHECKED X-Git-Tag: v1.5-dev20~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff5ae35b9fde764156b814dca8a57e83b8bcc0fd;p=thirdparty%2Fhaproxy.git MINOR: checks: use check->state instead of srv->state & SRV_CHECKED Having the check state partially stored in the server doesn't help. Some functions such as srv_getinter() rely on the server being checked to decide what check frequency to use, instead of relying on the check being configured. So let's get rid of SRV_CHECKED and SRV_AGENT_CHECKED and only use the check's states instead. --- diff --git a/include/types/server.h b/include/types/server.h index 7775369d61..54ab8133c7 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -48,7 +48,7 @@ #define SRV_BACKUP 0x0002 /* this server is a backup server */ #define SRV_MAPPORTS 0x0004 /* this server uses mapped ports */ /* unused: 0x0008 */ -#define SRV_CHECKED 0x0010 /* this server needs to be checked */ +/* unused: 0x0010 */ #define SRV_GOINGDOWN 0x0020 /* this server says that it's going down (404) */ #define SRV_WARMINGUP 0x0040 /* this server is warming up after a failure */ #define SRV_MAINTAIN 0x0080 /* this server is in maintenance mode */ @@ -56,9 +56,6 @@ /* unused: 0x0200, 0x0400 */ #define SRV_SEND_PROXY 0x0800 /* this server talks the PROXY protocol */ #define SRV_NON_STICK 0x1000 /* never add connections allocated to this server to a stick table */ -#define SRV_AGENT_CHECKED 0x2000 /* this server needs to be checked using an agent check. - * This is run independently of the main check whose - * presence is indicated by the SRV_CHECKED flag */ /* function which act on servers need to return various errors */ #define SRV_STATUS_OK 0 /* everything is OK. */ diff --git a/src/backend.c b/src/backend.c index 55debefafd..c680777435 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1443,7 +1443,7 @@ smp_fetch_srv_is_up(struct proxy *px, struct session *l4, void *l7, unsigned int smp->flags = SMP_F_VOL_TEST; smp->type = SMP_T_BOOL; if (!(srv->state & SRV_MAINTAIN) && - (!(srv->state & SRV_CHECKED) || (srv->state & SRV_RUNNING))) + (!(srv->check.state & CHK_ST_CONFIGURED) || (srv->state & SRV_RUNNING))) smp->data.uint = 1; else smp->data.uint = 0; diff --git a/src/cfgparse.c b/src/cfgparse.c index b67594114b..98d4c678e2 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -5124,7 +5124,6 @@ stats_error_parsing: } newsrv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED; - newsrv->state |= SRV_CHECKED; } if (do_agent) { @@ -5147,7 +5146,6 @@ stats_error_parsing: } newsrv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED; - newsrv->state |= SRV_AGENT_CHECKED; } if (!defsrv) { @@ -7018,7 +7016,7 @@ out_uri_auth_compat: goto next_srv; } - if (!(srv->state & SRV_CHECKED)) { + if (!(srv->check.state & CHK_ST_CONFIGURED)) { Alert("config : %s '%s', server '%s': unable to use %s/%s for " "tracking as it does not have checks enabled.\n", proxy_type_str(curproxy), curproxy->id, diff --git a/src/checks.c b/src/checks.c index 49bb411955..ec057812f4 100644 --- a/src/checks.c +++ b/src/checks.c @@ -736,8 +736,8 @@ static int httpchk_build_status_header(struct server *s, char *buffer) memcpy(buffer + hlen, "X-Haproxy-Server-State: ", 24); hlen += 24; - if (!(s->state & SRV_CHECKED)) - sv_state = 6; /* should obviously never happen */ + if (!(s->check.state & CHK_ST_ENABLED)) + sv_state = 6; else if (s->state & SRV_RUNNING) { if (s->check.health == s->check.rise + s->check.fall - 1) sv_state = 3; /* UP */ @@ -1506,7 +1506,7 @@ static struct task *process_chk(struct task *t) * stopped, the server should not be checked or the check * is disabled. */ - if (!(s->state & SRV_CHECKED) || + if (!(s->check.state & CHK_ST_ENABLED) || s->proxy->state == PR_STSTOPPED || (s->state & SRV_MAINTAIN) || !(check->state & CHK_ST_ENABLED)) @@ -1764,7 +1764,7 @@ int start_checks() { t->expire = TICK_ETERNITY; } - if (!(s->state & SRV_CHECKED)) + if (!(s->check.state & CHK_ST_CONFIGURED)) continue; if ((srv_getinter(&s->check) >= SRV_CHK_INTER_THRES) && @@ -1788,14 +1788,14 @@ int start_checks() { for (px = proxy; px; px = px->next) { for (s = px->srv; s; s = s->next) { /* A task for the main check */ - if (s->state & SRV_CHECKED) { + if (s->check.state & CHK_ST_CONFIGURED) { if (!start_check_task(&s->check, mininter, nbcheck, srvpos)) return -1; srvpos++; } /* A task for a auxiliary agent check */ - if (s->state & SRV_AGENT_CHECKED) { + if (s->agent.state & CHK_ST_CONFIGURED) { if (!start_check_task(&s->agent, mininter, nbcheck, srvpos)) { return -1; } diff --git a/src/dumpstats.c b/src/dumpstats.c index 350b111035..454795824f 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -2716,7 +2716,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); chunk_appendf(&trash, "MAINT(via)"); } - else if (ref->state & SRV_CHECKED) { + else if (ref->check.state & CHK_ST_ENABLED) { chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); chunk_appendf(&trash, srv_hlt_st[state], @@ -2724,7 +2724,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in (ref->state & SRV_RUNNING) ? (ref->check.fall) : (ref->check.rise)); } - if (sv->state & SRV_CHECKED) { + if (sv->check.state & CHK_ST_ENABLED) { chunk_appendf(&trash, " %s%s", (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", @@ -2759,7 +2759,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in (sv->state & SRV_BACKUP) ? "Y" : "-"); /* check failures: unique, fatal, down time */ - if (sv->state & SRV_CHECKED) { + if (sv->check.state & CHK_ST_ENABLED) { chunk_appendf(&trash, "%lld", ref->counters.failed_checks); if (ref->observe) @@ -2848,7 +2848,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in (sv->state & SRV_BACKUP) ? 1 : 0); /* check failures: unique, fatal; last change, total downtime */ - if (sv->state & SRV_CHECKED) + if (sv->check.state & CHK_ST_ENABLED) chunk_appendf(&trash, "%lld,%lld,%d,%d,", sv->counters.failed_checks, sv->counters.down_trans, @@ -2885,7 +2885,7 @@ static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, in read_freq_ctr(&sv->sess_per_sec), sv->counters.sps_max); - if (sv->state & SRV_CHECKED) { + if (sv->check.state & CHK_ST_ENABLED) { /* check_status */ chunk_appendf(&trash, "%s,", get_check_status_info(sv->check.status)); @@ -3407,7 +3407,7 @@ static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy svs = sv; /* FIXME: produce some small strings for "UP/DOWN x/y &#xxxx;" */ - if (!(svs->state & SRV_CHECKED)) + if (!(svs->check.state & CHK_ST_ENABLED)) sv_state = 8; else if (svs->state & SRV_RUNNING) { if (svs->check.health == svs->check.rise + svs->check.fall - 1) diff --git a/src/server.c b/src/server.c index a316daa5c7..d91c726a45 100644 --- a/src/server.c +++ b/src/server.c @@ -34,7 +34,7 @@ int srv_getinter(const struct check *check) { const struct server *s = check->server; - if ((s->state & SRV_CHECKED) && (check->health == check->rise + check->fall - 1)) + if ((check->state & CHK_ST_CONFIGURED) && (check->health == check->rise + check->fall - 1)) return check->inter; if (!(s->state & SRV_RUNNING) && check->health == 0)