r4396 - trunk/varnish-cache/lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Tue Dec 15 13:27:51 CET 2009


Author: phk
Date: 2009-12-15 13:27:51 +0100 (Tue, 15 Dec 2009)
New Revision: 4396

Modified:
   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
Log:
Avoid dragging the name and policy of the director around in arguments.



Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c	2009-12-15 11:55:07 UTC (rev 4395)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c	2009-12-15 12:27:51 UTC (rev 4396)
@@ -191,21 +191,18 @@
  */
 
 static void
-vcc_EmitBeIdent(struct vsb *v, const struct token *name,
-    const struct token *qual, int serial, const struct token *first,
-    const struct token *last)
+vcc_EmitBeIdent(struct tokenlist *tl, struct vsb *v, 
+    int serial, const struct token *first, const struct token *last)
 {
 
-	AN(name);
-	AN(qual);
 	assert(first != last);
 	vsb_printf(v, "\t.ident =");
 	if (serial >= 0) {
 		vsb_printf(v, "\n\t    \"%.*s %.*s [%d] \"",
-		    PF(qual), PF(name), serial);
+		    PF(tl->t_policy), PF(tl->t_dir), serial);
 	} else {
 		vsb_printf(v, "\n\t    \"%.*s %.*s \"",
-		    PF(qual), PF(name));
+		    PF(tl->t_policy), PF(tl->t_dir));
 	}
 	while (1) {
 		if (first->dec != NULL)
@@ -490,8 +487,8 @@
  */
 
 static void
-vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name,
-    const struct token *qual, int serial, const char *vgcname)
+vcc_ParseHostDef(struct tokenlist *tl, int *nbh, int serial,
+    const char *vgcname)
 {
 	struct token *t_field;
 	struct token *t_first;
@@ -530,7 +527,7 @@
 	*nbh = tl->nbackend_host++;
 	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)
 		Fb(tl, 0, "[%d]", serial);
 	Fb(tl, 0, "\",\n");
@@ -657,7 +654,7 @@
 	ExpectErr(tl, '}');
 
 	/* 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 */
 	Fb(tl, 0, "\t.hosthdr = ");
@@ -699,8 +696,7 @@
  */
 
 void
-vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name,
-    const struct token *qual, int serial)
+vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, int serial)
 {
 	struct host *h;
 	struct token *t;
@@ -726,9 +722,9 @@
 	} else if (tl->t->tok == '{') {
 		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) {
 			vsb_printf(tl->sb,
 			    "\nIn backend host specification starting at:\n");
@@ -751,20 +747,19 @@
  */
 
 static void
-vcc_ParseSimpleDirector(struct tokenlist *tl, const struct token *t_first,
-    struct token *t_dir)
+vcc_ParseSimpleDirector(struct tokenlist *tl)
 {
 	struct host *h;
 	char vgcname[BUFSIZ];
 
 	h = TlAlloc(tl, sizeof *h);
-	h->name = t_dir;
-	vcc_AddDef(tl, t_dir, R_BACKEND);
+	h->name = tl->t_dir;
+	vcc_AddDef(tl, tl->t_dir, R_BACKEND);
 	sprintf(vgcname, "VGC_backend__%.*s", PF(h->name));
 	h->vgcname = TlAlloc(tl, strlen(vgcname) + 1);
 	strcpy(h->vgcname, vgcname);
 
-	vcc_ParseHostDef(tl, &h->hnum, h->name, t_first, -1, vgcname);
+	vcc_ParseHostDef(tl, &h->hnum, -1, vgcname);
 	ERRCHK(tl);
 
 	VTAILQ_INSERT_TAIL(&tl->hosts, h, list);
@@ -786,7 +781,7 @@
 void
 vcc_ParseDirector(struct tokenlist *tl)
 {
-	struct token *t_dir, *t_first, *t_policy;
+	struct token *t_first;
 	struct dirlist const *dl;
 
 	t_first = tl->t;
@@ -794,35 +789,36 @@
 
 	vcc_ExpectCid(tl);		/* ID: name */
 	ERRCHK(tl);
-	t_dir = tl->t;
+	tl->t_dir = tl->t;
 	vcc_NextToken(tl);
 
 
 	if (vcc_IdIs(t_first, "backend")) {
-		vcc_ParseSimpleDirector(tl, t_first, t_dir);
+		tl->t_policy = t_first;
+		vcc_ParseSimpleDirector(tl);
 	} else {
 		Fh(tl, 1,
 		    "\n#define VGC_backend__%.*s (VCL_conf.director[%d])\n",
-		    PF(t_dir), tl->ndirector);
-		vcc_AddDef(tl, t_dir, R_BACKEND);
+		    PF(tl->t_dir), tl->ndirector);
+		vcc_AddDef(tl, tl->t_dir, R_BACKEND);
 		tl->ndirector++;
 		ExpectErr(tl, ID);		/* ID: policy */
-		t_policy = tl->t;
+		tl->t_policy = tl->t;
 		vcc_NextToken(tl);
 
 		for (dl = dirlist; dl->name != NULL; dl++)
-			if (vcc_IdIs(t_policy, dl->name))
+			if (vcc_IdIs(tl->t_policy, dl->name))
 				break;
 		if (dl->name == NULL) {
 			vsb_printf(tl->sb, "Unknown director policy: ");
-			vcc_ErrToken(tl, t_policy);
+			vcc_ErrToken(tl, tl->t_policy);
 			vsb_printf(tl->sb, " at\n");
-			vcc_ErrWhere(tl, t_policy);
+			vcc_ErrWhere(tl, tl->t_policy);
 			return;
 		}
 		ExpectErr(tl, '{');
 		vcc_NextToken(tl);
-		dl->func(tl, t_policy, t_dir);
+		dl->func(tl);
 		if (!tl->err) {
 			ExpectErr(tl, '}');
 			vcc_NextToken(tl);
@@ -834,4 +830,6 @@
 		vcc_ErrWhere(tl, t_first);
 		return;
 	}
+	tl->t_policy = NULL;
+	tl->t_dir = NULL;
 }

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2009-12-15 11:55:07 UTC (rev 4395)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2009-12-15 12:27:51 UTC (rev 4396)
@@ -89,6 +89,9 @@
 
 	VTAILQ_HEAD(, acl_e)	acl;
 
+	struct token		*t_dir;
+	struct token		*t_policy;
+
 	unsigned		recnt;
 	unsigned		nsockaddr;
 };
@@ -156,12 +159,10 @@
 
 /* vcc_backend.c */
 struct fld_spec;
-typedef void parsedirector_f(struct tokenlist *tl,
-    const struct token *t_policy, const struct token *t_dir);
+typedef void parsedirector_f(struct tokenlist *tl);
 
 void vcc_ParseDirector(struct tokenlist *tl);
-void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr,
-    const struct token *name, const struct token *qual, int serial);
+void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, int serial);
 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-15 11:55:07 UTC (rev 4395)
+++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c	2009-12-15 12:27:51 UTC (rev 4396)
@@ -50,8 +50,7 @@
  */
 
 void
-vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy,
-    const struct token *t_dir)
+vcc_ParseRandomDirector(struct tokenlist *tl)
 {
 	struct token *t_field, *t_be;
 	int nbh, nelem;
@@ -59,7 +58,7 @@
 	unsigned u, retries;
 	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);
 
@@ -83,7 +82,7 @@
 
 	Fc(tl, 0,
 	    "\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 */
 		first = "";
@@ -99,8 +98,7 @@
 			vcc_IsField(tl, &t_field, mfs);
 			ERRCHK(tl);
 			if (vcc_IdIs(t_field, "backend")) {
-				vcc_ParseBackendHost(tl, &nbh,
-				    t_dir, t_policy, nelem);
+				vcc_ParseBackendHost(tl, &nbh, nelem);
 				Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
 				ERRCHK(tl);
 			} else if (vcc_IdIs(t_field, "weight")) {
@@ -138,13 +136,13 @@
 	Fc(tl, 0, "};\n");
 	Fc(tl, 0,
 	    "\nstatic const struct vrt_dir_random vdr_%.*s = {\n",
-	    PF(t_dir));
-	Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir));
+	    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(t_dir));
+	Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(tl->t_dir));
 	Fc(tl, 0, "};\n");
 	Fi(tl, 0,
 	    "\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));
 }

Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c	2009-12-15 11:55:07 UTC (rev 4395)
+++ trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c	2009-12-15 12:27:51 UTC (rev 4396)
@@ -49,20 +49,19 @@
  */
 
 void
-vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy,
-    const struct token *t_dir)
+vcc_ParseRoundRobinDirector(struct tokenlist *tl)
 {
 	struct token *t_field, *t_be;
 	int nbh, nelem;
 	struct fld_spec *fs;
 	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);
 
 	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 */
 		first = "";
@@ -78,8 +77,7 @@
 			vcc_IsField(tl, &t_field, fs);
 			ERRCHK(tl);
 			if (vcc_IdIs(t_field, "backend")) {
-				vcc_ParseBackendHost(tl, &nbh,
-				    t_dir, t_policy, nelem);
+				vcc_ParseBackendHost(tl, &nbh, nelem);
 				Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
 				ERRCHK(tl);
 			} else {
@@ -100,11 +98,12 @@
 	Fc(tl, 0, "};\n");
 	Fc(tl, 0,
 	    "\nstatic const struct vrt_dir_round_robin vdrr_%.*s = {\n",
-	    PF(t_dir));
-	Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir));
+	    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(t_dir));
+	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, &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));
 }



More information about the varnish-commit mailing list