[master] dbd7ddc Allow reload of a series of persisted ban specs in one go.

Martin Blix Grydeland martin at varnish-cache.org
Thu Dec 13 15:17:15 CET 2012


commit dbd7ddc0c6158121b8511272bc76fe891f856f96
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Nov 19 13:46:56 2012 +0100

    Allow reload of a series of persisted ban specs in one go.

diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 7b9adf5..ef03ab2 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -573,29 +573,25 @@ BAN_RefBan(struct objcore *oc, double t0, const struct ban *tail)
  * mark any older bans, with the same condition, GONE as well.
  */
 
-void
-BAN_Reload(const uint8_t *ban, unsigned len)
+static void
+ban_reload(const uint8_t *ban, unsigned len)
 {
 	struct ban *b, *b2;
 	int gone = 0;
 	double t0, t1, t2 = 9e99;
 
 	ASSERT_CLI();
-	AZ(ban_shutdown);
+	Lck_AssertHeld(&ban_mtx);
 
 	t0 = ban_time(ban);
 	assert(len == ban_len(ban));
 
-	Lck_Lock(&ban_mtx);
-
 	VTAILQ_FOREACH(b, &ban_head, list) {
 		t1 = ban_time(b->spec);
 		assert(t1 < t2);
 		t2 = t1;
-		if (t1 == t0) {
-			Lck_Unlock(&ban_mtx);
+		if (t1 == t0)
 			return;
-		}
 		if (t1 < t0)
 			break;
 		if (ban_equal(b->spec, ban)) {
@@ -632,6 +628,30 @@ BAN_Reload(const uint8_t *ban, unsigned len)
 			VSC_C_main->bans_dups++;
 		}
 	}
+}
+
+/*--------------------------------------------------------------------
+ * Reload a series of persisted ban specs
+ */
+
+void
+BAN_Reload(const uint8_t *ptr, unsigned len)
+{
+	const uint8_t *pe;
+	unsigned l;
+
+	AZ(ban_shutdown);
+	pe = ptr + len;
+	Lck_Lock(&ban_mtx);
+	while (ptr < pe) {
+		/* XXX: This can be optimized by traversing the live
+		 * ban list together with the reload list (combining
+		 * the loops in BAN_Reload and ban_reload). */
+		l = ban_len(ptr);
+		assert(ptr + l <= pe);
+		ban_reload(ptr, l);
+		ptr += l;
+	}
 	Lck_Unlock(&ban_mtx);
 }
 



More information about the varnish-commit mailing list