[PATCH 2/3] Make vmod_debug register for expiry callbacks

Martin Blix Grydeland martin at varnish-software.com
Wed Feb 25 16:00:14 CET 2015


---
 lib/libvmod_debug/vmod_debug.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 7bd719f..69256d2 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -38,6 +38,26 @@
 
 static int n_init = 0;
 
+static struct exp_callback exp_cb;
+
+static void __match_proto__(exp_callback_f)
+exp_cb_insert(struct worker *wrk, struct objcore *oc, void *priv)
+{
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	VSL(SLT_Debug, 0, "exp_cb_insert: %p", oc);
+	assert(priv == &exp_cb);
+}
+
+static void __match_proto__(exp_callback_f)
+exp_cb_remove(struct worker *wrk, struct objcore *oc, void *priv)
+{
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	VSL(SLT_Debug, 0, "exp_cb_remove: %p", oc);
+	assert(priv == &exp_cb);
+}
+
 VCL_VOID __match_proto__(td_debug_panic)
 vmod_panic(VRT_CTX, const char *str, ...)
 {
@@ -74,6 +94,10 @@ fini_function(void *priv)
 
 	assert(n_init > 0);
 	n_init--;
+	if (n_init == 0) {
+		EXP_Dereg_Callback(&exp_cb);
+		VSL(SLT_Debug, 0, "exp_cb: deregistered");
+	}
 }
 
 int
@@ -83,6 +107,15 @@ init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
 
 	priv->priv = &n_init;
 	priv->free = fini_function;
+	if (n_init == 0) {
+		memset(&exp_cb, 0, sizeof exp_cb);
+		exp_cb.magic = EXP_CALLBACK_MAGIC;
+		exp_cb.cb_insert = exp_cb_insert;
+		exp_cb.cb_remove = exp_cb_remove;
+		exp_cb.priv = &exp_cb;
+		EXP_Reg_Callback(&exp_cb);
+		VSL(SLT_Debug, 0, "exp_cb: registered");
+	}
 	n_init++;
 	return (0);
 }
-- 
2.1.4




More information about the varnish-dev mailing list