Commit 81655e53 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent 18265396
......@@ -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)
......
......@@ -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
......
......@@ -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);
......
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