[master] 992d525 Merge the EXP_Register_Callback() and ObjUpdateMeta() notification mechanisms into a single general ObjSubscribeEvents() mechanism.

Poul-Henning Kamp phk at FreeBSD.org
Tue Feb 9 10:40:56 CET 2016


commit 992d5250bfad375fad376a20b7fdaafc834d1ee0
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 9 09:39:53 2016 +0000

    Merge the EXP_Register_Callback() and ObjUpdateMeta() notification
    mechanisms into a single general ObjSubscribeEvents() mechanism.
    
    For efficiency, only the events subscribed to will be delivered.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 3797f1d..eb16777 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -721,17 +721,6 @@ void EXP_Rearm(struct objcore *, double now, double ttl, double grace,
     double keep);
 void EXP_Poke(struct objcore *);
 
-enum exp_event_e {
-	EXP_INSERT,
-	EXP_INJECT,
-	EXP_REMOVE,
-};
-typedef void exp_callback_f(struct worker *, struct objcore *,
-    enum exp_event_e, void *priv);
-
-uintptr_t EXP_Register_Callback(exp_callback_f *func, void *priv);
-void EXP_Deregister_Callback(uintptr_t*);
-
 /* cache_fetch.c */
 enum vbf_fetch_mode_e {
 	VBF_NORMAL = 0,
@@ -884,7 +873,6 @@ void ObjTrimStore(struct worker *, struct objcore *);
 void ObjTouch(struct worker *, struct objcore *, double now);
 unsigned ObjGetXID(struct worker *, struct objcore *);
 uint64_t ObjGetLen(struct worker *, struct objcore *);
-void ObjUpdateMeta(struct worker *, struct objcore *);
 void ObjFreeObj(struct worker *, struct objcore *);
 void ObjSlim(struct worker *, struct objcore *);
 int ObjHasAttr(struct worker *, struct objcore *, enum obj_attr);
@@ -907,6 +895,20 @@ int ObjGetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t *);
 int ObjCheckFlag(struct worker *, struct objcore *, enum obj_flags of);
 void ObjSetFlag(struct worker *, struct objcore *, enum obj_flags of, int val);
 
+#define OEV_BANCHG	(1U<<1)
+#define OEV_TTLCHG	(1U<<2)
+#define OEV_INSERT	(1U<<3)
+#define OEV_REMOVE	(1U<<4)
+
+#define OEV_MASK (OEV_BANCHG|OEV_TTLCHG|OEV_INSERT|OEV_REMOVE)
+
+typedef void obj_event_f(struct worker *, void *priv, struct objcore *,
+    unsigned);
+
+uintptr_t ObjSubscribeEvents(obj_event_f *, void *, unsigned mask);
+void ObjUnsubscribeEvents(uintptr_t *);
+void ObjSendEvent(struct worker *, struct objcore *oc, unsigned event);
+
 /* cache_panic.c */
 const char *body_status_2str(enum body_status e);
 const char *sess_close_2str(enum sess_close sc, int want_desc);
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 0b333a9..f091abf 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -571,7 +571,7 @@ BAN_CheckObject(struct worker *wrk, struct objcore *oc, struct req *req)
 
 	if (b == NULL) {
 		/* not banned */
-		ObjUpdateMeta(wrk, oc);
+		ObjSendEvent(wrk, oc, OEV_BANCHG);
 		return (0);
 	} else {
 		VSLb(vsl, SLT_ExpBan, "%u banned lookup", ObjGetXID(wrk, oc));
diff --git a/bin/varnishd/cache/cache_ban_lurker.c b/bin/varnishd/cache/cache_ban_lurker.c
index 0d56883..3e355c1 100644
--- a/bin/varnishd/cache/cache_ban_lurker.c
+++ b/bin/varnishd/cache/cache_ban_lurker.c
@@ -192,7 +192,7 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
 				bd->refcount++;
 				VTAILQ_INSERT_TAIL(&bd->objcore, oc, ban_list);
 				Lck_Unlock(&ban_mtx);
-				ObjUpdateMeta(wrk, oc);
+				ObjSendEvent(wrk, oc, OEV_BANCHG);
 			}
 		}
 		(void)HSH_DerefObjCore(wrk, &oc);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 9553841..6cc92dd 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -40,14 +40,6 @@
 #include "hash/hash_slinger.h"
 #include "vtim.h"
 
-struct exp_callback {
-	unsigned			magic;
-#define EXP_CALLBACK_MAGIC		0xab956eb1
-	exp_callback_f			*func;
-	void				*priv;
-	VTAILQ_ENTRY(exp_callback)	list;
-};
-
 struct exp_priv {
 	unsigned			magic;
 #define EXP_PRIV_MAGIC			0x9db22482
@@ -60,32 +52,11 @@ struct exp_priv {
 	struct binheap			*heap;
 	pthread_cond_t			condvar;
 
-	VTAILQ_HEAD(,exp_callback)	ecb_list;
 	pthread_rwlock_t		cb_rwl;
 };
 
 static struct exp_priv *exphdl;
 
-static void
-exp_event(struct worker *wrk, struct objcore *oc, enum exp_event_e e)
-{
-	struct exp_callback *cb;
-
-	/*
-	 * Strictly speaking this is not atomic, but neither is VMOD
-	 * loading in general, so this is a fair optimization
-	 */
-	if (VTAILQ_EMPTY(&exphdl->ecb_list))
-		return;
-
-	AZ(pthread_rwlock_rdlock(&exphdl->cb_rwl));
-	VTAILQ_FOREACH(cb, &exphdl->ecb_list, list) {
-		CHECK_OBJ_NOTNULL(cb, EXP_CALLBACK_MAGIC);
-		cb->func(wrk, oc, e, cb->priv);
-	}
-	AZ(pthread_rwlock_unlock(&exphdl->cb_rwl));
-}
-
 /*--------------------------------------------------------------------
  * Calculate an objects effective ttl time, taking req.ttl into account
  * if it is available.
@@ -159,7 +130,7 @@ EXP_Insert(struct worker *wrk, struct objcore *oc)
 
 	HSH_Ref(oc);
 
-	exp_event(wrk, oc, EXP_INSERT);
+	ObjSendEvent(wrk, oc, OEV_INSERT);
 	exp_mail_it(oc, OC_EF_INSERT | OC_EF_EXP | OC_EF_MOVE);
 }
 
@@ -194,45 +165,6 @@ EXP_Rearm(struct objcore *oc, double now, double ttl, double grace, double keep)
 		exp_mail_it(oc, OC_EF_MOVE);
 }
 
-/*--------------------------------------------------------------------*/
-
-uintptr_t
-EXP_Register_Callback(exp_callback_f *func, void *priv)
-{
-	struct exp_callback *ecb;
-
-	AN(func);
-
-	ALLOC_OBJ(ecb, EXP_CALLBACK_MAGIC);
-	AN(ecb);
-	ecb->func = func;
-	ecb->priv = priv;
-	AZ(pthread_rwlock_wrlock(&exphdl->cb_rwl));
-	VTAILQ_INSERT_TAIL(&exphdl->ecb_list, ecb, list);
-	AZ(pthread_rwlock_unlock(&exphdl->cb_rwl));
-	return ((uintptr_t)ecb);
-}
-
-void
-EXP_Deregister_Callback(uintptr_t *handle)
-{
-	struct exp_callback *ecb;
-
-	AN(handle);
-	AN(*handle);
-	AZ(pthread_rwlock_wrlock(&exphdl->cb_rwl));
-	VTAILQ_FOREACH(ecb, &exphdl->ecb_list, list) {
-		CHECK_OBJ_NOTNULL(ecb, EXP_CALLBACK_MAGIC);
-		if ((uintptr_t)ecb == *handle)
-			break;
-	}
-	AN(ecb);
-	VTAILQ_REMOVE(&exphdl->ecb_list, ecb, list);
-	AZ(pthread_rwlock_unlock(&exphdl->cb_rwl));
-	FREE_OBJ(ecb);
-	*handle = 0;
-}
-
 /*--------------------------------------------------------------------
  * Handle stuff in the inbox
  */
@@ -256,14 +188,14 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, unsigned flags)
 			binheap_delete(ep->heap, oc->timer_idx);
 		}
 		assert(oc->timer_idx == BINHEAP_NOIDX);
-		exp_event(ep->wrk, oc, EXP_REMOVE);
+		ObjSendEvent(ep->wrk, oc, OEV_REMOVE);
 		(void)HSH_DerefObjCore(ep->wrk, &oc);
 		return;
 	}
 
 	if (flags & OC_EF_MOVE) {
 		oc->timer_when = EXP_WHEN(oc);
-		ObjUpdateMeta(ep->wrk, oc);
+		ObjSendEvent(ep->wrk, oc, OEV_TTLCHG);
 	}
 
 	VSLb(&ep->vsl, SLT_ExpKill, "EXP_When p=%p e=%.9f f=0x%x", oc,
@@ -325,7 +257,7 @@ exp_expire(struct exp_priv *ep, double now)
 	CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC);
 	VSLb(&ep->vsl, SLT_ExpKill, "EXP_Expired x=%u t=%.0f",
 	    ObjGetXID(ep->wrk, oc), EXP_Ttl(NULL, oc) - now);
-	exp_event(ep->wrk, oc, EXP_REMOVE);
+	ObjSendEvent(ep->wrk, oc, OEV_REMOVE);
 	(void)HSH_DerefObjCore(ep->wrk, &oc);
 	return (0);
 }
@@ -412,7 +344,6 @@ EXP_Init(void)
 	AZ(pthread_cond_init(&ep->condvar, NULL));
 	VSTAILQ_INIT(&ep->inbox);
 	AZ(pthread_rwlock_init(&ep->cb_rwl, NULL));
-	VTAILQ_INIT(&ep->ecb_list);
 	exphdl = ep;
 	WRK_BgThread(&pt, "cache-timeout", exp_thread, ep);
 }
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 78ab1d2..15bd0ff 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -236,6 +236,8 @@ child_main(void)
 	PAN_Init();
 	VFP_Init();
 
+	ObjInit();
+
 	VCL_Init();
 
 	HTTP_Init();
@@ -252,7 +254,6 @@ child_main(void)
 
 	VCA_Init();
 
-	SMP_Init();
 	STV_open();
 
 	VMOD_Init();
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 1fa8d01..cb32f97 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -69,8 +69,6 @@
  *
  * 23	ObjTouch()	Signal to LRU(-like) facilities
  *
- * 23	ObjUpdateMeta()	ban/ttl/grace/keep changed
- *
  * 3->4	HSH_Snipe()	kill if not in use
  * 3->4	HSH_Kill()	make unavailable
  *
@@ -311,19 +309,6 @@ ObjSlim(struct worker *wrk, struct objcore *oc)
 }
 
 /*====================================================================
- */
-void
-ObjUpdateMeta(struct worker *wrk, struct objcore *oc)
-{
-	const struct obj_methods *m = obj_getmethods(oc);
-
-	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-
-	if (m->objupdatemeta != NULL)
-		m->objupdatemeta(wrk, oc);
-}
-
-/*====================================================================
  * Called when the boc used to populate the objcore is going away.
  * Useful for releasing any leftovers from Trim.
  */
@@ -584,3 +569,96 @@ ObjSetFlag(struct worker *wrk, struct objcore *oc, enum obj_flags of, int val)
 	else
 		(*fp) &= ~of;
 }
+
+/*====================================================================
+ * Object event subscribtion mechanism.
+ *
+ * XXX: it is extremely unclear what the locking circumstances are here.
+ */
+
+struct oev_entry {
+	unsigned			magic;
+#define OEV_MAGIC			0xb0b7c5a1
+	unsigned			mask;
+	obj_event_f			*func;
+	void				*priv;
+	VTAILQ_ENTRY(oev_entry)		list;
+};
+
+static VTAILQ_HEAD(,oev_entry)		oev_list;
+static pthread_rwlock_t			oev_rwl;
+static unsigned				oev_mask;
+
+uintptr_t
+ObjSubscribeEvents(obj_event_f *func, void *priv, unsigned mask)
+{
+	struct oev_entry *oev;
+
+	AN(func);
+	AZ(mask & ~OEV_MASK);
+
+	ALLOC_OBJ(oev, OEV_MAGIC);
+	AN(oev);
+	oev->func = func;
+	oev->priv = priv;
+	oev->mask = mask;
+	AZ(pthread_rwlock_wrlock(&oev_rwl));
+	VTAILQ_INSERT_TAIL(&oev_list, oev, list);
+	oev_mask |= mask;
+	AZ(pthread_rwlock_unlock(&oev_rwl));
+	return ((uintptr_t)oev);
+}
+
+void
+ObjUnsubscribeEvents(uintptr_t *handle)
+{
+	struct oev_entry *oev, *oev2 = NULL;
+	unsigned newmask = 0;
+
+	AN(handle);
+	AN(*handle);
+	AZ(pthread_rwlock_wrlock(&oev_rwl));
+	VTAILQ_FOREACH(oev, &oev_list, list) {
+		CHECK_OBJ_NOTNULL(oev, OEV_MAGIC);
+		if ((uintptr_t)oev == *handle)
+			oev2 = oev;
+		else
+			newmask |= oev->mask;
+	}
+	AN(oev2);
+	VTAILQ_REMOVE(&oev_list, oev2, list);
+	oev_mask = newmask;
+	AZ(newmask & ~OEV_MASK);
+	AZ(pthread_rwlock_unlock(&oev_rwl));
+	FREE_OBJ(oev2);
+	*handle = 0;
+}
+
+void
+ObjSendEvent(struct worker *wrk, struct objcore *oc, unsigned event)
+{
+	struct oev_entry *oev;
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	AN(event & OEV_MASK);
+	AZ(event & ~OEV_MASK);
+	if (!(event & oev_mask))
+		return;
+
+	AZ(pthread_rwlock_rdlock(&oev_rwl));
+	VTAILQ_FOREACH(oev, &oev_list, list) {
+		CHECK_OBJ_NOTNULL(oev, OEV_MAGIC);
+		if (event & oev->mask)
+			oev->func(wrk, oev->priv, oc, event);
+	}
+	AZ(pthread_rwlock_unlock(&oev_rwl));
+
+}
+
+void
+ObjInit(void)
+{
+	VTAILQ_INIT(&oev_list);
+	AZ(pthread_rwlock_init(&oev_rwl, NULL));
+}
diff --git a/bin/varnishd/cache/cache_obj.h b/bin/varnishd/cache/cache_obj.h
index 41e3ae5..c4eea09 100644
--- a/bin/varnishd/cache/cache_obj.h
+++ b/bin/varnishd/cache/cache_obj.h
@@ -30,7 +30,6 @@
 
 /* Methods on objcore ------------------------------------------------*/
 
-typedef void objupdatemeta_f(struct worker *, struct objcore *);
 typedef void objfree_f(struct worker *, struct objcore *);
 
 /* This method is only used by SML (...to get to persistent) */
@@ -51,8 +50,6 @@ typedef void objtouch_f(struct worker *, struct objcore *, double now);
 
 struct obj_methods {
 	objfree_f	*objfree;
-	objupdatemeta_f	*objupdatemeta;
-
 	objiterator_f	*objiterator;
 	objgetspace_f	*objgetspace;
 	objextend_f	*objextend;
diff --git a/bin/varnishd/cache/cache_priv.h b/bin/varnishd/cache/cache_priv.h
index 7dd941e..3f64c8e 100644
--- a/bin/varnishd/cache/cache_priv.h
+++ b/bin/varnishd/cache/cache_priv.h
@@ -98,6 +98,9 @@ struct req * THR_GetRequest(void);
 /* cache_lck.c */
 void LCK_Init(void);
 
+/* cache_obj.c */
+void ObjInit(void);
+
 /* cache_panic.c */
 void PAN_Init(void);
 
@@ -134,6 +137,5 @@ int STV_BanInfoNew(const uint8_t *ban, unsigned len);
 void STV_BanExport(const uint8_t *banlist, unsigned len);
 
 /* storage_persistent.c */
-void SMP_Init(void);
 void SMP_Ready(void);
 
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 7ebb747..ba1a450 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -59,6 +59,8 @@ static struct obj_methods smp_oc_realmethods;
 
 static struct VSC_C_lck *lck_smp;
 
+static void smp_init(void);
+
 /*--------------------------------------------------------------------*/
 
 /*
@@ -326,6 +328,9 @@ smp_open(struct stevedore *st)
 
 	ASSERT_CLI();
 
+	if (VTAILQ_EMPTY(&silos))
+		smp_init();
+
 	CAST_OBJ_NOTNULL(sc, st->priv, SMP_SC_MAGIC);
 
 	Lck_New(&sc->mtx, lck_smp);
@@ -684,17 +689,19 @@ static struct cli_proto debug_cmds[] = {
 	{ NULL }
 };
 
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ */
 
-void
-SMP_Init(void)
+static void
+smp_init(void)
 {
 	lck_smp = Lck_CreateClass("smp");
 	CLI_AddFuncs(debug_cmds);
 	smp_oc_realmethods = SML_methods;
 	smp_oc_realmethods.objtouch = NULL;
-	smp_oc_realmethods.objupdatemeta = smp_oc_objupdatemeta;
 	smp_oc_realmethods.objfree = smp_oc_objfree;
+	(void)ObjSubscribeEvents(smp_oc_event, NULL,
+	    OEV_BANCHG|OEV_TTLCHG|OEV_INSERT);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h
index 9edb47b..f7af273 100644
--- a/bin/varnishd/storage/storage_persistent.h
+++ b/bin/varnishd/storage/storage_persistent.h
@@ -311,8 +311,8 @@ void smp_close_seg(struct smp_sc *sc, struct smp_seg *sg);
 void smp_init_oc(struct objcore *oc, struct smp_seg *sg, unsigned objidx);
 void smp_save_segs(struct smp_sc *sc);
 sml_getobj_f smp_sml_getobj;
-void smp_oc_objupdatemeta(struct worker *, struct objcore *);
 void smp_oc_objfree(struct worker *, struct objcore *);
+obj_event_f smp_oc_event;
 
 /* storage_persistent_subr.c */
 
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index e3cbe07..78b7e82 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -452,31 +452,6 @@ smp_sml_getobj(struct worker *wrk, struct objcore *oc)
 	return (o);
 }
 
-void __match_proto__(objupdatemeta_f)
-smp_oc_objupdatemeta(struct worker *wrk, struct objcore *oc)
-{
-	struct smp_seg *sg;
-	struct smp_object *so;
-
-	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-
-	CAST_OBJ_NOTNULL(sg, oc->stobj->priv, SMP_SEG_MAGIC);
-	CHECK_OBJ_NOTNULL(sg->sc, SMP_SC_MAGIC);
-	so = smp_find_so(sg, oc->stobj->priv2);
-
-	if (sg == sg->sc->cur_seg) {
-		/* Lock necessary, we might race close_seg */
-		Lck_Lock(&sg->sc->mtx);
-		so->ban = BAN_Time(oc->ban);
-		EXP_COPY(so, oc);
-		Lck_Unlock(&sg->sc->mtx);
-	} else {
-		so->ban = BAN_Time(oc->ban);
-		EXP_COPY(so, oc);
-	}
-}
-
 void __match_proto__(objfree_f)
 smp_oc_objfree(struct worker *wrk, struct objcore *oc)
 {
@@ -518,3 +493,36 @@ smp_init_oc(struct objcore *oc, struct smp_seg *sg, unsigned objidx)
 	oc->stobj->priv = sg;
 	oc->stobj->priv2 = objidx;
 }
+
+/*--------------------------------------------------------------------*/
+
+void __match_proto__(obj_event_f)
+smp_oc_event(struct worker *wrk, void *priv, struct objcore *oc, unsigned ev)
+{
+	struct smp_seg *sg;
+	struct smp_object *so;
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	AZ(priv);
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+
+	CAST_OBJ_NOTNULL(sg, oc->stobj->priv, SMP_SEG_MAGIC);
+	CHECK_OBJ_NOTNULL(sg->sc, SMP_SC_MAGIC);
+	so = smp_find_so(sg, oc->stobj->priv2);
+
+	if (sg == sg->sc->cur_seg) {
+		/* Lock necessary, we might race close_seg */
+		Lck_Lock(&sg->sc->mtx);
+		if (ev & (OEV_BANCHG|OEV_INSERT))
+			so->ban = BAN_Time(oc->ban);
+		if (ev & (OEV_TTLCHG|OEV_INSERT))
+			EXP_COPY(so, oc);
+		Lck_Unlock(&sg->sc->mtx);
+	} else {
+		if (ev & (OEV_BANCHG|OEV_INSERT))
+			so->ban = BAN_Time(oc->ban);
+		if (ev & (OEV_TTLCHG|OEV_INSERT))
+			EXP_COPY(so, oc);
+	}
+}
+
diff --git a/bin/varnishtest/tests/m00021.vtc b/bin/varnishtest/tests/m00021.vtc
index 5db3362..87f6834 100644
--- a/bin/varnishtest/tests/m00021.vtc
+++ b/bin/varnishtest/tests/m00021.vtc
@@ -10,17 +10,17 @@ varnish v1 -vcl+backend {} -start
 varnish v1 -cliok "param.set debug +vclrel"
 
 logexpect l1 -v v1 -g raw {
-	expect * 0 Debug "exp_cb: registered"
-	expect * 0 Debug "exp_cb: event insert 0x[0-9a-f]+"
-	expect * 0 Debug "exp_cb: event remove 0x[0-9a-f]+"
-	expect * 0 Debug "exp_cb: deregistered"
+	expect * 0 Debug "Subscribed to Object Events"
+	expect * 0 Debug "Object Event: insert 0x[0-9a-f]+"
+	expect * 0 Debug "Object Event: remove 0x[0-9a-f]+"
+	expect * 0 Debug "Unsubscribed from Object Events"
 } -start
 
 varnish v1 -vcl+backend {
 	import ${vmod_debug};
 
 	sub vcl_init {
-		debug.register_exp_callback();
+		debug.register_obj_events();
 	}
 
 	sub vcl_recv {
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index 8bc0dd2..d0ebe1c 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -99,7 +99,7 @@ $Function STRING argtest(STRING one, REAL two=2, STRING three="3",
 
 $Function INT vre_limit()
 
-$Function VOID register_exp_callback(PRIV_VCL)
+$Function VOID register_obj_events(PRIV_VCL)
 
 Register the vmod to receive expiry callbacks
 
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 839d0ad..1e1b71f 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -44,7 +44,7 @@ struct priv_vcl {
 	unsigned		magic;
 #define PRIV_VCL_MAGIC		0x8E62FA9D
 	char			*foo;
-	uintptr_t		exp_cb;
+	uintptr_t		obj_cb;
 	struct vcl		*vcl;
 	struct vclref		*vclref;
 };
@@ -198,8 +198,8 @@ vmod_vre_limit(VRT_CTX)
 	return (cache_param->vre_limits.match);
 }
 
-static void __match_proto__(exp_callback_f)
-exp_cb(struct worker *wrk, struct objcore *oc, enum exp_event_e ev, void *priv)
+static void __match_proto__(obj_event_f)
+obj_cb(struct worker *wrk, void *priv, struct objcore *oc, unsigned event)
 {
 	const struct priv_vcl *priv_vcl;
 	const char *what;
@@ -207,26 +207,28 @@ exp_cb(struct worker *wrk, struct objcore *oc, enum exp_event_e ev, void *priv)
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	CAST_OBJ_NOTNULL(priv_vcl, priv, PRIV_VCL_MAGIC);
-	switch (ev) {
-	case EXP_INSERT: what = "insert"; break;
-	case EXP_INJECT: what = "inject"; break;
-	case EXP_REMOVE: what = "remove"; break;
-	default: WRONG("Wrong exp_event");
+	switch (event) {
+	case OEV_INSERT: what = "insert"; break;
+	case OEV_REMOVE: what = "remove"; break;
+	default: WRONG("Wrong object event");
 	}
-	VSL(SLT_Debug, 0, "exp_cb: event %s 0x%jx", what,
+
+	/* We cannot trust %p to be 0x... format as expected by m00021.vtc */
+	VSL(SLT_Debug, 0, "Object Event: %s 0x%jx", what,
 	    (intmax_t)(uintptr_t)oc);
 }
 
 VCL_VOID __match_proto__()
-vmod_register_exp_callback(VRT_CTX, struct vmod_priv *priv)
+vmod_register_obj_events(VRT_CTX, struct vmod_priv *priv)
 {
 	struct priv_vcl *priv_vcl;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CAST_OBJ_NOTNULL(priv_vcl, priv->priv, PRIV_VCL_MAGIC);
-	AZ(priv_vcl->exp_cb);
-	priv_vcl->exp_cb = EXP_Register_Callback(exp_cb, priv_vcl);
-	VSL(SLT_Debug, 0, "exp_cb: registered");
+	AZ(priv_vcl->obj_cb);
+	priv_vcl->obj_cb = ObjSubscribeEvents(obj_cb, priv_vcl,
+		OEV_INSERT|OEV_REMOVE);
+	VSL(SLT_Debug, 0, "Subscribed to Object Events");
 }
 
 VCL_VOID __match_proto__()
@@ -246,9 +248,9 @@ priv_vcl_free(void *priv)
 	CAST_OBJ_NOTNULL(priv_vcl, priv, PRIV_VCL_MAGIC);
 	AN(priv_vcl->foo);
 	free(priv_vcl->foo);
-	if (priv_vcl->exp_cb != 0) {
-		EXP_Deregister_Callback(&priv_vcl->exp_cb);
-		VSL(SLT_Debug, 0, "exp_cb: deregistered");
+	if (priv_vcl->obj_cb != 0) {
+		ObjUnsubscribeEvents(&priv_vcl->obj_cb);
+		VSL(SLT_Debug, 0, "Unsubscribed from Object Events");
 	}
 	AZ(priv_vcl->vcl);
 	AZ(priv_vcl->vclref);



More information about the varnish-commit mailing list