[master] 804014ada Add a debug VDP to be pendantic about VDP_END

Nils Goroll nils.goroll at uplex.de
Fri Oct 9 08:38:06 UTC 2020


commit 804014ada87886d08a22ae3ba101887e2baaed51
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Oct 8 16:18:46 2020 +0200

    Add a debug VDP to be pendantic about VDP_END
    
    the sole purpose is to ensure that we send a VDP_END.
    
    Later, we might consider to arm the assertion in VDP_Close(). At this
    point, a couple of VTCs fail. We would need to at least improve error
    handling.

diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index 04b57936e..79234e9f3 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -157,6 +157,11 @@ VDP_Close(struct req *req)
 			VTAILQ_REMOVE(&vdc->vdp, vdpe, list);
 		}
 		vdc->nxt = VTAILQ_FIRST(&vdc->vdp);
+#ifdef VDP_PEDANTIC_ARMED
+		// enable when we are confident to get VDP_END right
+		if (vdc->nxt == NULL && vdc->retval >= 0)
+			assert(vdpe->end == VDP_END);
+#endif
 	}
 	return (rv);
 }
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index e301c6291..40ecc13ca 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -166,6 +166,41 @@ static const struct vdp xyzzy_vdp_rot13 = {
 	.fini  = xyzzy_rot13_fini,
 };
 
+/**********************************************************************
+ * assert that we see a VDP_END
+ *
+ * note:
+ * we could lookup our own vdpe in _fini and check for vdpe->end == VDP_END
+ * yet that would cross the API
+ */
+
+void * end_marker = &end_marker;
+
+static int v_matchproto_(vdp_bytes_f)
+xyzzy_pedantic_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
+    const void *ptr, ssize_t len)
+{
+	AZ(*priv);
+	if (act == VDP_END)
+		*priv = end_marker;
+	return (VDP_bytes(vdx, act, ptr, len));
+}
+
+static int v_matchproto_(vdp_fini_f)
+xyzzy_pedantic_fini(struct req *req, void **priv)
+{
+	(void) req;
+	assert (*priv == end_marker);
+	*priv = NULL;
+	return (0);
+}
+
+static const struct vdp xyzzy_vdp_pedantic = {
+	.name  = "debug.pedantic",
+	.bytes = xyzzy_pedantic_bytes,
+	.fini  = xyzzy_pedantic_fini,
+};
+
 /**********************************************************************/
 
 VCL_STRING v_matchproto_(td_debug_author)
@@ -379,13 +414,10 @@ event_load(VRT_CTX, struct vmod_priv *priv)
 	priv->priv = priv_vcl;
 	priv->free = priv_vcl_free;
 
-	/*
-	 * NB: This is a proof of concept, until we decide what the real
-	 * API should look like, do NOT do this anywhere else.
-	 */
 	VRT_AddVFP(ctx, &xyzzy_rot13);
 
 	VRT_AddVDP(ctx, &xyzzy_vdp_rot13);
+	VRT_AddVDP(ctx, &xyzzy_vdp_pedantic);
 	return (0);
 }
 
@@ -544,6 +576,7 @@ event_discard(VRT_CTX, void *priv)
 
 	VRT_RemoveVFP(ctx, &xyzzy_rot13);
 	VRT_RemoveVDP(ctx, &xyzzy_vdp_rot13);
+	VRT_RemoveVDP(ctx, &xyzzy_vdp_pedantic);
 
 	if (--loads)
 		return (0);


More information about the varnish-commit mailing list