Commit c89e454e authored by Tollef Fog Heen's avatar Tollef Fog Heen

Add string representation of backend

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

Partially fixes #294.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3197 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent edf9158b
......@@ -85,6 +85,7 @@ struct director {
unsigned magic;
#define DIRECTOR_MAGIC 0x3336351d
const char *name;
char *vcl_name;
vdi_getfd_f *getfd;
vdi_fini_f *fini;
vdi_healthy *healthy;
......
......@@ -152,6 +152,7 @@ vdi_random_fini(struct director *d)
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 @@ VRT_init_dir_random(struct cli *cli, struct director **bp, const struct vrt_dir_
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;
......
......@@ -116,6 +116,7 @@ vdi_round_robin_fini(struct director *d)
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 @@ VRT_init_dir_round_robin(struct cli *cli, struct director **bp, const struct vrt
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;
......
......@@ -87,6 +87,7 @@ vdi_simple_fini(struct director *d)
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 @@ VRT_init_dir_simple(struct cli *cli, struct director **bp, const struct vrt_dir_
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;
......
......@@ -648,6 +648,14 @@ VRT_double_string(const struct sess *sp, double num)
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
......
# $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
......@@ -171,6 +171,7 @@ void VRT_fini_dir(struct cli *, struct director *);
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 { \
......
......@@ -150,6 +150,9 @@ vcc_StringVal(struct tokenlist *tl)
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",
......
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