[master] 8e58c80 Add vcl_init() and vcl_fini() methods which are called when a VCL after a vcl file is loaded and before it is discarded.
Poul-Henning Kamp
phk at varnish-cache.org
Tue May 17 20:36:06 CEST 2011
commit 8e58c809758ad572eb16998b3c984ba6b996bd66
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue May 17 18:34:46 2011 +0000
Add vcl_init() and vcl_fini() methods which are called when a VCL
after a vcl file is loaded and before it is discarded.
The major use will probably be to tell VMODs things like filenames.
Requested by: geoff & DocWilco
diff --git a/bin/varnishd/cache_vcl.c b/bin/varnishd/cache_vcl.c
index 0b25346..d2f74fc 100644
--- a/bin/varnishd/cache_vcl.c
+++ b/bin/varnishd/cache_vcl.c
@@ -172,12 +172,13 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
}
REPLACE(vcl->name, name);
VTAILQ_INSERT_TAIL(&vcl_head, vcl, list);
+ cli_out(cli, "Loaded \"%s\" as \"%s\"", fn , name);
+ vcl->conf->init_vcl(cli);
+ (void)vcl->conf->init_func(NULL);
Lck_Lock(&vcl_mtx);
if (vcl_active == NULL)
vcl_active = vcl;
Lck_Unlock(&vcl_mtx);
- cli_out(cli, "Loaded \"%s\" as \"%s\"", fn , name);
- vcl->conf->init_func(cli);
VSC_main->n_vcl++;
VSC_main->n_vcl_avail++;
return (0);
@@ -197,7 +198,8 @@ VCL_Nuke(struct vcls *vcl)
assert(vcl->conf->discard);
assert(vcl->conf->busy == 0);
VTAILQ_REMOVE(&vcl_head, vcl, list);
- vcl->conf->fini_func(NULL);
+ (void)vcl->conf->fini_func(NULL);
+ vcl->conf->fini_vcl(NULL);
free(vcl->name);
(void)dlclose(vcl->dlh);
FREE_OBJ(vcl);
diff --git a/bin/varnishd/cache_vrt.c b/bin/varnishd/cache_vrt.c
index 0d66435..4cb9e9c 100644
--- a/bin/varnishd/cache_vrt.c
+++ b/bin/varnishd/cache_vrt.c
@@ -71,6 +71,8 @@ void
VRT_count(const struct sess *sp, unsigned u)
{
+ if (sp == NULL)
+ return;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (params->vcl_trace)
WSP(sp, SLT_VCL_trace, "%u %d.%d", u,
@@ -240,6 +242,10 @@ void
VRT_handling(struct sess *sp, unsigned hand)
{
+ if (sp == NULL) {
+ assert(hand == VCL_RET_OK);
+ return;
+ }
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
assert(hand < VCL_RET_MAX);
sp->handling = hand;
diff --git a/bin/varnishd/default.vcl b/bin/varnishd/default.vcl
index 3681ffe..59ed706 100644
--- a/bin/varnishd/default.vcl
+++ b/bin/varnishd/default.vcl
@@ -139,3 +139,11 @@ sub vcl_error {
"};
return (deliver);
}
+
+sub vcl_init {
+ return (ok);
+}
+
+sub vcl_fini {
+ return (ok);
+}
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index c5cdb07..1806416 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -166,17 +166,22 @@ vsb_newbuf(struct vsb *s, char *buf, int length, int flags)
{
memset(s, 0, sizeof(*s));
- s->s_flags = flags;
s->s_magic = VSB_MAGIC;
+ s->s_flags = flags;
+ s->s_size = length;
+ s->s_buf = buf;
- if (buf != NULL) {
- s->s_size = length;
- s->s_buf = buf;
- return (s);
+ if ((s->s_flags & VSB_AUTOEXTEND) == 0) {
+ KASSERT(s->s_size > 1,
+ ("attempt to create a too small vsb"));
}
- s->s_size = length;
+
+ if (s->s_buf != NULL)
+ return (s);
+
if ((flags & VSB_AUTOEXTEND) != 0)
s->s_size = vsb_extendsize(s->s_size);
+
s->s_buf = SBMALLOC(s->s_size);
if (s->s_buf == NULL)
return (NULL);
@@ -243,7 +248,7 @@ vsb_setpos(struct vsb *s, ssize_t pos)
("attempt to seek to a negative position (%jd)", (intmax_t)pos));
KASSERT(pos < s->s_size,
("attempt to seek past end of vsb (%jd >= %jd)",
- (intmax_t)pos, (intmax_t)->s_size));
+ (intmax_t)pos, (intmax_t)s->s_size));
if (pos < 0 || pos > s->s_len)
return (-1);
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 904fea1..15c1a51 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -92,6 +92,8 @@ returns =(
('fetch', ('error', 'restart', 'hit_for_pass', 'deliver',)),
('deliver', ('restart', 'deliver',)),
('error', ('restart', 'deliver',)),
+ ('init', ('ok',)),
+ ('fini', ('ok',)),
)
#######################################################################
@@ -750,8 +752,8 @@ struct VCL_conf {
const char **srcname;
const char **srcbody;
- vcl_init_f *init_func;
- vcl_fini_f *fini_func;
+ vcl_init_f *init_vcl;
+ vcl_fini_f *fini_vcl;
""")
for i in returns:
diff --git a/lib/libvcl/vcc_compile.c b/lib/libvcl/vcc_compile.c
index 823b2a6..e9f85b9 100644
--- a/lib/libvcl/vcc_compile.c
+++ b/lib/libvcl/vcc_compile.c
@@ -366,8 +366,8 @@ EmitStruct(const struct vcc *tl)
Fc(tl, 0, "\nconst struct VCL_conf VCL_conf = {\n");
Fc(tl, 0, "\t.magic = VCL_CONF_MAGIC,\n");
- Fc(tl, 0, "\t.init_func = VGC_Init,\n");
- Fc(tl, 0, "\t.fini_func = VGC_Fini,\n");
+ Fc(tl, 0, "\t.init_vcl = VGC_Init,\n");
+ Fc(tl, 0, "\t.fini_vcl = VGC_Fini,\n");
Fc(tl, 0, "\t.ndirector = %d,\n", tl->ndirector);
Fc(tl, 0, "\t.director = directors,\n");
Fc(tl, 0, "\t.ref = VGC_ref,\n");
More information about the varnish-commit
mailing list