Commit 19ff7a59 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Keep track of and report how many return(vcl)'s hold a label

parent 6cd97d11
......@@ -72,6 +72,7 @@ struct vcl {
pthread_rwlock_t temp_rwl;
VTAILQ_HEAD(,backend) backend_list;
VTAILQ_HEAD(,vclref) ref_list;
int nrefs;
struct vcl *label;
int nlabels;
};
......@@ -521,15 +522,29 @@ VRT_count(VRT_CTX, unsigned u)
}
VCL_VCL
VRT_vcl_lookup(const char *name)
VRT_vcl_get(VRT_CTX, const char *name)
{
VCL_VCL vcl;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
vcl = vcl_find(name);
AN(vcl);
Lck_Lock(&vcl_mtx);
vcl->nrefs++;
Lck_Unlock(&vcl_mtx);
return (vcl);
}
void
VRT_vcl_rel(VRT_CTX, VCL_VCL vcl)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(vcl);
Lck_Lock(&vcl_mtx);
vcl->nrefs--;
Lck_Unlock(&vcl_mtx);
}
void
VRT_vcl_select(VRT_CTX, VCL_VCL vcl)
{
......@@ -564,6 +579,7 @@ VRT_ref_vcl(VRT_CTX, const char *desc)
Lck_Lock(&vcl_mtx);
VTAILQ_INSERT_TAIL(&vcl->ref_list, ref, list);
vcl->nrefs++;
Lck_Unlock(&vcl_mtx);
return (ref);
......@@ -595,6 +611,7 @@ VRT_rel_vcl(VRT_CTX, struct vclref **refp)
Lck_Lock(&vcl_mtx);
assert(!VTAILQ_EMPTY(&vcl->ref_list));
VTAILQ_REMOVE(&vcl->ref_list, ref, list);
vcl->nrefs--;
/* No garbage collection here, for the same reasons as in VCL_Rel. */
Lck_Unlock(&vcl_mtx);
......@@ -812,12 +829,15 @@ vcl_cli_list(struct cli *cli, const char * const *av, void *priv)
flg = "available";
VCLI_Out(cli, "%-10s %5s/%-8s %6u %s",
flg, vcl->state, vcl->temp, vcl->busy, vcl->loaded_name);
if (vcl->label != NULL)
if (vcl->label != NULL) {
VCLI_Out(cli, " -> %s", vcl->label->loaded_name);
else if (vcl->nlabels > 1)
VCLI_Out(cli, " (%d labels)", vcl->nlabels);
else if (vcl->nlabels > 0)
VCLI_Out(cli, " (%d label)", vcl->nlabels);
if (vcl->nrefs)
VCLI_Out(cli, " (%d return(vcl)%s)",
vcl->nrefs, vcl->nrefs > 1 ? "'s" : "");
} else if (vcl->nlabels > 0) {
VCLI_Out(cli, " (%d label%s)",
vcl->nlabels, vcl->nlabels > 1 ? "s" : "");
}
VCLI_Out(cli, "\n");
}
}
......
......@@ -643,15 +643,17 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv)
vp->state);
VCLI_Out(cli, "/%-8s", vp->warm ?
VCL_STATE_WARM : VCL_STATE_COLD);
VCLI_Out(cli, " %6s %s", "", vp->name);
VCLI_Out(cli, " %6s %s", "-", vp->name);
if (mcf_is_label(vp)) {
vd = VTAILQ_FIRST(&vp->dfrom);
AN(vd);
VCLI_Out(cli, " -> %s", vd->to->name);
} else if (vp->nto > 1) {
VCLI_Out(cli, " (%d labels)", vp->nto);
if (vp->nto > 0)
VCLI_Out(cli, " (%d return(vcl)%s)",
vp->nto, vp->nto > 1 ? "'s" : "");
} else if (vp->nto > 0) {
VCLI_Out(cli, " (%d label)", vp->nto);
VCLI_Out(cli, " (%d label%s)",
vp->nto, vp->nto > 1 ? "s" : "");
}
VCLI_Out(cli, "\n");
}
......
......@@ -319,7 +319,8 @@ int VRT_Vmod_Init(VRT_CTX, struct vmod **hdl, void *ptr, int len,
void VRT_Vmod_Fini(struct vmod **hdl);
/* VCL program related */
VCL_VCL VRT_vcl_lookup(const char *);
VCL_VCL VRT_vcl_get(VRT_CTX, const char *);
void VRT_vcl_rel(VRT_CTX, VCL_VCL);
void VRT_vcl_select(VRT_CTX, VCL_VCL);
struct vmod_priv;
......
......@@ -264,8 +264,10 @@ parse_return_vcl(struct vcc *tl)
p = New_IniFin(tl);
AN(p);
VSB_printf(p->ini, "\t%s = VRT_vcl_lookup(\"%.*s\");",
VSB_printf(p->ini, "\t%s = VRT_vcl_get(ctx, \"%.*s\");",
buf, PF(tl->t));
VSB_printf(p->fin, "\tVRT_vcl_rel(ctx, %s);",
buf);
}
Fb(tl, 1, "VRT_vcl_select(ctx, %s);\t/* %.*s */\n",
(const char*)sym->eval_priv, PF(tl->t));
......
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