Commit b38feaa8 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Track labels using the VCL dependencies (in MGR)

Also try to clarify CLIS_PARAM (= nonsensical parameter) from
CLIS_CANT (= params make sense, but you can't do that.)
parent 205ce3f5
...@@ -71,7 +71,6 @@ struct vclprog { ...@@ -71,7 +71,6 @@ struct vclprog {
unsigned warm; unsigned warm;
const char * state; const char * state;
double go_cold; double go_cold;
struct vclprog *label;
VTAILQ_HEAD(, vcldep) dfrom; VTAILQ_HEAD(, vcldep) dfrom;
VTAILQ_HEAD(, vcldep) dto; VTAILQ_HEAD(, vcldep) dto;
}; };
...@@ -149,7 +148,7 @@ mcf_find_no_vcl(struct cli *cli, const char *name) ...@@ -149,7 +148,7 @@ mcf_find_no_vcl(struct cli *cli, const char *name)
} }
static int static int
mcf_is_label(struct vclprog *vp) mcf_is_label(const struct vclprog *vp)
{ {
return (!strcmp(vp->state, VCL_STATE_LABEL)); return (!strcmp(vp->state, VCL_STATE_LABEL));
} }
...@@ -265,7 +264,7 @@ mgt_vcl_setstate(struct cli *cli, struct vclprog *vp, const char *vs) ...@@ -265,7 +264,7 @@ mgt_vcl_setstate(struct cli *cli, struct vclprog *vp, const char *vs)
char *p; char *p;
int i; int i;
if (vp == active_vcl || vp->label != NULL) { if (vp == active_vcl || mcf_is_label(vp)) {
AN(vp->warm); AN(vp->warm);
return (0); return (0);
} }
...@@ -400,6 +399,7 @@ int ...@@ -400,6 +399,7 @@ int
mgt_push_vcls_and_start(struct cli *cli, unsigned *status, char **p) mgt_push_vcls_and_start(struct cli *cli, unsigned *status, char **p)
{ {
struct vclprog *vp; struct vclprog *vp;
struct vcldep *vd;
AN(active_vcl); AN(active_vcl);
...@@ -420,8 +420,10 @@ mgt_push_vcls_and_start(struct cli *cli, unsigned *status, char **p) ...@@ -420,8 +420,10 @@ mgt_push_vcls_and_start(struct cli *cli, unsigned *status, char **p)
VTAILQ_FOREACH(vp, &vclhead, list) { VTAILQ_FOREACH(vp, &vclhead, list) {
if (!mcf_is_label(vp)) if (!mcf_is_label(vp))
continue; continue;
vd = VTAILQ_FIRST(&vp->dfrom);
AN(vd);
if (mgt_cli_askchild(status, p, "vcl.label %s %s\n", if (mgt_cli_askchild(status, p, "vcl.label %s %s\n",
vp->name, vp->label->name)) vp->name, vd->to->name))
return (1); return (1);
free(*p); free(*p);
*p = NULL; *p = NULL;
...@@ -490,8 +492,8 @@ mcf_vcl_state(struct cli *cli, const char * const *av, void *priv) ...@@ -490,8 +492,8 @@ mcf_vcl_state(struct cli *cli, const char * const *av, void *priv)
VCLI_SetResult(cli, CLIS_PARAM); VCLI_SetResult(cli, CLIS_PARAM);
return; return;
} }
if (vp->label != NULL) { if (!VTAILQ_EMPTY(&vp->dto)) {
AZ(!strcmp(vp->state, "cold")); AN(strcmp(vp->state, "cold"));
if (!strcmp(av[3], "cold")) { if (!strcmp(av[3], "cold")) {
VCLI_Out(cli, "A labeled VCL cannot be set cold"); VCLI_Out(cli, "A labeled VCL cannot be set cold");
VCLI_SetResult(cli, CLIS_CANT); VCLI_SetResult(cli, CLIS_CANT);
...@@ -511,7 +513,7 @@ mcf_vcl_state(struct cli *cli, const char * const *av, void *priv) ...@@ -511,7 +513,7 @@ mcf_vcl_state(struct cli *cli, const char * const *av, void *priv)
} else if (!strcmp(av[3], VCL_STATE_COLD)) { } else if (!strcmp(av[3], VCL_STATE_COLD)) {
if (vp == active_vcl) { if (vp == active_vcl) {
VCLI_Out(cli, "Cannot set the active VCL cold."); VCLI_Out(cli, "Cannot set the active VCL cold.");
VCLI_SetResult(cli, CLIS_PARAM); VCLI_SetResult(cli, CLIS_CANT);
return; return;
} }
vp->state = VCL_STATE_AUTO; vp->state = VCL_STATE_AUTO;
...@@ -572,23 +574,19 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv) ...@@ -572,23 +574,19 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv)
if (vp == NULL) if (vp == NULL)
return; return;
if (vp == active_vcl) { if (vp == active_vcl) {
VCLI_SetResult(cli, CLIS_PARAM); VCLI_SetResult(cli, CLIS_CANT);
VCLI_Out(cli, "Cannot discard active VCL program\n"); VCLI_Out(cli, "Cannot discard active VCL program\n");
return; return;
} }
if (!VTAILQ_EMPTY(&vp->dto)) { if (!VTAILQ_EMPTY(&vp->dto)) {
if (vp->label != NULL && !mcf_is_label(vp)) { VCLI_SetResult(cli, CLIS_CANT);
AN(vp->warm); AN(vp->warm);
VCLI_SetResult(cli, CLIS_PARAM); if (!mcf_is_label(vp))
VCLI_Out(cli, "Cannot discard labeled VCL program.\n");
else
VCLI_Out(cli, VCLI_Out(cli,
"Cannot discard labeled (\"%s\") VCL program.\n", "Cannot discard this VCL label, "
vp->label->name); "other VCLs depend on it.\n");
return;
}
VCLI_SetResult(cli, CLIS_PARAM);
VCLI_Out(cli,
"Cannot discard \"%s\" VCL label, "
"other VCLs depend on it.\n", vp->name);
n = 0; n = 0;
VTAILQ_FOREACH(vd, &vp->dto, lto) { VTAILQ_FOREACH(vd, &vp->dto, lto) {
if (n++ == 5) { if (n++ == 5) {
...@@ -599,13 +597,10 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv) ...@@ -599,13 +597,10 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv)
} }
return; return;
} }
if (mcf_is_label(vp)) { if (mcf_is_label(vp))
AN(vp->warm); AN(vp->warm);
vp->label->label = NULL; else
vp->label = NULL;
} else {
(void)mgt_vcl_setstate(cli, vp, VCL_STATE_COLD); (void)mgt_vcl_setstate(cli, vp, VCL_STATE_COLD);
}
if (child_pid >= 0) { if (child_pid >= 0) {
/* XXX If this fails the child is crashing, figure that later */ /* XXX If this fails the child is crashing, figure that later */
(void)mgt_cli_askchild(&status, &p, "vcl.discard %s\n", av[2]); (void)mgt_cli_askchild(&status, &p, "vcl.discard %s\n", av[2]);
...@@ -614,6 +609,21 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv) ...@@ -614,6 +609,21 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv)
mgt_vcl_del(vp); mgt_vcl_del(vp);
} }
static void
mcf_list_labels(struct cli *cli, const struct vclprog *vp)
{
int n = 0;
struct vcldep *vd;
VTAILQ_FOREACH(vd, &vp->dto, lto) {
if (n++ == 5) {
VCLI_Out(cli, " [...]");
break;
}
VCLI_Out(cli, " %s", vd->from->name);
}
}
static void __match_proto__(cli_func_t) static void __match_proto__(cli_func_t)
mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) mcf_vcl_list(struct cli *cli, const char * const *av, void *priv)
{ {
...@@ -637,10 +647,7 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) ...@@ -637,10 +647,7 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv)
VCLI_Out(cli, "/%-8s", vp->warm ? VCLI_Out(cli, "/%-8s", vp->warm ?
VCL_STATE_WARM : VCL_STATE_COLD); VCL_STATE_WARM : VCL_STATE_COLD);
VCLI_Out(cli, " %6s %s", "", vp->name); VCLI_Out(cli, " %6s %s", "", vp->name);
if (vp->label != NULL) mcf_list_labels(cli, vp);
VCLI_Out(cli, " %s %s",
mcf_is_label(vp) ?
"->" : "<-", vp->label->name);
VCLI_Out(cli, "\n"); VCLI_Out(cli, "\n");
} }
} }
...@@ -664,14 +671,15 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv) ...@@ -664,14 +671,15 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv)
if (vpt == NULL) if (vpt == NULL)
return; return;
if (mcf_is_label(vpt)) { if (mcf_is_label(vpt)) {
VCLI_SetResult(cli, CLIS_PARAM); VCLI_SetResult(cli, CLIS_CANT);
VCLI_Out(cli, "VCL labels cannot point to labels"); VCLI_Out(cli, "VCL labels cannot point to labels");
return; return;
} }
if (vpt->label != NULL) { if (!VTAILQ_EMPTY(&vpt->dto)) {
VCLI_SetResult(cli, CLIS_PARAM); VCLI_SetResult(cli, CLIS_CANT);
VCLI_Out(cli, "VCL already labeled (\"%s\")", VCLI_Out(cli, "VCL already labeled with");
vpt->label->name); mcf_list_labels(cli, vpt);
VCLI_Out(cli, "\n");
return; return;
} }
vpl = mcf_vcl_byname(av[2]); vpl = mcf_vcl_byname(av[2]);
...@@ -681,11 +689,6 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv) ...@@ -681,11 +689,6 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv)
VCLI_Out(cli, "%s is not a label", vpl->name); VCLI_Out(cli, "%s is not a label", vpl->name);
return; return;
} }
AN(vpl->label);
assert(vpl->label->label == vpl);
/* XXX SET vp->label AUTO */
vpl->label->label = NULL;
vpl->label = NULL;
mgt_vcl_dep_del(VTAILQ_FIRST(&vpl->dfrom)); mgt_vcl_dep_del(VTAILQ_FIRST(&vpl->dfrom));
AN(VTAILQ_EMPTY(&vpl->dfrom)); AN(VTAILQ_EMPTY(&vpl->dfrom));
} else { } else {
...@@ -694,8 +697,6 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv) ...@@ -694,8 +697,6 @@ mcf_vcl_label(struct cli *cli, const char * const *av, void *priv)
AN(vpl); AN(vpl);
mgt_vcl_dep_add(vpl, vpt); mgt_vcl_dep_add(vpl, vpt);
vpl->warm = 1; vpl->warm = 1;
vpl->label = vpt;
vpt->label = vpl;
if (vpt->state == VCL_STATE_COLD) if (vpt->state == VCL_STATE_COLD)
vpt->state = VCL_STATE_AUTO; vpt->state = VCL_STATE_AUTO;
(void)mgt_vcl_setstate(cli, vpt, VCL_STATE_WARM); (void)mgt_vcl_setstate(cli, vpt, VCL_STATE_WARM);
......
...@@ -16,7 +16,7 @@ varnish v1 -cliok start ...@@ -16,7 +16,7 @@ varnish v1 -cliok start
varnish v1 -cliok "vcl.use vcl1" varnish v1 -cliok "vcl.use vcl1"
varnish v1 -clierr 106 "vcl.discard vcl1" varnish v1 -clierr 300 "vcl.discard vcl1"
varnish v1 -clierr 106 "vcl.discard vcl0" varnish v1 -clierr 106 "vcl.discard vcl0"
......
...@@ -58,4 +58,4 @@ varnish v1 -clierr 106 "vcl.show -x nowhere" ...@@ -58,4 +58,4 @@ varnish v1 -clierr 106 "vcl.show -x nowhere"
varnish v1 -clierr 106 "vcl.show nothere" varnish v1 -clierr 106 "vcl.show nothere"
varnish v1 -clierr 106 "vcl.use nothere" varnish v1 -clierr 106 "vcl.use nothere"
varnish v1 -clierr 106 "vcl.discard nowhere" varnish v1 -clierr 106 "vcl.discard nowhere"
varnish v1 -clierr 106 "vcl.discard vcl1" varnish v1 -clierr 300 "vcl.discard vcl1"
...@@ -37,7 +37,7 @@ client c1 { ...@@ -37,7 +37,7 @@ client c1 {
expect resp.http.vcl == vclA expect resp.http.vcl == vclA
} -run } -run
varnish v1 -clierr 106 "vcl.discard vcl1" varnish v1 -clierr 300 "vcl.discard vcl1"
varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclB)); } } varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclB)); } }
...@@ -54,7 +54,7 @@ varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } } ...@@ -54,7 +54,7 @@ varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } }
varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } } varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } }
varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } } varnish v1 -vcl+backend { sub vcl_recv { return (vcl(vclA)); } }
varnish v1 -clierr 106 "vcl.discard vclA" varnish v1 -clierr 300 "vcl.discard vclA"
varnish v1 -vcl+backend { } varnish v1 -vcl+backend { }
varnish v1 -cliok "vcl.discard vcl3" varnish v1 -cliok "vcl.discard vcl3"
......
...@@ -63,7 +63,7 @@ varnish v1 -expect VBE.vcl1.default.happy >= 0 ...@@ -63,7 +63,7 @@ varnish v1 -expect VBE.vcl1.default.happy >= 0
varnish v1 -expect VBE.vcl2.default.happy >= 0 varnish v1 -expect VBE.vcl2.default.happy >= 0
# You can't freeze the active VCL # You can't freeze the active VCL
varnish v1 -clierr 106 "vcl.state vcl2 cold" varnish v1 -clierr 300 "vcl.state vcl2 cold"
# However a warm event is guaranteed... # However a warm event is guaranteed...
logexpect l1 -v v1 -g raw { logexpect l1 -v v1 -g raw {
......
...@@ -37,16 +37,16 @@ client c1 { ...@@ -37,16 +37,16 @@ client c1 {
varnish v1 -cliok "vcl.list" varnish v1 -cliok "vcl.list"
varnish v1 -clierr 106 "vcl.label foo vcl0" varnish v1 -clierr 106 "vcl.label foo vcl0"
varnish v1 -cliok "vcl.label foo vcl2" varnish v1 -cliok "vcl.label foo vcl2"
varnish v1 -clierr 106 "vcl.label bar vcl2" varnish v1 -clierr 300 "vcl.label bar vcl2"
varnish v1 -clierr 106 "vcl.discard vcl2" varnish v1 -clierr 300 "vcl.discard vcl2"
varnish v1 -cliok "vcl.label foo vcl1" varnish v1 -cliok "vcl.label foo vcl1"
varnish v1 -clierr 106 "vcl.label vcl1 vcl2" varnish v1 -clierr 106 "vcl.label vcl1 vcl2"
varnish v1 -clierr 106 "vcl.state foo cold" varnish v1 -clierr 106 "vcl.state foo cold"
varnish v1 -clierr 106 "vcl.label bar foo" varnish v1 -clierr 300 "vcl.label bar foo"
varnish v1 -clierr 106 "vcl.discard vcl1" varnish v1 -clierr 300 "vcl.discard vcl1"
varnish v1 -cliok "vcl.list" varnish v1 -cliok "vcl.list"
varnish v1 -cliok "vcl.use foo" varnish v1 -cliok "vcl.use foo"
varnish v1 -clierr 106 "vcl.discard foo" varnish v1 -clierr 300 "vcl.discard foo"
varnish v1 -cliok "vcl.list" varnish v1 -cliok "vcl.list"
client c1 -run client c1 -run
...@@ -75,14 +75,14 @@ varnish v1 -stop ...@@ -75,14 +75,14 @@ varnish v1 -stop
varnish v1 -cliok "vcl.list" varnish v1 -cliok "vcl.list"
varnish v1 -clierr 106 "vcl.label foo vcl0" varnish v1 -clierr 106 "vcl.label foo vcl0"
varnish v1 -cliok "vcl.label foo vcl1" varnish v1 -cliok "vcl.label foo vcl1"
varnish v1 -clierr 106 "vcl.label bar foo" varnish v1 -clierr 300 "vcl.label bar foo"
varnish v1 -clierr 200 "vcl.state vcl1 warm" varnish v1 -clierr 200 "vcl.state vcl1 warm"
varnish v1 -clierr 200 "vcl.state vcl1 auto" varnish v1 -clierr 200 "vcl.state vcl1 auto"
varnish v1 -clierr 300 "vcl.state vcl1 cold" varnish v1 -clierr 300 "vcl.state vcl1 cold"
varnish v1 -clierr 106 "vcl.discard vcl1" varnish v1 -clierr 300 "vcl.discard vcl1"
varnish v1 -cliok "vcl.list" varnish v1 -cliok "vcl.list"
varnish v1 -cliok "vcl.use foo" varnish v1 -cliok "vcl.use foo"
varnish v1 -clierr 106 "vcl.discard foo" varnish v1 -clierr 300 "vcl.discard foo"
varnish v1 -cliok "vcl.list" varnish v1 -cliok "vcl.list"
server s1 -start server s1 -start
......
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