From: phk Date: Tue, 1 Jul 2008 19:23:56 +0000 (+0000) Subject: Fix a brain-o in the backend identification string: We need to X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72d40a44127e7e977df56a19e72fa549e96db5dd;p=varnish Fix a brain-o in the backend identification string: We need to explicitly and uniquely identify all backend stanzas because they have individual metrics. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2872 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index de5f15b7..a8eb9b47 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -45,10 +45,10 @@ struct sockaddr; * A backend is a host+port somewhere on the network */ struct vrt_backend { - const char *portname; - const char *hostname; - const char *vcl_name; - const char *ident; + char *portname; + char *hostname; + char *vcl_name; + char *ident; double connect_timeout; }; diff --git a/varnish-cache/lib/libvcl/vcc_backend.c b/varnish-cache/lib/libvcl/vcc_backend.c index 62ad3a26..f54d988b 100644 --- a/varnish-cache/lib/libvcl/vcc_backend.c +++ b/varnish-cache/lib/libvcl/vcc_backend.c @@ -72,16 +72,14 @@ CheckHostPort(const char *host, const char *port) */ static void -vcc_EmitBeIdent(struct vsb *v, const struct token *qual, int serial, const struct token *first, const struct token *last) +vcc_EmitBeIdent(struct vsb *v, const struct token *name, const char *qual, int serial, const struct token *first, const struct token *last) { vsb_printf(v, "\t.ident ="); - if (serial != 0 && qual != NULL) { - vsb_printf(v, "\n\t \"%.*s \"", PF(qual)); - qual = VTAILQ_NEXT(qual, list); - vsb_printf(v, "\n\t \"%.*s \"", PF(qual)); - vsb_printf(v, "\n\t \":: %d :: \"", serial); - } + AN(qual); + vsb_printf(v, "\n\t \"%s %.*s\"", qual, PF(name)); + if (serial != 0) + vsb_printf(v, "\n\t \"[%d]\"", serial); while (first != last) { if (first->dec != NULL) vsb_printf(v, "\n\t \"\\\"\" %.*s \"\\\" \"", @@ -213,7 +211,7 @@ vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs) */ static void -vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *qual, int serial) +vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) { struct token *t_field; struct token *t_first; @@ -274,6 +272,7 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *qual, i t_host = tl->t; vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "port")) { + ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_port = tl->t; vcc_NextToken(tl); @@ -330,8 +329,8 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *qual, i } ExpectErr(tl, '}'); - vcc_EmitBeIdent(tl->fh, qual, serial, t_first, tl->t); - Fh(tl, 0, "\t.vcl_name = \"%.*s", PF(qual)); + vcc_EmitBeIdent(tl->fh, name, qual, serial, t_first, tl->t); + Fh(tl, 0, "\t.vcl_name = \"%.*s", PF(name)); if (serial) Fh(tl, 0, "[%d]", serial); Fh(tl, 0, "\"\n};\n"); @@ -356,7 +355,7 @@ vcc_ParseBackend(struct tokenlist *tl) h->name = tl->t; vcc_NextToken(tl); - vcc_ParseBackendHost(tl, &nbh, h->name, 0); + vcc_ParseBackendHost(tl, &nbh, h->name, "backend", 0); ERRCHK(tl); h->hnum = nbh; @@ -421,7 +420,8 @@ vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir) vcc_IsField(tl, &t_field, fs); ERRCHK(tl); if (vcc_IdIs(t_field, "backend")) { - vcc_ParseBackendHost(tl, &nbh, t_dir, nelem); + vcc_ParseBackendHost(tl, &nbh, + t_dir, "random", nelem); Fc(tl, 0, " .host = &bh_%d,", nbh); ERRCHK(tl); } else if (vcc_IdIs(t_field, "weight")) { diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 00c38f18..237622e0 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -399,10 +399,10 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, " * A backend is a host+port somewhere on the network\n"); vsb_cat(sb, " */\n"); vsb_cat(sb, "struct vrt_backend {\n"); - vsb_cat(sb, " const char *portname;\n"); - vsb_cat(sb, " const char *hostname;\n"); - vsb_cat(sb, " const char *vcl_name;\n"); - vsb_cat(sb, " const char *ident;\n"); + vsb_cat(sb, " char *portname;\n"); + vsb_cat(sb, " char *hostname;\n"); + vsb_cat(sb, " char *vcl_name;\n"); + vsb_cat(sb, " char *ident;\n"); vsb_cat(sb, " double connect_timeout;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "\n");