Skip to content

Commit

Permalink
Keep track of and report how many return(vcl)'s hold a label
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Jan 10, 2017
1 parent 6cd97d1 commit 19ff7a5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
32 changes: 26 additions & 6 deletions bin/varnishd/cache/cache_vcl.c
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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");
}
}
Expand Down
10 changes: 6 additions & 4 deletions bin/varnishd/mgt/mgt_vcl.c
Expand Up @@ -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");
}
Expand Down
3 changes: 2 additions & 1 deletion include/vrt.h
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/libvcc/vcc_action.c
Expand Up @@ -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));
Expand Down

0 comments on commit 19ff7a5

Please sign in to comment.