[PATCH 15/15] Recompile the ban lists if we don't have enough space to append a new ban.

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


---
 bin/varnishd/storage/storage_persistent.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 86b94f8..bc11637 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -68,6 +68,8 @@ static VTAILQ_HEAD(,smp_sc)	silos = VTAILQ_HEAD_INITIALIZER(silos);
  * Add bans to silos
  */
 
+static void smp_recompile_bans(struct smp_sc *sc, const struct ban *tail);
+
 static void
 smp_appendban(struct smp_sc *sc, struct smp_signspace *spc,
     uint32_t len, const uint8_t *ban)
@@ -108,9 +110,18 @@ smp_baninfo(struct stevedore *stv, enum baninfo event, const struct ban *ban)
 	switch (event) {
 	case BI_NEW:
 		BAN_Spec(ban, &spec, &len);
-		smp_appendban(sc, &sc->ban1, len, spec);
-		smp_appendban(sc, &sc->ban2, len, spec);
-		sc->n_ban++;
+		if (SIGNSPACE_FREE(&sc->ban1) < 4 + 4 + len) {
+			/* Assert unless the recompiled ban lists
+			 * frees/truncates at least 10% of the
+			 * bans */
+			assert(sc->n_ban_dropped + sc->n_ban_gone >=
+			       sc->n_ban / 10);
+			smp_recompile_bans(sc, BAN_Prev(NULL));
+		} else {
+			smp_appendban(sc, &sc->ban1, len, spec);
+			smp_appendban(sc, &sc->ban2, len, spec);
+			sc->n_ban++;
+		}
 		break;
 	case BI_DROP:
 		sc->n_ban_dropped++;
-- 
1.7.9.5




More information about the varnish-dev mailing list