[master] 445f3c5 Generalize the ban reporting to the stevedores using their API. This way any stevedore interested in new bans can request to be notified (not just the persistent).

Martin Blix Grydeland martin at varnish-cache.org
Wed Oct 10 09:49:18 CEST 2012


commit 445f3c53332c687316a98941d894e62b6746576e
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed May 23 09:16:29 2012 +0200

    Generalize the ban reporting to the stevedores using their API. This
    way any stevedore interested in new bans can request to be notified
    (not just the persistent).
    
    Also report dropped bans to the stevedores.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 7533782..b6c33cb 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -188,6 +188,15 @@ enum httpwhence {
 	HTTP_Obj
 };
 
+/*--------------------------------------------------------------------
+ * Ban info event types
+ */
+
+enum baninfo {
+	BI_NEW,
+	BI_DROP
+};
+
 /* NB: remember to update http_Copy() if you add fields */
 struct http {
 	unsigned		magic;
@@ -1054,6 +1063,7 @@ void STV_free(struct storage *st);
 void STV_open(void);
 void STV_close(void);
 void STV_Freestore(struct object *o);
+void STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len);
 
 /* storage_synth.c */
 struct vsb *SMS_Makesynth(struct object *obj);
@@ -1063,7 +1073,6 @@ void SMS_Init(void);
 /* storage_persistent.c */
 void SMP_Init(void);
 void SMP_Ready(void);
-void SMP_NewBan(const uint8_t *ban, unsigned len);
 
 /*
  * A normal pointer difference is signed, but we never want a negative value
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 2054d3e..aa8bca9 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -66,6 +66,7 @@
 #include <stdio.h>
 
 #include "cache.h"
+#include "storage/storage.h"
 
 #include "hash/hash_slinger.h"
 #include "vcli.h"
@@ -413,7 +414,7 @@ BAN_Insert(struct ban *b)
 	else
 		be = NULL;
 
-	SMP_NewBan(b->spec, ln);
+	STV_BanInfo(BI_NEW, b->spec, ln);	/* Notify stevedores */
 	Lck_Unlock(&ban_mtx);
 
 	if (be == NULL)
@@ -595,7 +596,9 @@ BAN_Compile(void)
 
 	ASSERT_CLI();
 
-	SMP_NewBan(ban_magic->spec, ban_len(ban_magic->spec));
+	/* Notify stevedores */
+	STV_BanInfo(BI_NEW, ban_magic->spec, ban_len(ban_magic->spec));
+
 	ban_start = VTAILQ_FIRST(&ban_head);
 	WRK_BgThread(&ban_thread, "ban-lurker", ban_lurker, NULL);
 }
@@ -812,6 +815,9 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl, unsigned pass)
 	do {
 		Lck_Lock(&ban_mtx);
 		b2 = ban_CheckLast();
+		if (b2 != NULL)
+			/* Notify stevedores */
+			STV_BanInfo(BI_DROP, b2->spec, ban_len(b2->spec));
 		Lck_Unlock(&ban_mtx);
 		if (b2 != NULL)
 			BAN_Free(b2);
@@ -959,6 +965,10 @@ ban_lurker(struct worker *wrk, void *priv)
 			 */
 			Lck_Lock(&ban_mtx);
 			bf = ban_CheckLast();
+			if (bf != NULL)
+				/* Notify stevedores */
+				STV_BanInfo(BI_DROP, bf->spec,
+					    ban_len(bf->spec));
 			Lck_Unlock(&ban_mtx);
 			if (bf != NULL)
 				BAN_Free(bf);
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index fa5a683..5262b70 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -453,6 +453,15 @@ STV_close(void)
 		stv->close(stv);
 }
 
+void
+STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len)
+{
+	struct stevedore *stv;
+
+	VTAILQ_FOREACH(stv, &stv_stevedores, list)
+		if (stv->baninfo != NULL)
+			stv->baninfo(stv, event, ban, len);
+}
 
 /*--------------------------------------------------------------------
  * VRT functions for stevedores
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index fd1adef..e4a02c1 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -38,6 +38,7 @@ struct busyobj;
 struct objcore;
 struct worker;
 struct lru;
+enum baninfo;
 
 typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
 typedef void storage_open_f(const struct stevedore *);
@@ -48,6 +49,8 @@ typedef struct object *storage_allocobj_f(struct stevedore *, struct busyobj *,
     struct objcore **, unsigned ltot, const struct stv_objsecrets *);
 typedef void storage_close_f(const struct stevedore *);
 typedef void storage_signal_close_f(const struct stevedore *);
+typedef void storage_baninfo_f(struct stevedore *, enum baninfo event,
+    const uint8_t *ban, unsigned len);
 
 /* Prototypes for VCL variable responders */
 #define VRTSTVTYPE(ct) typedef ct storage_var_##ct(const struct stevedore *);
@@ -71,6 +74,7 @@ struct stevedore {
 	storage_close_f		*close;		/* --//-- */
 	storage_allocobj_f	*allocobj;	/* --//-- */
 	storage_signal_close_f	*signal_close;	/* --//-- */
+	storage_baninfo_f	*baninfo;	/* --//-- */
 
 	struct lru		*lru;
 
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 6b8764f..d0d40e2 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -92,14 +92,23 @@ smp_appendban(struct smp_sc *sc, struct smp_signspace *spc,
 
 /* Trust that cache_ban.c takes care of locking */
 
-void
-SMP_NewBan(const uint8_t *ban, unsigned ln)
+static void
+smp_baninfo(struct stevedore *stv, enum baninfo event,
+	    const uint8_t *ban, unsigned len)
 {
 	struct smp_sc *sc;
 
-	VTAILQ_FOREACH(sc, &silos, list) {
-		smp_appendban(sc, &sc->ban1, ln, ban);
-		smp_appendban(sc, &sc->ban2, ln, ban);
+	(void)stv;
+	switch (event) {
+	case BI_NEW:
+		VTAILQ_FOREACH(sc, &silos, list) {
+			smp_appendban(sc, &sc->ban1, len, ban);
+			smp_appendban(sc, &sc->ban2, len, ban);
+		}
+		break;
+	default:
+		/* Ignored */
+		break;
 	}
 }
 
@@ -584,6 +593,7 @@ const struct stevedore smp_stevedore = {
 	.allocobj =	smp_allocobj,
 	.free	=	smp_free,
 	.signal_close = smp_signal_close,
+	.baninfo =	smp_baninfo,
 };
 
 /*--------------------------------------------------------------------



More information about the varnish-commit mailing list