[master] 91dfd24 Add support for a default backend probe.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Jun 23 11:06:25 CEST 2015
commit 91dfd24d30bc7ae9f67d33ffbfb5cb840f8bd492
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Jun 23 09:05:32 2015 +0000
Add support for a default backend probe.
If you add a probe named "default" all backends will get it automatically,
unless they have their own .probe configuration.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 706c92b..71ac981 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1069,6 +1069,7 @@ void VRY_Finish(struct req *req, enum vry_finish_flag);
/* cache_vcl.c */
struct director *VCL_DefaultDirector(const struct vcl *);
+const struct vrt_backend_probe *VCL_DefaultProbe(const struct vcl *);
void VCL_Init(void);
const char *VCL_Method_Name(unsigned);
const char *VCL_Name(const struct vcl *);
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index e56ec77..7291cd4 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -59,6 +59,7 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
struct backend *b;
char buf[128];
struct vcl *vcl;
+ const struct vrt_backend_probe *vbp;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC);
@@ -99,8 +100,11 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
VBE_fill_director(b);
- if (vrt->probe != NULL)
- VBP_Insert(b, vrt->probe,
+ vbp = vrt->probe;
+ if (vbp == NULL)
+ vbp = VCL_DefaultProbe(vcl);
+ if (vbp != NULL)
+ VBP_Insert(b, vbp,
VBT_Ref(vrt->ipv4_suckaddr, vrt->ipv6_suckaddr));
VCL_AddBackend(ctx->vcl, b);
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 02404fd..40b630a 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -312,18 +312,27 @@ VCL_TestLoad(const char *fn)
/*--------------------------------------------------------------------*/
struct director *
-VCL_DefaultDirector(const struct vcl *vcc)
+VCL_DefaultDirector(const struct vcl *vcl)
{
- AN(vcc);
- return (*vcc->conf->default_director);
+ CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+ return (*vcl->conf->default_director);
}
const char *
-VCL_Name(const struct vcl *vcc)
+VCL_Name(const struct vcl *vcl)
{
- AN(vcc);
- return (vcc->loaded_name);
+
+ CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+ return (vcl->loaded_name);
+}
+
+const struct vrt_backend_probe *
+VCL_DefaultProbe(const struct vcl *vcl)
+{
+
+ CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+ return (vcl->conf->default_probe);
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishtest/tests/c00035.vtc b/bin/varnishtest/tests/c00035.vtc
index 5eab71d..4bffe36 100644
--- a/bin/varnishtest/tests/c00035.vtc
+++ b/bin/varnishtest/tests/c00035.vtc
@@ -6,26 +6,21 @@ server s1 -repeat 40 {
} -start
varnish v1 -vcl {
+ probe default {
+ .window = 8;
+ .initial = 7;
+ .threshold = 8;
+ .interval = 0.1s;
+ }
backend s1 {
.host = "${s1_addr}";
.port = "${s1_port}";
- .probe = {
- .window = 8;
- .initial = 7;
- .threshold = 8;
- .interval = 0.1s;
- }
}
} -start
delay 1
-varnish v1 -vcl {
- backend s1 {
- .host = "${s1_addr}";
- .port = "${s1_port}";
- }
-} -cliok "vcl.use vcl2" -cliok "vcl.discard vcl1"
+varnish v1 -vcl+backend { } -cliok "vcl.use vcl2" -cliok "vcl.discard vcl1"
delay 1
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 345ae05..39810fc 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -1055,18 +1055,19 @@ fo.write("\n" + tbl40("#define VCL_RET_MAX", "%d\n" % n))
fo.write("""
struct VCL_conf {
- unsigned magic;
-#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */
+ unsigned magic;
+#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */
- struct director **default_director;
- unsigned nref;
- struct vrt_ref *ref;
+ struct director **default_director;
+ const struct vrt_backend_probe *default_probe;
+ unsigned nref;
+ struct vrt_ref *ref;
- unsigned nsrc;
- const char **srcname;
- const char **srcbody;
+ unsigned nsrc;
+ const char **srcname;
+ const char **srcbody;
- vcl_event_f *event_vcl;
+ vcl_event_f *event_vcl;
""")
for i in returns:
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 9ef1c95..c0501a3 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -91,12 +91,14 @@ vcc_ProbeRedef(struct vcc *tl, struct token **t_did,
}
static void
-vcc_ParseProbeSpec(struct vcc *tl)
+vcc_ParseProbeSpec(struct vcc *tl, const struct token *nm, char **name)
{
struct fld_spec *fs;
struct token *t_field;
struct token *t_did = NULL, *t_window = NULL, *t_threshold = NULL;
struct token *t_initial = NULL;
+ struct vsb *vsb;
+ char *retval;
unsigned window, threshold, initial, status;
double t;
@@ -113,12 +115,23 @@ vcc_ParseProbeSpec(struct vcc *tl)
SkipToken(tl, '{');
+ vsb = VSB_new_auto();
+ AN(vsb);
+ if (nm != NULL)
+ VSB_printf(vsb, "vgc_probe_%.*s", PF(nm));
+ else
+ VSB_printf(vsb, "vgc_probe__%d", tl->nprobe++);
+ AZ(VSB_finish(vsb));
+ retval = TlDup(tl, VSB_data(vsb));
+ VSB_delete(vsb);
+ if (name != NULL)
+ *name = retval;
+
window = 0;
threshold = 0;
initial = 0;
status = 0;
- Fh(tl, 0, "static const struct vrt_backend_probe vgc_probe__%d = {\n",
- tl->nprobe++);
+ Fh(tl, 0, "static const struct vrt_backend_probe %s = {\n", retval);
Fh(tl, 0, "\t.magic = VRT_BACKEND_PROBE_MAGIC,\n");
while (tl->t->tok != '}') {
@@ -237,6 +250,7 @@ vcc_ParseProbe(struct vcc *tl)
{
struct token *t_probe;
int i;
+ char *p;
vcc_NextToken(tl); /* ID: probe */
@@ -250,9 +264,11 @@ vcc_ParseProbe(struct vcc *tl)
vcc_ErrWhere(tl, t_probe);
}
- Fh(tl, 0, "\n#define vgc_probe_%.*s\tvgc_probe__%d\n",
- PF(t_probe), tl->nprobe);
- vcc_ParseProbeSpec(tl);
+ vcc_ParseProbeSpec(tl, t_probe, &p);
+ if (vcc_IdIs(t_probe, "default")) {
+ vcc_AddRef(tl, t_probe, SYM_PROBE);
+ tl->default_probe = p;
+ }
}
/*--------------------------------------------------------------------
@@ -271,6 +287,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
struct fld_spec *fs;
struct inifin *ifp;
struct vsb *vsb;
+ char *p;
unsigned u;
double t;
@@ -356,8 +373,8 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
SkipToken(tl, ';');
Fb(tl, 0, "\t.max_connections = %u,\n", u);
} else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') {
- Fb(tl, 0, "\t.probe = &vgc_probe__%d,\n", tl->nprobe);
- vcc_ParseProbeSpec(tl);
+ vcc_ParseProbeSpec(tl, NULL, &p);
+ Fb(tl, 0, "\t.probe = &%s,\n", p);
ERRCHK(tl);
} else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) {
Fb(tl, 0, "\t.probe = &vgc_probe_%.*s,\n", PF(tl->t));
@@ -444,7 +461,7 @@ vcc_ParseBackend(struct vcc *tl)
vcc_NextToken(tl);
sprintf(vgcname, "vgc_backend_%.*s", PF(t_be));
- Fh(tl, 0, "static struct director *%s;\n", vgcname);
+ Fh(tl, 0, "\nstatic struct director *%s;\n", vgcname);
sym = VCC_GetSymbolTok(tl, t_be, SYM_BACKEND);
AN(sym);
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 511f20e..36f813a 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -405,6 +405,8 @@ EmitStruct(const struct vcc *tl)
Fc(tl, 0, "\t.magic = VCL_CONF_MAGIC,\n");
Fc(tl, 0, "\t.event_vcl = VGC_Event,\n");
Fc(tl, 0, "\t.default_director = &%s,\n", tl->default_director);
+ if (tl->default_probe != NULL)
+ Fc(tl, 0, "\t.default_probe = &%s,\n", tl->default_probe);
Fc(tl, 0, "\t.ref = VGC_ref,\n");
Fc(tl, 0, "\t.nref = VGC_NREFS,\n");
Fc(tl, 0, "\t.nsrc = VGC_NSRCS,\n");
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index a222b9b..86f731d 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -198,6 +198,7 @@ struct vcc {
const char *default_director;
struct token *t_default_director;
+ const char *default_probe;
unsigned unique;
More information about the varnish-commit
mailing list