[PATCH 11/15] Recompile the silo ban lists on BanCompile callback

Martin Blix Grydeland martin at varnish-software.com
Wed Nov 7 12:32:14 CET 2012


---
 bin/varnishd/storage/storage_persistent.c |   49 +++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index ec306e6..ba7996d 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -117,6 +117,54 @@ smp_baninfo(struct stevedore *stv, enum baninfo event, const struct ban *ban)
 	}
 }
 
+/* Write the current ban list from 'tailb' to the head to the
+ * silo. This will compact the list removing any dropped bans, and
+ * compacting any gone bans. */
+
+static void
+smp_recompile_bans(struct smp_sc *sc, const struct ban *tail)
+{
+	const struct ban *b;
+	uint8_t *ptr, *ptr2;
+	const uint8_t *spec;
+	unsigned len;
+
+	/* Write the list to ban1 */
+	smp_reset_signspace(&sc->ban1);
+	ptr = ptr2 = SIGNSPACE_FRONT(&sc->ban1);
+	for (b = tail; b != NULL; b = BAN_Prev(b)) {
+		BAN_Spec(b, &spec, &len);
+		assert(SIGNSPACE_FREE(&sc->ban1) >= (ptr - ptr2) + 4 + 4 + len);
+		memcpy(ptr, "BAN", 4);
+		ptr += 4;
+		vbe32enc(ptr, len);
+		ptr += 4;
+		memcpy(ptr, spec, len);
+		ptr += len;
+	}
+	smp_append_signspace(&sc->ban1, ptr - ptr2);
+	smp_sync_sign(&sc->ban1.ctx);
+
+	/* Copy to ban2 */
+	smp_copy_signspace(&sc->ban2, &sc->ban1);
+	smp_sync_sign(&sc->ban2.ctx);
+}
+
+/* Recompile the silo ban lists from the live ban list. Trust that
+ * cache_ban.c takes care of the locking */
+static void
+smp_bancompile(const struct stevedore *stv)
+{
+	struct smp_sc *sc;
+	const struct ban *tailb;
+
+	ASSERT_CLI();
+	CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
+
+	tailb = BAN_Prev(NULL);  /* Safe as we are running under ban mtx */
+	smp_recompile_bans(sc, tailb);
+}
+
 /*--------------------------------------------------------------------
  * Attempt to open and read in a ban list
  */
@@ -611,6 +659,7 @@ const struct stevedore smp_stevedore = {
 	.free	=	smp_free,
 	.signal_close = smp_signal_close,
 	.baninfo =	smp_baninfo,
+	.bancompile =	smp_bancompile,
 };
 
 /*--------------------------------------------------------------------
-- 
1.7.9.5




More information about the varnish-dev mailing list