[master] 4c2344b 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-cache.org
Thu Dec 13 15:17:15 CET 2012


commit 4c2344ba0b3728c5b68f46f6c147c44a3d8bf143
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Fri Nov 30 11:28:24 2012 +0100

    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.

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 92499b0..ec288d9 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -574,6 +574,29 @@ 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;
+
+	Lck_AssertHeld(&ban_mtx);
+	/* XXX: Use the ban entry size measurements to hit the target
+	 * and avoid multiple allocations */
+	AN(VSB_new(&vsb, NULL, 64 * VSC_C_main->bans, VSB_AUTOEXTEND));
+	VTAILQ_FOREACH_REVERSE(b, &ban_head, banhead_s, list) {
+		AZ(VSB_bcat(&vsb, b->spec, ban_len(b->spec)));
+	}
+	AZ(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.
  *
@@ -689,9 +712,17 @@ BAN_Compile(void)
 	ASSERT_CLI();
 	AZ(ban_shutdown);
 
+	Lck_Lock(&ban_mtx);
+
 	/* Do late reporting of ban_magic */
 	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();
+
+	Lck_Unlock(&ban_mtx);
+
 	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 89b60cc..3d0c3fa 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -107,6 +107,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
  */
@@ -579,6 +599,7 @@ const struct stevedore smp_stevedore = {
 	.free	=	smp_free,
 	.signal_close = smp_signal_close,
 	.baninfo =	smp_baninfo,
+	.banexport =	smp_banexport,
 };
 
 /*--------------------------------------------------------------------



More information about the varnish-commit mailing list