[master] dd45b5496 The vsc and vsc_seg variables are global to the VMOD, rather than per-VCL, so cleanup should only happen on the last discard event.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Feb 22 10:06:06 UTC 2019
commit dd45b5496ccbb95136e47d327c29c2accae34563
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Feb 22 10:02:58 2019 +0000
The vsc and vsc_seg variables are global to the VMOD, rather than
per-VCL, so cleanup should only happen on the last discard event.
This brought confusion to #2576, and while that ticket is probably
easier to debug if the counters were per-vcl, I think it is important
to keep the "per-vmod" behaviour around as an example.
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index c62b3e85e..fa05142b6 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -56,6 +56,7 @@ static VCL_DURATION vcl_release_delay = 0.0;
static pthread_mutex_t vsc_mtx = PTHREAD_MUTEX_INITIALIZER;
static struct vsc_seg *vsc_seg = NULL;
static struct VSC_debug *vsc = NULL;
+static int loads;
/**********************************************************************/
@@ -284,6 +285,9 @@ event_load(VRT_CTX, struct vmod_priv *priv)
struct priv_vcl *priv_vcl;
AN(ctx->msg);
+
+ loads++;
+
if (cache_param->nuke_limit == 42) {
VSB_printf(ctx->msg, "nuke_limit is not the answer.");
return (-1);
@@ -370,19 +374,38 @@ event_cold(VRT_CTX, const struct vmod_priv *priv)
return (0);
}
+static int
+event_discard(VRT_CTX, void *priv)
+{
+
+ (void)priv;
+
+ VRT_RemoveVFP(ctx, &xyzzy_rot13);
+
+ if (--loads)
+ return(0);
+
+ /*
+ * The vsc and vsc_seg variables are not per-VCL, they are
+ * the same in all VCL's which import the same binary version
+ * of this VMOD, so we should only carry out cleanup on the
+ * last discard event.
+ */
+ if (vsc)
+ VSC_debug_Destroy(&vsc_seg);
+
+ return(0);
+}
+
int v_matchproto_(vmod_event_f)
xyzzy_event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
{
switch (e) {
- case VCL_EVENT_LOAD: return (event_load(ctx, priv));
- case VCL_EVENT_WARM: return (event_warm(ctx, priv));
- case VCL_EVENT_COLD: return (event_cold(ctx, priv));
- case VCL_EVENT_DISCARD:
- VRT_RemoveVFP(ctx, &xyzzy_rot13);
- if (vsc)
- VSC_debug_Destroy(&vsc_seg);
- return (0);
+ case VCL_EVENT_LOAD: return (event_load(ctx, priv));
+ case VCL_EVENT_WARM: return (event_warm(ctx, priv));
+ case VCL_EVENT_COLD: return (event_cold(ctx, priv));
+ case VCL_EVENT_DISCARD: return (event_discard(ctx, priv));
default: return (0);
}
}
More information about the varnish-commit
mailing list