[PATCH 2/7] Report BAN event persistence failures back to cache_ban.c

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


---
 bin/varnishd/cache/cache.h                |    2 +-
 bin/varnishd/cache/cache_ban.c            |    6 +++---
 bin/varnishd/storage/stevedore.c          |   13 +++++++++++--
 bin/varnishd/storage/storage.h            |    2 +-
 bin/varnishd/storage/storage_persistent.c |   18 ++++++++++++------
 5 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 4b29167..6a0d1a4 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1060,7 +1060,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);
+int STV_BanInfo(enum baninfo event, const uint8_t *ban, 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 57fadb9..21abf41 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -476,7 +476,7 @@ BAN_Insert(struct ban *b)
 	else
 		be = NULL;
 
-	STV_BanInfo(BI_NEW, b->spec, ln);	/* Notify stevedores */
+	AZ(STV_BanInfo(BI_NEW, b->spec, ln));	/* Notify stevedores */
 	Lck_Unlock(&ban_mtx);
 
 	if (be == NULL)
@@ -682,7 +682,7 @@ BAN_Compile(void)
 	AZ(ban_shutdown);
 
 	/* Notify stevedores */
-	STV_BanInfo(BI_NEW, ban_magic->spec, ban_len(ban_magic->spec));
+	AZ(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);
@@ -875,7 +875,7 @@ ban_cleantail(void)
 			VSC_C_main->bans--;
 			VSC_C_main->bans_deleted++;
 			VTAILQ_REMOVE(&ban_head, b, list);
-			STV_BanInfo(BI_DROP, b->spec, ban_len(b->spec));
+			AZ(STV_BanInfo(BI_DROP, b->spec, ban_len(b->spec)));
 		} else {
 			b = NULL;
 		}
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 5262b70..be16057 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -453,14 +453,23 @@ STV_close(void)
 		stv->close(stv);
 }
 
-void
+/*-------------------------------------------------------------------
+ * Notify the stevedores of BAN related events. A non-zero return
+ * value indicates that the stevedore is unable to persist the
+ * event.
+ */
+
+int
 STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len)
 {
 	struct stevedore *stv;
+	int r = 0;
 
 	VTAILQ_FOREACH(stv, &stv_stevedores, list)
 		if (stv->baninfo != NULL)
-			stv->baninfo(stv, event, ban, len);
+			r |= stv->baninfo(stv, event, ban, len);
+
+	return (r);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index e9971e7..cddf6ef 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -48,7 +48,7 @@ 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,
+typedef int storage_baninfo_f(struct stevedore *, enum baninfo event,
     const uint8_t *ban, unsigned len);
 
 /* Prototypes for VCL variable responders */
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index e2cf429..d02ae88 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -68,41 +68,47 @@ static VTAILQ_HEAD(,smp_sc)	silos = VTAILQ_HEAD_INITIALIZER(silos);
  * Add bans to silos
  */
 
-static void
+static int
 smp_appendban(struct smp_sc *sc, struct smp_signspace *spc,
     uint32_t len, const uint8_t *ban)
 {
 
 	(void)sc;
-	assert(SIGNSPACE_FREE(spc) >=  len);
+	if (SIGNSPACE_FREE(spc) < len)
+		return (-1);
 
 	memcpy(SIGNSPACE_FRONT(spc), ban, len);
 	smp_append_signspace(spc, len);
+
+	return (0);
 }
 
 /* Trust that cache_ban.c takes care of locking */
 
-static void
+static int
 smp_baninfo(struct stevedore *stv, enum baninfo event,
 	    const uint8_t *ban, unsigned len)
 {
 	struct smp_sc *sc;
+	int r = 0;
 
 	CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
 
 	if (!(sc->flags & SMP_SC_OPENED))
 		/* Ignore ban events until we have been opened */
-		return;
+		return (0);
 
 	switch (event) {
 	case BI_NEW:
-		smp_appendban(sc, &sc->ban1, len, ban);
-		smp_appendban(sc, &sc->ban2, len, ban);
+		r |= smp_appendban(sc, &sc->ban1, len, ban);
+		r |= smp_appendban(sc, &sc->ban2, len, ban);
 		break;
 	default:
 		/* Ignored */
 		break;
 	}
+
+	return (r);
 }
 
 /*--------------------------------------------------------------------
-- 
1.7.10.4




More information about the varnish-dev mailing list