Permalink
Browse files

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

  • Loading branch information...
1 parent 6cd97d1 commit 19ff7a5986568164a9d17c67f0723bfa233ffbce @bsdphk bsdphk committed Jan 10, 2017
Showing with 37 additions and 12 deletions.
  1. +26 −6 bin/varnishd/cache/cache_vcl.c
  2. +6 −4 bin/varnishd/mgt/mgt_vcl.c
  3. +2 −1 include/vrt.h
  4. +3 −1 lib/libvcc/vcc_action.c
@@ -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,16 +522,30 @@ 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)
{
struct req *req = ctx->req;
@@ -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");
}
View
@@ -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));

0 comments on commit 19ff7a5

Please sign in to comment.