r4405 - in trunk/varnish-cache: bin/varnishd include lib/libvcl
phk at projects.linpro.no
phk at projects.linpro.no
Wed Dec 16 11:45:39 CET 2009
Author: phk
Date: 2009-12-16 11:45:39 +0100 (Wed, 16 Dec 2009)
New Revision: 4405
Modified:
trunk/varnish-cache/bin/varnishd/cache_backend.h
trunk/varnish-cache/bin/varnishd/cache_vrt.c
trunk/varnish-cache/include/vrt.h
trunk/varnish-cache/lib/libvcl/vcc_backend.c
trunk/varnish-cache/lib/libvcl/vcc_compile.h
trunk/varnish-cache/lib/libvcl/vcc_dir_random.c
trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c
trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:
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.
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h 2009-12-16 10:16:59 UTC (rev 4404)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h 2009-12-16 10:45:39 UTC (rev 4405)
@@ -154,3 +154,15 @@
/* cache_backend_poll.c */
void VBP_Start(struct backend *b, struct vrt_backend_probe const *p);
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 *);
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-12-16 10:16:59 UTC (rev 4404)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-12-16 10:45:39 UTC (rev 4405)
@@ -850,7 +850,24 @@
}
/*--------------------------------------------------------------------*/
+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
VRT_Rollback(struct sess *sp)
{
Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h 2009-12-16 10:16:59 UTC (rev 4404)
+++ trunk/varnish-cache/include/vrt.h 2009-12-16 10:45:39 UTC (rev 4405)
@@ -161,12 +161,8 @@
void VRT_synth_page(struct sess *sp, unsigned flags, const char *, ...);
/* Backend related */
-void VRT_init_dir_simple(struct cli *, struct director **,
- const struct vrt_backend *);
-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_init_dir(struct cli *, struct director **, const char *name,
+ int idx, const void *priv);
void VRT_fini_dir(struct cli *, struct director *);
char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2009-12-16 10:16:59 UTC (rev 4404)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2009-12-16 10:45:39 UTC (rev 4405)
@@ -70,7 +70,6 @@
struct host {
VTAILQ_ENTRY(host) list;
- int hnum;
struct token *name;
char *vgcname;
};
@@ -487,8 +486,7 @@
*/
static void
-vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial,
- const char *vgcname)
+vcc_ParseHostDef(struct tokenlist *tl, int serial, const char *vgcname)
{
struct token *t_field;
struct token *t_first;
@@ -523,8 +521,8 @@
AN(vsb);
tl->fb = vsb;
- *nbh = tl->nbackend_host++;
- Fb(tl, 0, "\nstatic const struct vrt_backend bh_%d = {\n", *nbh);
+ Fb(tl, 0, "\nstatic const struct vrt_backend vgc_dir_priv_%s = {\n",
+ vgcname);
Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(tl->t_dir));
if (serial >= 0)
@@ -676,8 +674,8 @@
Fh(tl, 0, "%s", vsb_data(vsb));
vsb_delete(vsb);
- Fi(tl, 0, "\tVRT_init_dir_simple(cli, &VGCDIR(%s), &bh_%d);\n",
- vgcname, *nbh);
+ Fi(tl, 0, "\tVRT_init_dir(cli, VCL_conf.director, \"simple\",\n"
+ "\t VGC_backend_%s, &vgc_dir_priv_%s);\n", vgcname, vgcname);
Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(%s));\n", vgcname);
tl->ndirector++;
}
@@ -695,12 +693,14 @@
*/
void
-vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, int serial)
+vcc_ParseBackendHost(struct tokenlist *tl, int serial, char **nm)
{
struct host *h;
struct token *t;
char vgcname[BUFSIZ];
+ AN(nm);
+ *nm = NULL;
if (tl->t->tok == ID) {
VTAILQ_FOREACH(h, &tl->hosts, list) {
if (vcc_Teq(h->name, tl->t))
@@ -717,18 +717,22 @@
vcc_NextToken(tl);
ExpectErr(tl, ';');
vcc_NextToken(tl);
- *nbh = h->hnum;
+ *nm = h->vgcname;
} else if (tl->t->tok == '{') {
t = tl->t;
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) {
vsb_printf(tl->sb,
"\nIn backend host specification starting at:\n");
vcc_ErrWhere(tl, t);
}
+ *nm = strdup(vgcname); /* XXX */
+
return;
} else {
vsb_printf(tl->sb,
@@ -758,7 +762,7 @@
h->vgcname = TlAlloc(tl, strlen(vgcname) + 1);
strcpy(h->vgcname, vgcname);
- vcc_ParseHostDef(tl, &h->hnum, -1, vgcname);
+ vcc_ParseHostDef(tl, -1, vgcname);
ERRCHK(tl);
VTAILQ_INSERT_TAIL(&tl->hosts, h, list);
@@ -821,6 +825,13 @@
ExpectErr(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) {
vsb_printf(tl->sb,
Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2009-12-16 10:16:59 UTC (rev 4404)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2009-12-16 10:45:39 UTC (rev 4405)
@@ -81,7 +81,6 @@
VTAILQ_HEAD(, ref) refs;
struct vsb *sb;
int err;
- int nbackend_host;
int ndirector;
VTAILQ_HEAD(, proc) procs;
struct proc *curproc;
@@ -162,7 +161,7 @@
typedef void parsedirector_f(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, ...);
void vcc_ResetFldSpec(struct fld_spec *f);
void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs);
Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2009-12-16 10:16:59 UTC (rev 4404)
+++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2009-12-16 10:45:39 UTC (rev 4405)
@@ -53,13 +53,12 @@
vcc_ParseRandomDirector(struct tokenlist *tl)
{
struct token *t_field, *t_be;
- int nbh, nelem;
+ int nelem;
struct fld_spec *fs, *mfs;
unsigned u, retries;
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);
retries = 0;
@@ -88,7 +87,6 @@
first = "";
t_be = tl->t;
vcc_ResetFldSpec(mfs);
- nbh = -1;
ExpectErr(tl, '{');
vcc_NextToken(tl);
@@ -98,9 +96,11 @@
vcc_IsField(tl, &t_field, mfs);
ERRCHK(tl);
if (vcc_IdIs(t_field, "backend")) {
- vcc_ParseBackendHost(tl, &nbh, nelem);
- Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
+ vcc_ParseBackendHost(tl, nelem, &p);
ERRCHK(tl);
+ AN(p);
+ Fc(tl, 0, "%s .host = &vgc_dir_priv_%s",
+ first, p);
} else if (vcc_IdIs(t_field, "weight")) {
ExpectErr(tl, CNUM);
u = vcc_UintVal(tl);
@@ -135,13 +135,11 @@
}
Fc(tl, 0, "};\n");
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));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->t_dir));
Fc(tl, 0, "\t.retries = %u,\n", retries);
Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(tl->t_dir));
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));
}
Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2009-12-16 10:16:59 UTC (rev 4404)
+++ trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2009-12-16 10:45:39 UTC (rev 4405)
@@ -52,12 +52,11 @@
vcc_ParseRoundRobinDirector(struct tokenlist *tl)
{
struct token *t_field, *t_be;
- int nbh, nelem;
+ int nelem;
struct fld_spec *fs;
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);
Fc(tl, 0, "\nstatic const struct vrt_dir_round_robin_entry "
@@ -67,7 +66,6 @@
first = "";
t_be = tl->t;
vcc_ResetFldSpec(fs);
- nbh = -1;
ExpectErr(tl, '{');
vcc_NextToken(tl);
@@ -77,9 +75,11 @@
vcc_IsField(tl, &t_field, fs);
ERRCHK(tl);
if (vcc_IdIs(t_field, "backend")) {
- vcc_ParseBackendHost(tl, &nbh, nelem);
- Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
+ vcc_ParseBackendHost(tl, nelem, &p);
ERRCHK(tl);
+ AN(p);
+ Fc(tl, 0, "%s .host = &vgc_dir_priv_%s",
+ first, p);
} else {
ErrInternal(tl);
}
@@ -97,13 +97,10 @@
}
Fc(tl, 0, "};\n");
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));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->t_dir));
Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdrre_%.*s,\n", PF(tl->t_dir));
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));
}
Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-12-16 10:16:59 UTC (rev 4404)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-12-16 10:45:39 UTC (rev 4405)
@@ -227,8 +227,8 @@
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, "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, "40:23Z phk $\n *\n * Runtime support for compiled VCL ");
+ vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 4391 2009-12-14 12:");
+ 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, "libvcl/vcc_gen_fixed_token.tcl\n");
vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n");
@@ -297,13 +297,9 @@
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, "ss *sp, unsigned flags, const char *, ...);\n");
- vsb_cat(sb, "\n/* Backend related */\nvoid VRT_init_dir_simple(stru");
- vsb_cat(sb, "ct cli *, struct director **,\n");
- vsb_cat(sb, " const struct vrt_backend *);\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, "\n/* Backend related */\nvoid VRT_init_dir(struct cli ");
+ vsb_cat(sb, "*, struct director **, const char *name,\n");
+ vsb_cat(sb, " int idx, const void *priv);\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, "uct sockaddr *sa);\nchar *VRT_int_string(const struct ");
More information about the varnish-commit
mailing list