Commit 5946ee7e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Avoid dragging the name and policy of the director around in arguments.



git-svn-id: http://www.varnish-cache.org/svn/trunk@4396 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 0c6d6494
...@@ -191,21 +191,18 @@ Emit_Sockaddr(struct tokenlist *tl, const struct token *t_host, ...@@ -191,21 +191,18 @@ Emit_Sockaddr(struct tokenlist *tl, const struct token *t_host,
*/ */
static void static void
vcc_EmitBeIdent(struct vsb *v, const struct token *name, vcc_EmitBeIdent(struct tokenlist *tl, struct vsb *v,
const struct token *qual, int serial, const struct token *first, int serial, const struct token *first, const struct token *last)
const struct token *last)
{ {
AN(name);
AN(qual);
assert(first != last); assert(first != last);
vsb_printf(v, "\t.ident ="); vsb_printf(v, "\t.ident =");
if (serial >= 0) { if (serial >= 0) {
vsb_printf(v, "\n\t \"%.*s %.*s [%d] \"", vsb_printf(v, "\n\t \"%.*s %.*s [%d] \"",
PF(qual), PF(name), serial); PF(tl->t_policy), PF(tl->t_dir), serial);
} else { } else {
vsb_printf(v, "\n\t \"%.*s %.*s \"", vsb_printf(v, "\n\t \"%.*s %.*s \"",
PF(qual), PF(name)); PF(tl->t_policy), PF(tl->t_dir));
} }
while (1) { while (1) {
if (first->dec != NULL) if (first->dec != NULL)
...@@ -490,8 +487,8 @@ vcc_ParseProbe(struct tokenlist *tl) ...@@ -490,8 +487,8 @@ vcc_ParseProbe(struct tokenlist *tl)
*/ */
static void static void
vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial,
const struct token *qual, int serial, const char *vgcname) const char *vgcname)
{ {
struct token *t_field; struct token *t_field;
struct token *t_first; struct token *t_first;
...@@ -530,7 +527,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, ...@@ -530,7 +527,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name,
*nbh = tl->nbackend_host++; *nbh = tl->nbackend_host++;
Fb(tl, 0, "\nstatic const struct vrt_backend bh_%d = {\n", *nbh); Fb(tl, 0, "\nstatic const struct vrt_backend bh_%d = {\n", *nbh);
Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(name)); Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(tl->t_dir));
if (serial >= 0) if (serial >= 0)
Fb(tl, 0, "[%d]", serial); Fb(tl, 0, "[%d]", serial);
Fb(tl, 0, "\",\n"); Fb(tl, 0, "\",\n");
...@@ -657,7 +654,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, ...@@ -657,7 +654,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name,
ExpectErr(tl, '}'); ExpectErr(tl, '}');
/* We have parsed it all, emit the ident string */ /* We have parsed it all, emit the ident string */
vcc_EmitBeIdent(tl->fb, name, qual, serial, t_first, tl->t); vcc_EmitBeIdent(tl, tl->fb, serial, t_first, tl->t);
/* Emit the hosthdr field, fall back to .host if not specified */ /* Emit the hosthdr field, fall back to .host if not specified */
Fb(tl, 0, "\t.hosthdr = "); Fb(tl, 0, "\t.hosthdr = ");
...@@ -699,8 +696,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, ...@@ -699,8 +696,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name,
*/ */
void void
vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, int serial)
const struct token *qual, int serial)
{ {
struct host *h; struct host *h;
struct token *t; struct token *t;
...@@ -726,9 +722,9 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, ...@@ -726,9 +722,9 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name,
} else if (tl->t->tok == '{') { } else if (tl->t->tok == '{') {
t = tl->t; t = tl->t;
sprintf(vgcname, "VGC_backend_%.*s_%d", PF(name), serial); sprintf(vgcname, "VGC_backend_%.*s_%d", PF(tl->t_dir), serial);
vcc_ParseHostDef(tl, nbh, name, qual, serial, vgcname); vcc_ParseHostDef(tl, nbh, serial, vgcname);
if (tl->err) { if (tl->err) {
vsb_printf(tl->sb, vsb_printf(tl->sb,
"\nIn backend host specification starting at:\n"); "\nIn backend host specification starting at:\n");
...@@ -751,20 +747,19 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, ...@@ -751,20 +747,19 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name,
*/ */
static void static void
vcc_ParseSimpleDirector(struct tokenlist *tl, const struct token *t_first, vcc_ParseSimpleDirector(struct tokenlist *tl)
struct token *t_dir)
{ {
struct host *h; struct host *h;
char vgcname[BUFSIZ]; char vgcname[BUFSIZ];
h = TlAlloc(tl, sizeof *h); h = TlAlloc(tl, sizeof *h);
h->name = t_dir; h->name = tl->t_dir;
vcc_AddDef(tl, t_dir, R_BACKEND); vcc_AddDef(tl, tl->t_dir, R_BACKEND);
sprintf(vgcname, "VGC_backend__%.*s", PF(h->name)); sprintf(vgcname, "VGC_backend__%.*s", PF(h->name));
h->vgcname = TlAlloc(tl, strlen(vgcname) + 1); h->vgcname = TlAlloc(tl, strlen(vgcname) + 1);
strcpy(h->vgcname, vgcname); strcpy(h->vgcname, vgcname);
vcc_ParseHostDef(tl, &h->hnum, h->name, t_first, -1, vgcname); vcc_ParseHostDef(tl, &h->hnum, -1, vgcname);
ERRCHK(tl); ERRCHK(tl);
VTAILQ_INSERT_TAIL(&tl->hosts, h, list); VTAILQ_INSERT_TAIL(&tl->hosts, h, list);
...@@ -786,7 +781,7 @@ static const struct dirlist { ...@@ -786,7 +781,7 @@ static const struct dirlist {
void void
vcc_ParseDirector(struct tokenlist *tl) vcc_ParseDirector(struct tokenlist *tl)
{ {
struct token *t_dir, *t_first, *t_policy; struct token *t_first;
struct dirlist const *dl; struct dirlist const *dl;
t_first = tl->t; t_first = tl->t;
...@@ -794,35 +789,36 @@ vcc_ParseDirector(struct tokenlist *tl) ...@@ -794,35 +789,36 @@ vcc_ParseDirector(struct tokenlist *tl)
vcc_ExpectCid(tl); /* ID: name */ vcc_ExpectCid(tl); /* ID: name */
ERRCHK(tl); ERRCHK(tl);
t_dir = tl->t; tl->t_dir = tl->t;
vcc_NextToken(tl); vcc_NextToken(tl);
if (vcc_IdIs(t_first, "backend")) { if (vcc_IdIs(t_first, "backend")) {
vcc_ParseSimpleDirector(tl, t_first, t_dir); tl->t_policy = t_first;
vcc_ParseSimpleDirector(tl);
} else { } else {
Fh(tl, 1, Fh(tl, 1,
"\n#define VGC_backend__%.*s (VCL_conf.director[%d])\n", "\n#define VGC_backend__%.*s (VCL_conf.director[%d])\n",
PF(t_dir), tl->ndirector); PF(tl->t_dir), tl->ndirector);
vcc_AddDef(tl, t_dir, R_BACKEND); vcc_AddDef(tl, tl->t_dir, R_BACKEND);
tl->ndirector++; tl->ndirector++;
ExpectErr(tl, ID); /* ID: policy */ ExpectErr(tl, ID); /* ID: policy */
t_policy = tl->t; tl->t_policy = tl->t;
vcc_NextToken(tl); vcc_NextToken(tl);
for (dl = dirlist; dl->name != NULL; dl++) for (dl = dirlist; dl->name != NULL; dl++)
if (vcc_IdIs(t_policy, dl->name)) if (vcc_IdIs(tl->t_policy, dl->name))
break; break;
if (dl->name == NULL) { if (dl->name == NULL) {
vsb_printf(tl->sb, "Unknown director policy: "); vsb_printf(tl->sb, "Unknown director policy: ");
vcc_ErrToken(tl, t_policy); vcc_ErrToken(tl, tl->t_policy);
vsb_printf(tl->sb, " at\n"); vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, t_policy); vcc_ErrWhere(tl, tl->t_policy);
return; return;
} }
ExpectErr(tl, '{'); ExpectErr(tl, '{');
vcc_NextToken(tl); vcc_NextToken(tl);
dl->func(tl, t_policy, t_dir); dl->func(tl);
if (!tl->err) { if (!tl->err) {
ExpectErr(tl, '}'); ExpectErr(tl, '}');
vcc_NextToken(tl); vcc_NextToken(tl);
...@@ -834,4 +830,6 @@ vcc_ParseDirector(struct tokenlist *tl) ...@@ -834,4 +830,6 @@ vcc_ParseDirector(struct tokenlist *tl)
vcc_ErrWhere(tl, t_first); vcc_ErrWhere(tl, t_first);
return; return;
} }
tl->t_policy = NULL;
tl->t_dir = NULL;
} }
...@@ -89,6 +89,9 @@ struct tokenlist { ...@@ -89,6 +89,9 @@ struct tokenlist {
VTAILQ_HEAD(, acl_e) acl; VTAILQ_HEAD(, acl_e) acl;
struct token *t_dir;
struct token *t_policy;
unsigned recnt; unsigned recnt;
unsigned nsockaddr; unsigned nsockaddr;
}; };
...@@ -156,12 +159,10 @@ void vcc_ParseAction(struct tokenlist *tl); ...@@ -156,12 +159,10 @@ void vcc_ParseAction(struct tokenlist *tl);
/* vcc_backend.c */ /* vcc_backend.c */
struct fld_spec; struct fld_spec;
typedef void parsedirector_f(struct tokenlist *tl, typedef void parsedirector_f(struct tokenlist *tl);
const struct token *t_policy, const struct token *t_dir);
void vcc_ParseDirector(struct tokenlist *tl); void vcc_ParseDirector(struct tokenlist *tl);
void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, int serial);
const struct token *name, const struct token *qual, int serial);
struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...); struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...);
void vcc_ResetFldSpec(struct fld_spec *f); void vcc_ResetFldSpec(struct fld_spec *f);
void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs); void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs);
......
...@@ -50,8 +50,7 @@ SVNID("$Id$") ...@@ -50,8 +50,7 @@ SVNID("$Id$")
*/ */
void void
vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, vcc_ParseRandomDirector(struct tokenlist *tl)
const struct token *t_dir)
{ {
struct token *t_field, *t_be; struct token *t_field, *t_be;
int nbh, nelem; int nbh, nelem;
...@@ -59,7 +58,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, ...@@ -59,7 +58,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy,
unsigned u, retries; unsigned u, retries;
const char *first; const char *first;
Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend__%.*s);\n", PF(t_dir)); Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend__%.*s);\n", PF(tl->t_dir));
fs = vcc_FldSpec(tl, "?retries", NULL); fs = vcc_FldSpec(tl, "?retries", NULL);
...@@ -83,7 +82,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, ...@@ -83,7 +82,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy,
Fc(tl, 0, Fc(tl, 0,
"\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n", "\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n",
PF(t_dir)); PF(tl->t_dir));
for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */ for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */
first = ""; first = "";
...@@ -99,8 +98,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, ...@@ -99,8 +98,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy,
vcc_IsField(tl, &t_field, mfs); vcc_IsField(tl, &t_field, mfs);
ERRCHK(tl); ERRCHK(tl);
if (vcc_IdIs(t_field, "backend")) { if (vcc_IdIs(t_field, "backend")) {
vcc_ParseBackendHost(tl, &nbh, vcc_ParseBackendHost(tl, &nbh, nelem);
t_dir, t_policy, nelem);
Fc(tl, 0, "%s .host = &bh_%d", first, nbh); Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
ERRCHK(tl); ERRCHK(tl);
} else if (vcc_IdIs(t_field, "weight")) { } else if (vcc_IdIs(t_field, "weight")) {
...@@ -138,13 +136,13 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, ...@@ -138,13 +136,13 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy,
Fc(tl, 0, "};\n"); Fc(tl, 0, "};\n");
Fc(tl, 0, Fc(tl, 0,
"\nstatic const struct vrt_dir_random vdr_%.*s = {\n", "\nstatic const struct vrt_dir_random vdr_%.*s = {\n",
PF(t_dir)); PF(tl->t_dir));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir)); Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->t_dir));
Fc(tl, 0, "\t.retries = %u,\n", retries); Fc(tl, 0, "\t.retries = %u,\n", retries);
Fc(tl, 0, "\t.nmember = %d,\n", nelem); Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir)); Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(tl->t_dir));
Fc(tl, 0, "};\n"); Fc(tl, 0, "};\n");
Fi(tl, 0, Fi(tl, 0,
"\tVRT_init_dir_random(cli, &VGC_backend__%.*s , &vdr_%.*s);\n", "\tVRT_init_dir_random(cli, &VGC_backend__%.*s , &vdr_%.*s);\n",
PF(t_dir), PF(t_dir)); PF(tl->t_dir), PF(tl->t_dir));
} }
...@@ -49,20 +49,19 @@ SVNID("$Id$") ...@@ -49,20 +49,19 @@ SVNID("$Id$")
*/ */
void void
vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy, vcc_ParseRoundRobinDirector(struct tokenlist *tl)
const struct token *t_dir)
{ {
struct token *t_field, *t_be; struct token *t_field, *t_be;
int nbh, nelem; int nbh, nelem;
struct fld_spec *fs; struct fld_spec *fs;
const char *first; const char *first;
Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend__%.*s);\n", PF(t_dir)); Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend__%.*s);\n", PF(tl->t_dir));
fs = vcc_FldSpec(tl, "!backend", NULL); fs = vcc_FldSpec(tl, "!backend", NULL);
Fc(tl, 0, "\nstatic const struct vrt_dir_round_robin_entry " Fc(tl, 0, "\nstatic const struct vrt_dir_round_robin_entry "
"vdrre_%.*s[] = {\n", PF(t_dir)); "vdrre_%.*s[] = {\n", PF(tl->t_dir));
for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */ for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */
first = ""; first = "";
...@@ -78,8 +77,7 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy, ...@@ -78,8 +77,7 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy,
vcc_IsField(tl, &t_field, fs); vcc_IsField(tl, &t_field, fs);
ERRCHK(tl); ERRCHK(tl);
if (vcc_IdIs(t_field, "backend")) { if (vcc_IdIs(t_field, "backend")) {
vcc_ParseBackendHost(tl, &nbh, vcc_ParseBackendHost(tl, &nbh, nelem);
t_dir, t_policy, nelem);
Fc(tl, 0, "%s .host = &bh_%d", first, nbh); Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
ERRCHK(tl); ERRCHK(tl);
} else { } else {
...@@ -100,11 +98,12 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy, ...@@ -100,11 +98,12 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy,
Fc(tl, 0, "};\n"); Fc(tl, 0, "};\n");
Fc(tl, 0, Fc(tl, 0,
"\nstatic const struct vrt_dir_round_robin vdrr_%.*s = {\n", "\nstatic const struct vrt_dir_round_robin vdrr_%.*s = {\n",
PF(t_dir)); PF(tl->t_dir));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir)); Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->t_dir));
Fc(tl, 0, "\t.nmember = %d,\n", nelem); Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdrre_%.*s,\n", PF(t_dir)); Fc(tl, 0, "\t.members = vdrre_%.*s,\n", PF(tl->t_dir));
Fc(tl, 0, "};\n"); Fc(tl, 0, "};\n");
Fi(tl, 0, "\tVRT_init_dir_round_robin(" Fi(tl, 0, "\tVRT_init_dir_round_robin("
"cli, &VGC_backend__%.*s , &vdrr_%.*s);\n", PF(t_dir), PF(t_dir)); "cli, &VGC_backend__%.*s , &vdrr_%.*s);\n",
PF(tl->t_dir), PF(tl->t_dir));
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment