[PATCH 3/7] Add a facility to export a complete ban list to the stevedores. Call this on startup, after reading the persisted ban lists, to make sure all stevedores has all the bans from every stevedore stored.

Martin Blix Grydeland martin at varnish-software.com
Mon Dec 3 11:09:51 CET 2012


---
 bin/varnishd/cache/cache.h                |    1 +
 bin/varnishd/cache/cache_ban.c            |   27 +++++++++++++++++++++++++--
 bin/varnishd/storage/stevedore.c          |   16 ++++++++++++++++
 bin/varnishd/storage/storage.h            |    3 +++
 bin/varnishd/storage/storage_persistent.c |   21 +++++++++++++++++++++
 5 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 6a0d1a4..f97f8a7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1061,6 +1061,7 @@ void STV_open(void);
 void STV_close(void);
 void STV_Freestore(struct object *o);
 int STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len);
+void STV_BanExport(const uint8_t *bans, unsigned len);
 
 /* storage_synth.c */
 struct vsb *SMS_Makesynth(struct object *obj);
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 21abf41..4e912ee 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -566,6 +566,28 @@ BAN_RefBan(struct objcore *oc, double t0, const struct ban *tail)
 }
 
 /*--------------------------------------------------------------------
+ * Compile a full ban list and export this area to the stevedores for
+ * persistence.
+ */
+
+static void
+ban_export(void)
+{
+	struct ban *b;
+	struct vsb vsb;
+
+	/* XXX: Use the ban entry size measurements to hit the target
+	 * and avoid multiple allocations */
+	VSB_new(&vsb, NULL, 64 * VSC_C_main->bans, VSB_AUTOEXTEND);
+	VTAILQ_FOREACH_REVERSE(b, &ban_head, banhead_s, list) {
+		VSB_bcat(&vsb, b->spec, ban_len(b->spec));
+	}
+	VSB_finish(&vsb);
+	STV_BanExport((const uint8_t *)VSB_data(&vsb), VSB_len(&vsb));
+	VSB_delete(&vsb);
+}
+
+/*--------------------------------------------------------------------
  * Put a skeleton ban in the list, unless there is an identical,
  * time & condition, ban already in place.
  *
@@ -681,8 +703,9 @@ BAN_Compile(void)
 	ASSERT_CLI();
 	AZ(ban_shutdown);
 
-	/* Notify stevedores */
-	AZ(STV_BanInfo(BI_NEW, ban_magic->spec, ban_len(ban_magic->spec)));
+	/* All bans have been read from all persistent stevedores. Export
+	   the compiled list */
+	ban_export();
 
 	ban_start = VTAILQ_FIRST(&ban_head);
 	WRK_BgThread(&ban_thread, "ban-lurker", ban_lurker, NULL);
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index be16057..63400eb 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -472,6 +472,22 @@ STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len)
 	return (r);
 }
 
+/*-------------------------------------------------------------------
+ * Export a complete ban list to the stevedores for persistence.
+ * The stevedores should clear any previous ban lists and replace
+ * them with this list.
+ */
+
+void
+STV_BanExport(const uint8_t *bans, unsigned len)
+{
+	struct stevedore *stv;
+
+	VTAILQ_FOREACH(stv, &stv_stevedores, list)
+		if (stv->banexport != NULL)
+			stv->banexport(stv, bans, len);
+}
+
 /*--------------------------------------------------------------------
  * VRT functions for stevedores
  */
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index cddf6ef..4a69bb0 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -50,6 +50,8 @@ typedef void storage_close_f(const struct stevedore *);
 typedef void storage_signal_close_f(const struct stevedore *);
 typedef int storage_baninfo_f(struct stevedore *, enum baninfo event,
     const uint8_t *ban, unsigned len);
+typedef void storage_banexport_f(struct stevedore *, const uint8_t *bans,
+    unsigned len);
 
 /* Prototypes for VCL variable responders */
 #define VRTSTVTYPE(ct) typedef ct storage_var_##ct(const struct stevedore *);
@@ -74,6 +76,7 @@ struct stevedore {
 	storage_allocobj_f	*allocobj;	/* --//-- */
 	storage_signal_close_f	*signal_close;	/* --//-- */
 	storage_baninfo_f	*baninfo;	/* --//-- */
+	storage_banexport_f	*banexport;	/* --//-- */
 
 	struct lru		*lru;
 
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index d02ae88..37bcea3 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -111,6 +111,26 @@ smp_baninfo(struct stevedore *stv, enum baninfo event,
 	return (r);
 }
 
+static void
+smp_banexport_spc(struct smp_signspace *spc, const uint8_t *bans, unsigned len)
+{
+	smp_reset_signspace(spc);
+	assert(SIGNSPACE_FREE(spc) >= len);
+	memcpy(SIGNSPACE_DATA(spc), bans, len);
+	smp_append_signspace(spc, len);
+	smp_sync_sign(&spc->ctx);
+}
+
+static void
+smp_banexport(struct stevedore *stv, const uint8_t *bans, unsigned len)
+{
+	struct smp_sc *sc;
+
+	CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
+	smp_banexport_spc(&sc->ban1, bans, len);
+	smp_banexport_spc(&sc->ban2, bans, len);
+}
+
 /*--------------------------------------------------------------------
  * Attempt to open and read in a ban list
  */
@@ -586,6 +606,7 @@ const struct stevedore smp_stevedore = {
 	.free	=	smp_free,
 	.signal_close = smp_signal_close,
 	.baninfo =	smp_baninfo,
+	.banexport =	smp_banexport,
 };
 
 /*--------------------------------------------------------------------
-- 
1.7.10.4




More information about the varnish-dev mailing list