Commit fa1136d5 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Get rid of all reference to backend index numbers in the compiled VCL code.

Unify the call to initialize a director, fan it out in the VRT code.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4405 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8ea1366c
...@@ -154,3 +154,15 @@ void VBE_DropRefLocked(struct backend *b); ...@@ -154,3 +154,15 @@ void VBE_DropRefLocked(struct backend *b);
/* cache_backend_poll.c */ /* cache_backend_poll.c */
void VBP_Start(struct backend *b, struct vrt_backend_probe const *p); void VBP_Start(struct backend *b, struct vrt_backend_probe const *p);
void VBP_Stop(struct backend *b); void VBP_Stop(struct backend *b);
/* Init functions for directors */
struct vrt_backend;
void VRT_init_dir_simple(struct cli *, struct director **,
const struct vrt_backend *);
struct vrt_dir_random;
void VRT_init_dir_random(struct cli *, struct director **,
const struct vrt_dir_random *);
struct vrt_dir_round_robin;
void VRT_init_dir_round_robin(struct cli *, struct director **,
const struct vrt_dir_round_robin *);
...@@ -849,6 +849,23 @@ VRT_backend_string(struct sess *sp) ...@@ -849,6 +849,23 @@ VRT_backend_string(struct sess *sp)
return (sp->director->vcl_name); return (sp->director->vcl_name);
} }
/*--------------------------------------------------------------------*/
void
VRT_init_dir(struct cli *cli, struct director **dir, const char *name,
int idx, const void *priv)
{
if (!strcmp(name, "simple"))
VRT_init_dir_simple(cli, dir + idx, priv);
else if (!strcmp(name, "random"))
VRT_init_dir_random(cli, dir + idx, priv);
else if (!strcmp(name, "round-robin"))
VRT_init_dir_round_robin(cli, dir + idx, priv);
else
INCOMPL();
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
......
...@@ -161,12 +161,8 @@ void VRT_Rollback(struct sess *sp); ...@@ -161,12 +161,8 @@ void VRT_Rollback(struct sess *sp);
void VRT_synth_page(struct sess *sp, unsigned flags, const char *, ...); void VRT_synth_page(struct sess *sp, unsigned flags, const char *, ...);
/* Backend related */ /* Backend related */
void VRT_init_dir_simple(struct cli *, struct director **, void VRT_init_dir(struct cli *, struct director **, const char *name,
const struct vrt_backend *); int idx, const void *priv);
void VRT_init_dir_random(struct cli *, struct director **,
const struct vrt_dir_random *);
void VRT_init_dir_round_robin(struct cli *, struct director **,
const struct vrt_dir_round_robin *);
void VRT_fini_dir(struct cli *, struct director *); void VRT_fini_dir(struct cli *, struct director *);
char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa); char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
......
...@@ -70,7 +70,6 @@ SVNID("$Id$") ...@@ -70,7 +70,6 @@ SVNID("$Id$")
struct host { struct host {
VTAILQ_ENTRY(host) list; VTAILQ_ENTRY(host) list;
int hnum;
struct token *name; struct token *name;
char *vgcname; char *vgcname;
}; };
...@@ -487,8 +486,7 @@ vcc_ParseProbe(struct tokenlist *tl) ...@@ -487,8 +486,7 @@ vcc_ParseProbe(struct tokenlist *tl)
*/ */
static void static void
vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial, vcc_ParseHostDef(struct tokenlist *tl, int serial, const char *vgcname)
const char *vgcname)
{ {
struct token *t_field; struct token *t_field;
struct token *t_first; struct token *t_first;
...@@ -523,8 +521,8 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial, ...@@ -523,8 +521,8 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial,
AN(vsb); AN(vsb);
tl->fb = vsb; tl->fb = vsb;
*nbh = tl->nbackend_host++; Fb(tl, 0, "\nstatic const struct vrt_backend vgc_dir_priv_%s = {\n",
Fb(tl, 0, "\nstatic const struct vrt_backend bh_%d = {\n", *nbh); vgcname);
Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(tl->t_dir)); Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(tl->t_dir));
if (serial >= 0) if (serial >= 0)
...@@ -676,8 +674,8 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial, ...@@ -676,8 +674,8 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial,
Fh(tl, 0, "%s", vsb_data(vsb)); Fh(tl, 0, "%s", vsb_data(vsb));
vsb_delete(vsb); vsb_delete(vsb);
Fi(tl, 0, "\tVRT_init_dir_simple(cli, &VGCDIR(%s), &bh_%d);\n", Fi(tl, 0, "\tVRT_init_dir(cli, VCL_conf.director, \"simple\",\n"
vgcname, *nbh); "\t VGC_backend_%s, &vgc_dir_priv_%s);\n", vgcname, vgcname);
Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(%s));\n", vgcname); Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(%s));\n", vgcname);
tl->ndirector++; tl->ndirector++;
} }
...@@ -695,12 +693,14 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial, ...@@ -695,12 +693,14 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial,
*/ */
void void
vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, int serial) vcc_ParseBackendHost(struct tokenlist *tl, int serial, char **nm)
{ {
struct host *h; struct host *h;
struct token *t; struct token *t;
char vgcname[BUFSIZ]; char vgcname[BUFSIZ];
AN(nm);
*nm = NULL;
if (tl->t->tok == ID) { if (tl->t->tok == ID) {
VTAILQ_FOREACH(h, &tl->hosts, list) { VTAILQ_FOREACH(h, &tl->hosts, list) {
if (vcc_Teq(h->name, tl->t)) if (vcc_Teq(h->name, tl->t))
...@@ -717,18 +717,22 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, int serial) ...@@ -717,18 +717,22 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, int serial)
vcc_NextToken(tl); vcc_NextToken(tl);
ExpectErr(tl, ';'); ExpectErr(tl, ';');
vcc_NextToken(tl); vcc_NextToken(tl);
*nbh = h->hnum; *nm = h->vgcname;
} else if (tl->t->tok == '{') { } else if (tl->t->tok == '{') {
t = tl->t; t = tl->t;
sprintf(vgcname, "%.*s_%d", PF(tl->t_dir), serial); sprintf(vgcname, "%.*s_%d", PF(tl->t_dir), serial);
vcc_ParseHostDef(tl, nbh, serial, vgcname); Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n",
PF(tl->t_dir));
vcc_ParseHostDef(tl, 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");
vcc_ErrWhere(tl, t); vcc_ErrWhere(tl, t);
} }
*nm = strdup(vgcname); /* XXX */
return; return;
} else { } else {
vsb_printf(tl->sb, vsb_printf(tl->sb,
...@@ -758,7 +762,7 @@ vcc_ParseSimpleDirector(struct tokenlist *tl) ...@@ -758,7 +762,7 @@ vcc_ParseSimpleDirector(struct tokenlist *tl)
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, -1, vgcname); vcc_ParseHostDef(tl, -1, vgcname);
ERRCHK(tl); ERRCHK(tl);
VTAILQ_INSERT_TAIL(&tl->hosts, h, list); VTAILQ_INSERT_TAIL(&tl->hosts, h, list);
...@@ -821,6 +825,13 @@ vcc_ParseDirector(struct tokenlist *tl) ...@@ -821,6 +825,13 @@ vcc_ParseDirector(struct tokenlist *tl)
ExpectErr(tl, '}'); ExpectErr(tl, '}');
vcc_NextToken(tl); vcc_NextToken(tl);
} }
Fi(tl, 0,
"\tVRT_init_dir(cli, VCL_conf.director, \"%.*s\",\n",
PF(tl->t_policy));
Fi(tl, 0, "\t VGC_backend__%.*s, &vgc_dir_priv_%.*s);\n",
PF(tl->t_dir), PF(tl->t_dir));
} }
if (tl->err) { if (tl->err) {
vsb_printf(tl->sb, vsb_printf(tl->sb,
......
...@@ -81,7 +81,6 @@ struct tokenlist { ...@@ -81,7 +81,6 @@ struct tokenlist {
VTAILQ_HEAD(, ref) refs; VTAILQ_HEAD(, ref) refs;
struct vsb *sb; struct vsb *sb;
int err; int err;
int nbackend_host;
int ndirector; int ndirector;
VTAILQ_HEAD(, proc) procs; VTAILQ_HEAD(, proc) procs;
struct proc *curproc; struct proc *curproc;
...@@ -162,7 +161,7 @@ struct fld_spec; ...@@ -162,7 +161,7 @@ struct fld_spec;
typedef void parsedirector_f(struct tokenlist *tl); typedef void parsedirector_f(struct tokenlist *tl);
void vcc_ParseDirector(struct tokenlist *tl); void vcc_ParseDirector(struct tokenlist *tl);
void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, int serial); void vcc_ParseBackendHost(struct tokenlist *tl, int serial, char **nm);
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);
......
...@@ -53,12 +53,11 @@ void ...@@ -53,12 +53,11 @@ void
vcc_ParseRandomDirector(struct tokenlist *tl) vcc_ParseRandomDirector(struct tokenlist *tl)
{ {
struct token *t_field, *t_be; struct token *t_field, *t_be;
int nbh, nelem; int nelem;
struct fld_spec *fs, *mfs; struct fld_spec *fs, *mfs;
unsigned u, retries; unsigned u, retries;
const char *first; const char *first;
char *p;
Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n", PF(tl->t_dir));
fs = vcc_FldSpec(tl, "?retries", NULL); fs = vcc_FldSpec(tl, "?retries", NULL);
...@@ -88,7 +87,6 @@ vcc_ParseRandomDirector(struct tokenlist *tl) ...@@ -88,7 +87,6 @@ vcc_ParseRandomDirector(struct tokenlist *tl)
first = ""; first = "";
t_be = tl->t; t_be = tl->t;
vcc_ResetFldSpec(mfs); vcc_ResetFldSpec(mfs);
nbh = -1;
ExpectErr(tl, '{'); ExpectErr(tl, '{');
vcc_NextToken(tl); vcc_NextToken(tl);
...@@ -98,9 +96,11 @@ vcc_ParseRandomDirector(struct tokenlist *tl) ...@@ -98,9 +96,11 @@ vcc_ParseRandomDirector(struct tokenlist *tl)
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, nelem); vcc_ParseBackendHost(tl, nelem, &p);
Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
ERRCHK(tl); ERRCHK(tl);
AN(p);
Fc(tl, 0, "%s .host = &vgc_dir_priv_%s",
first, p);
} else if (vcc_IdIs(t_field, "weight")) { } else if (vcc_IdIs(t_field, "weight")) {
ExpectErr(tl, CNUM); ExpectErr(tl, CNUM);
u = vcc_UintVal(tl); u = vcc_UintVal(tl);
...@@ -135,13 +135,11 @@ vcc_ParseRandomDirector(struct tokenlist *tl) ...@@ -135,13 +135,11 @@ vcc_ParseRandomDirector(struct tokenlist *tl)
} }
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 vgc_dir_priv_%.*s = {\n",
PF(tl->t_dir)); PF(tl->t_dir));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->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(tl->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, "\tVRT_init_dir_random(cli, &VGCDIR(_%.*s) , &vdr_%.*s);\n",
PF(tl->t_dir), PF(tl->t_dir));
} }
...@@ -52,11 +52,10 @@ void ...@@ -52,11 +52,10 @@ void
vcc_ParseRoundRobinDirector(struct tokenlist *tl) vcc_ParseRoundRobinDirector(struct tokenlist *tl)
{ {
struct token *t_field, *t_be; struct token *t_field, *t_be;
int nbh, nelem; int nelem;
struct fld_spec *fs; struct fld_spec *fs;
const char *first; const char *first;
char *p;
Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n", PF(tl->t_dir));
fs = vcc_FldSpec(tl, "!backend", NULL); fs = vcc_FldSpec(tl, "!backend", NULL);
...@@ -67,7 +66,6 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl) ...@@ -67,7 +66,6 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl)
first = ""; first = "";
t_be = tl->t; t_be = tl->t;
vcc_ResetFldSpec(fs); vcc_ResetFldSpec(fs);
nbh = -1;
ExpectErr(tl, '{'); ExpectErr(tl, '{');
vcc_NextToken(tl); vcc_NextToken(tl);
...@@ -77,9 +75,11 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl) ...@@ -77,9 +75,11 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl)
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, nelem); vcc_ParseBackendHost(tl, nelem, &p);
Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
ERRCHK(tl); ERRCHK(tl);
AN(p);
Fc(tl, 0, "%s .host = &vgc_dir_priv_%s",
first, p);
} else { } else {
ErrInternal(tl); ErrInternal(tl);
} }
...@@ -97,13 +97,10 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl) ...@@ -97,13 +97,10 @@ vcc_ParseRoundRobinDirector(struct tokenlist *tl)
} }
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 vgc_dir_priv_%.*s = {\n",
PF(tl->t_dir)); PF(tl->t_dir));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->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(tl->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("
"cli, &VGCDIR(_%.*s), &vdrr_%.*s);\n",
PF(tl->t_dir), PF(tl->t_dir));
} }
...@@ -227,8 +227,8 @@ vcl_output_lang_h(struct vsb *sb) ...@@ -227,8 +227,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI");
vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT");
vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n");
vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 4356 2009-11-19 11:"); vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 4391 2009-12-14 12:");
vsb_cat(sb, "40:23Z phk $\n *\n * Runtime support for compiled VCL "); vsb_cat(sb, "10:15Z phk $\n *\n * Runtime support for compiled VCL ");
vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/"); vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/");
vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n"); vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n");
vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n");
...@@ -297,13 +297,9 @@ vcl_output_lang_h(struct vsb *sb) ...@@ -297,13 +297,9 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, ");\nvoid VRT_Rollback(struct sess *sp);\n"); vsb_cat(sb, ");\nvoid VRT_Rollback(struct sess *sp);\n");
vsb_cat(sb, "\n/* Synthetic pages */\nvoid VRT_synth_page(struct se"); vsb_cat(sb, "\n/* Synthetic pages */\nvoid VRT_synth_page(struct se");
vsb_cat(sb, "ss *sp, unsigned flags, const char *, ...);\n"); vsb_cat(sb, "ss *sp, unsigned flags, const char *, ...);\n");
vsb_cat(sb, "\n/* Backend related */\nvoid VRT_init_dir_simple(stru"); vsb_cat(sb, "\n/* Backend related */\nvoid VRT_init_dir(struct cli ");
vsb_cat(sb, "ct cli *, struct director **,\n"); vsb_cat(sb, "*, struct director **, const char *name,\n");
vsb_cat(sb, " const struct vrt_backend *);\n"); vsb_cat(sb, " int idx, const void *priv);\n");
vsb_cat(sb, "void VRT_init_dir_random(struct cli *, struct director");
vsb_cat(sb, " **,\n const struct vrt_dir_random *);\n");
vsb_cat(sb, "void VRT_init_dir_round_robin(struct cli *, struct dir");
vsb_cat(sb, "ector **,\n const struct vrt_dir_round_robin *);\n");
vsb_cat(sb, "void VRT_fini_dir(struct cli *, struct director *);\n"); vsb_cat(sb, "void VRT_fini_dir(struct cli *, struct director *);\n");
vsb_cat(sb, "\nchar *VRT_IP_string(const struct sess *sp, const str"); vsb_cat(sb, "\nchar *VRT_IP_string(const struct sess *sp, const str");
vsb_cat(sb, "uct sockaddr *sa);\nchar *VRT_int_string(const struct "); vsb_cat(sb, "uct sockaddr *sa);\nchar *VRT_int_string(const struct ");
......
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