r3197 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl

tfheen at projects.linpro.no tfheen at projects.linpro.no
Wed Sep 17 12:04:47 CEST 2008


Author: tfheen
Date: 2008-09-17 12:04:47 +0200 (Wed, 17 Sep 2008)
New Revision: 3197

Added:
   trunk/varnish-cache/bin/varnishtest/tests/b00016.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache_backend.h
   trunk/varnish-cache/bin/varnishd/cache_dir_random.c
   trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c
   trunk/varnish-cache/bin/varnishd/cache_dir_simple.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/include/vrt.h
   trunk/varnish-cache/lib/libvcl/vcc_string.c
Log:
Add string representation of backend

This takes the name from the name assigned in the VCL.

Partially fixes #294.


Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h	2008-09-17 07:49:28 UTC (rev 3196)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h	2008-09-17 10:04:47 UTC (rev 3197)
@@ -85,6 +85,7 @@
 	unsigned		magic;
 #define DIRECTOR_MAGIC		0x3336351d
 	const char		*name;
+	char			*vcl_name;
 	vdi_getfd_f		*getfd;
 	vdi_fini_f		*fini;
 	vdi_healthy		*healthy;

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2008-09-17 07:49:28 UTC (rev 3196)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2008-09-17 10:04:47 UTC (rev 3197)
@@ -152,6 +152,7 @@
 	for (i = 0; i < vs->nhosts; i++, vh++)
 		VBE_DropRef(vh->backend);
 	free(vs->hosts);
+	free(vs->dir.vcl_name);
 	vs->dir.magic = 0;
 	FREE_OBJ(vs);
 }
@@ -174,6 +175,7 @@
 	vs->dir.magic = DIRECTOR_MAGIC;
 	vs->dir.priv = vs;
 	vs->dir.name = "random";
+	REPLACE(vs->dir.vcl_name, t->name);
 	vs->dir.getfd = vdi_random_getfd;
 	vs->dir.fini = vdi_random_fini;
 	vs->dir.healthy = vdi_random_healthy;

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c	2008-09-17 07:49:28 UTC (rev 3196)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c	2008-09-17 10:04:47 UTC (rev 3197)
@@ -116,6 +116,7 @@
 	for (i = 0; i < vs->nhosts; i++, vh++)
 		VBE_DropRef(vh->backend);
 	free(vs->hosts);
+	free(vs->dir.vcl_name);
 	vs->dir.magic = 0;
 	vs->next_host = 0;
 	FREE_OBJ(vs);
@@ -139,6 +140,7 @@
 	vs->dir.magic = DIRECTOR_MAGIC;
 	vs->dir.priv = vs;
 	vs->dir.name = "round_robin";
+	REPLACE(vs->dir.vcl_name, t->name);
 	vs->dir.getfd = vdi_round_robin_getfd;
 	vs->dir.fini = vdi_round_robin_fini;
 	vs->dir.healthy = vdi_round_robin_healthy;

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_simple.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_simple.c	2008-09-17 07:49:28 UTC (rev 3196)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_simple.c	2008-09-17 10:04:47 UTC (rev 3197)
@@ -87,6 +87,7 @@
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
 	
 	VBE_DropRef(vs->backend);
+	free(vs->dir.vcl_name);
 	vs->dir.magic = 0;
 	FREE_OBJ(vs);
 }
@@ -103,6 +104,7 @@
 	vs->dir.magic = DIRECTOR_MAGIC;
 	vs->dir.priv = vs;
 	vs->dir.name = "simple";
+	REPLACE(vs->dir.vcl_name, t->host->vcl_name);
 	vs->dir.getfd = vdi_simple_getfd;
 	vs->dir.fini = vdi_simple_fini;
 	vs->dir.healthy = vdi_simple_healthy;

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-09-17 07:49:28 UTC (rev 3196)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-09-17 10:04:47 UTC (rev 3197)
@@ -648,6 +648,14 @@
 	return (p);
 }
 
+const char *
+VRT_backend_string(struct sess *sp)
+{
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+       CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+       return (sp->director->vcl_name);
+}
+
 /*--------------------------------------------------------------------*/
 
 void

Added: trunk/varnish-cache/bin/varnishtest/tests/b00016.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/b00016.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/b00016.vtc	2008-09-17 10:04:47 UTC (rev 3197)
@@ -0,0 +1,73 @@
+# $Id$
+
+test "Check naming of backends"
+
+varnish v1 -vcl { 
+	backend foo {
+		.host = "127.0.0.2";
+		.port = "9080";
+	}
+
+	sub vcl_recv {
+	    error 200 "ok";
+	}
+
+	sub vcl_error {
+	    set obj.http.X-Backend-Name = req.backend;
+	}
+} -start
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.http.X-Backend-Name == "foo"
+} -run
+
+varnish v1 -vcl { 
+	director bar random {
+		{
+		.backend = {
+		 	.host = "127.0.0.2";
+			.port = "9080";
+		}
+		.weight = 1;
+		}
+	}
+
+	sub vcl_recv {
+	    error 200 "ok";
+	}
+
+	sub vcl_error {
+	    set obj.http.X-Backend-Name = req.backend;
+	}
+}
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.http.X-Backend-Name == "bar"
+} -run
+
+varnish v1 -vcl { 
+	director baz round-robin {
+		 { .backend = {
+		 	.host = "127.0.0.2";
+			.port = "9080";
+		} }
+	}
+
+	sub vcl_recv {
+	    error 200 "ok";
+	}
+
+	sub vcl_error {
+	    set obj.http.X-Backend-Name = req.backend;
+	}
+}
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.http.X-Backend-Name == "baz"
+} -run

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h	2008-09-17 07:49:28 UTC (rev 3196)
+++ trunk/varnish-cache/include/vrt.h	2008-09-17 10:04:47 UTC (rev 3197)
@@ -171,6 +171,7 @@
 char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
 char *VRT_int_string(const struct sess *sp, int);
 char *VRT_double_string(const struct sess *sp, double);
+const char *VRT_backend_string(struct sess *sp);
 
 #define VRT_done(sp, hand)			\
 	do {					\

Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_string.c	2008-09-17 07:49:28 UTC (rev 3196)
+++ trunk/varnish-cache/lib/libvcl/vcc_string.c	2008-09-17 10:04:47 UTC (rev 3197)
@@ -150,6 +150,9 @@
 		case FLOAT:
 			Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
 			break;
+		case BACKEND:
+			Fb(tl, 0, "VRT_backend_string(sp)");
+			break;
 		default:
 			vsb_printf(tl->sb,
 			    "String representation of '%s' not implemented yet.\n",




More information about the varnish-commit mailing list