[master] 93b6da1 Introduce the VCL_EVENT_ACTIVATE which is posted before vcl.use takes effect. Use this to move backend probes as appropriate.

Poul-Henning Kamp phk at FreeBSD.org
Mon Jan 19 14:53:54 CET 2015


commit 93b6da19abbb9cdf5973b4f64005a9f7941a23f6
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jan 19 13:53:17 2015 +0000

    Introduce the VCL_EVENT_ACTIVATE which is posted before vcl.use
    takes effect.  Use this to move backend probes as appropriate.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 4f8834d..2c85d29 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -83,25 +83,6 @@ VBE_Healthy(const struct backend *backend, double *changed)
 }
 
 /*--------------------------------------------------------------------
- *
- */
-
-void
-VBE_UseHealth(const struct director *vdi)
-{
-	struct vbe_dir *vs;
-
-	ASSERT_CLI();
-
-	if (strcmp(vdi->name, "simple"))
-		return;
-	CAST_OBJ_NOTNULL(vs, vdi->priv, VDI_SIMPLE_MAGIC);
-	if (vs->vrt->probe == NULL)
-		return;
-	VBP_Use(vs->backend, vs->vrt->probe);
-}
-
-/*--------------------------------------------------------------------
  * Get a connection to the backend
  */
 
@@ -291,38 +272,14 @@ vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo)
 /*--------------------------------------------------------------------*/
 
 void
-VRT_fini_vbe(VRT_CTX, struct director **dp, const struct vrt_backend *vrt)
+VRT_init_vbe(VRT_CTX, struct director **dp, const struct vrt_backend *vrt)
 {
 	struct vbe_dir *vs;
-	struct director *d;
 
 	ASSERT_CLI();
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(dp);
-	(void)vrt;
-
-	d = *dp;
-	*dp = NULL;
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
-
-	if (vs->vrt->probe != NULL)
-		VBP_Remove(vs->backend, vs->vrt->probe);
-
-	VBE_DropRefVcl(vs->backend);
-	free(vs->dir.vcl_name);
-	vs->dir.magic = 0;
-	FREE_OBJ(vs);
-}
-
-
-void
-VRT_init_vbe(VRT_CTX, struct director **bp, const struct vrt_backend *vrt)
-{
-	struct vbe_dir *vs;
-
-	ASSERT_CLI();
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	AZ(*dp);
 
 	ALLOC_OBJ(vs, VDI_SIMPLE_MAGIC);
 	XXXAN(vs);
@@ -340,7 +297,48 @@ VRT_init_vbe(VRT_CTX, struct director **bp, const struct vrt_backend *vrt)
 
 	vs->backend = VBE_AddBackend(NULL, vrt);
 	if (vs->vrt->probe != NULL)
-		VBP_Insert(vs->backend, vs->vrt->probe, vs->vrt->hosthdr);
+		VBP_Insert(vs->backend, vrt->probe, vrt->hosthdr);
 
-	* bp = &vs->dir;
+	*dp = &vs->dir;
+}
+
+void
+VRT_use_vbe(VRT_CTX, const struct director *d, const struct vrt_backend *vrt)
+{
+	struct vbe_dir *vs;
+
+	ASSERT_CLI();
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+
+	if (vrt->probe == NULL)
+		return;
+
+	CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
+
+	VBP_Use(vs->backend, vrt->probe);
+}
+
+void
+VRT_fini_vbe(VRT_CTX, struct director **dp, const struct vrt_backend *vrt)
+{
+	struct vbe_dir *vs;
+	struct director *d;
+
+	ASSERT_CLI();
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	AN(dp);
+
+	d = *dp;
+	*dp = NULL;
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+	CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
+
+	if (vs->vrt->probe != NULL)
+		VBP_Remove(vs->backend, vrt->probe);
+
+	VBE_DropRefVcl(vs->backend);
+	free(vs->dir.vcl_name);
+	vs->dir.magic = 0;
+	FREE_OBJ(vs);
 }
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index 32f3b8d..26955a6 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -96,9 +96,6 @@ struct vbc {
 	struct backend		*backend;
 };
 
-/* cache_backend.c */
-void VBE_UseHealth(const struct director *vdi);
-
 /* cache_backend_cfg.c */
 void VBE_DropRefConn(struct backend *, const struct acct_bereq *);
 void VBE_DropRefVcl(struct backend *);
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 08f996b..d74e9b0 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -360,7 +360,8 @@ static void
 ccf_config_use(struct cli *cli, const char * const *av, void *priv)
 {
 	struct vcls *vcl;
-	int i;
+	struct vrt_ctx ctx;
+	unsigned hand = 0;
 
 	(void)av;
 	(void)priv;
@@ -370,13 +371,19 @@ ccf_config_use(struct cli *cli, const char * const *av, void *priv)
 		VCLI_SetResult(cli, CLIS_PARAM);
 		return;
 	}
+
+	INIT_OBJ(&ctx, VRT_CTX_MAGIC);
+	ctx.handling = &hand;
+	ctx.cli = cli;
+	if (vcl->conf->event_vcl(&ctx, VCL_EVENT_ACTIVATE)) {
+		VCLI_Out(cli, "VCL \"%s\" Failed to activate", av[2]);
+		VCLI_SetResult(cli, CLIS_CANT);
+		return;
+	}
+
 	Lck_Lock(&vcl_mtx);
 	vcl_active = vcl;
 	Lck_Unlock(&vcl_mtx);
-
-	/* Tickle this VCL's backends to take over health polling */
-	for(i = 1; i < vcl->conf->ndirector; i++)
-		VBE_UseHealth(vcl->conf->director[i]);
 }
 
 static void
diff --git a/include/vrt.h b/include/vrt.h
index 09e2b52..c30696a 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -226,6 +226,7 @@ void VRT_synth_page(VRT_CTX, const char *, ...);
 
 /* Backend related */
 void VRT_init_vbe(VRT_CTX, struct director **, const struct vrt_backend *);
+void VRT_use_vbe(VRT_CTX, const struct director *, const struct vrt_backend *);
 void VRT_fini_vbe(VRT_CTX, struct director **, const struct vrt_backend *);
 
 /* Suckaddr related */
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index ea26bf2..aafcfc0 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -947,6 +947,7 @@ struct worker;
 
 enum vcl_event_e {
 	VCL_EVENT_INIT,
+	VCL_EVENT_ACTIVATE,
 	VCL_EVENT_FINI,
 };
 
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 66feb7e..f6026ef 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -428,6 +428,10 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be)
 	VSB_printf(ifp->fin,
 	    "\tVRT_fini_vbe(ctx, &VGCDIR(%s), &vgc_dir_priv_%s);",
 	    vgcname, vgcname);
+	VSB_printf(ifp->event,
+	    "\tif (ev == VCL_EVENT_ACTIVATE)\n"
+	    "\t\tVRT_use_vbe(ctx, VGCDIR(%s), &vgc_dir_priv_%s);",
+	    vgcname, vgcname);
 	tl->ndirector++;
 }
 
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 32dc8f2..4ebe707 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -346,17 +346,16 @@ EmitInitFini(const struct vcc *tl)
 	Fc(tl, 0, "{\n");
 	Fc(tl, 0, "\tif (ev == VCL_EVENT_INIT)\n");
 	Fc(tl, 0, "\t\treturn(VGC_Init(ctx));\n");
-	Fc(tl, 0, "\telse if (ev == VCL_EVENT_FINI)\n");
+	Fc(tl, 0, "\tif (ev == VCL_EVENT_FINI)\n");
 	Fc(tl, 0, "\t\treturn(VGC_Fini(ctx));\n");
-	Fc(tl, 0, "\telse {\n");
+	Fc(tl, 0, "\t\n");
 	VTAILQ_FOREACH(p, &tl->inifin, list) {
 		AZ(VSB_finish(p->event));
 		if (VSB_len(p->event))
 			Fc(tl, 0, "\t/* %u */\n%s\n", p->n, VSB_data(p->event));
 		VSB_delete(p->event);
 	}
-	Fc(tl, 0, "\t\treturn (0);\n");
-	Fc(tl, 0, "\t}\n");
+	Fc(tl, 0, "\treturn (0);\n");
 	Fc(tl, 0, "}\n");
 }
 



More information about the varnish-commit mailing list