[4.1] 88e4ad9 Simplify `vcl.use` by making it failsafe

Lasse Karstensen lkarsten at varnish-software.com
Fri Jan 22 16:46:58 CET 2016


commit 88e4ad90a3a3312aa260f22cdd5f17e6ba376db0
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Dec 7 15:02:13 2015 +0100

    Simplify `vcl.use` by making it failsafe
    
    By the time we decide to switch to a VCL, it must be warm and usable.
    The deprecated VCL_EVENT_USE should not get in the way.

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 45d3e8b..e10f0c8 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -435,11 +435,8 @@ vcl_setup_event(VRT_CTX, enum vcl_event_e ev)
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(ctx->handling);
 	AN(ctx->vcl);
-	assert(ev == VCL_EVENT_LOAD || ev == VCL_EVENT_WARM ||
-	    ev == VCL_EVENT_USE);
-
-	if (ev != VCL_EVENT_USE)
-		AN(ctx->msg);
+	AN(ctx->msg);
+	assert(ev == VCL_EVENT_LOAD || ev == VCL_EVENT_WARM);
 
 	return (ctx->vcl->conf->event_vcl(ctx, ev));
 }
@@ -451,10 +448,11 @@ vcl_failsafe_event(VRT_CTX, enum vcl_event_e ev)
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(ctx->handling);
 	AN(ctx->vcl);
-	assert(ev == VCL_EVENT_COLD || ev == VCL_EVENT_DISCARD);
+	assert(ev == VCL_EVENT_COLD || ev == VCL_EVENT_DISCARD ||
+	    ev == VCL_EVENT_USE);
 
 	if (ctx->vcl->conf->event_vcl(ctx, ev) != 0)
-		WRONG("A VMOD cannot fail COLD or DISCARD events");
+		WRONG("A VMOD cannot fail USE, COLD or DISCARD events");
 }
 
 static int
@@ -738,33 +736,20 @@ ccf_config_use(struct cli *cli, const char * const *av, void *priv)
 	struct vcl *vcl;
 	struct vrt_ctx ctx;
 	unsigned hand = 0;
-	struct vsb *vsb;
-	int i;
 
 	ASSERT_CLI();
+	AN(cli);
 	AZ(priv);
 	vcl = vcl_find(av[2]);
 	AN(vcl);				// MGT ensures this
 	assert(vcl->temp == VCL_TEMP_WARM);	// MGT ensures this
 	INIT_OBJ(&ctx, VRT_CTX_MAGIC);
 	ctx.handling = &hand;
-	vsb = VSB_new_auto();
-	AN(vsb);
-	ctx.msg = vsb;
 	ctx.vcl = vcl;
-	i = vcl_setup_event(&ctx, VCL_EVENT_USE);
-	AZ(VSB_finish(vsb));
-	if (i) {
-		VCLI_Out(cli, "VCL \"%s\" Failed to activate", av[2]);
-		if (VSB_len(vsb) > 0)
-			VCLI_Out(cli, "\nMessage:\n\t%s", VSB_data(vsb));
-		VCLI_SetResult(cli, CLIS_CANT);
-	} else {
-		Lck_Lock(&vcl_mtx);
-		vcl_active = vcl;
-		Lck_Unlock(&vcl_mtx);
-	}
-	VSB_delete(vsb);
+	vcl_failsafe_event(&ctx, VCL_EVENT_USE);
+	Lck_Lock(&vcl_mtx);
+	vcl_active = vcl;
+	Lck_Unlock(&vcl_mtx);
 }
 
 static void __match_proto__(cli_func_t)
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index da6d8b4..cc22496 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -326,7 +326,8 @@ EmitCoordinates(const struct vcc *tl, struct vsb *vsb)
  * Init/Fini/Event
  *
  * We call DISCARD and COLD events in the opposite order of LOAD and
- * WARM.
+ * WARM. The child will panic if a USE event fails, since a WARM event
+ * leads to a usable state.
  */
 
 static void
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index a9e2cde..9485268 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -278,6 +278,7 @@ event_warm(VRT_CTX)
 
 	VSL(SLT_Debug, 0, "%s: VCL_EVENT_WARM", VCL_Name(ctx->vcl));
 
+	AN(ctx->msg);
 	if (cache_param->max_esi_depth == 42) {
 		VSB_printf(ctx->msg, "max_esi_depth is not the answer.");
 		return (-1);



More information about the varnish-commit mailing list