[PATCH 06/15] Add a BAN_Spec function, to get access to the byte representation of a ban.

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


Will truncate GONE bans to only contain the timestamp.
---
 bin/varnishd/cache/cache.h     |    1 +
 bin/varnishd/cache/cache_ban.c |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 8a73aa7..582dc0b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -758,6 +758,7 @@ void BAN_Compile(void);
 struct ban *BAN_RefBan(struct objcore *oc, double t0, const struct ban *tail);
 void BAN_TailDeref(struct ban **ban);
 double BAN_Time(const struct ban *ban);
+void BAN_Spec(const struct ban *ban, const uint8_t **spec, unsigned *len);
 
 /* cache_busyobj.c */
 void VBO_Init(void);
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index afc9861..d15f6c5 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -637,6 +637,28 @@ BAN_Time(const struct ban *b)
 }
 
 /*--------------------------------------------------------------------
+ *
+ * Get a bans byte spec and length for offline storage purpose
+ * (e.g. persistent stevedores). Truncates GONE bans to only include
+ * the timestamp.
+ */
+
+void
+BAN_Spec(const struct ban *ban, const uint8_t **spec, unsigned *len)
+{
+	CHECK_OBJ_NOTNULL(ban, BAN_MAGIC);
+	AN(spec);
+	AN(len);
+
+	*spec = ban->spec;
+	if (ban->flags & BAN_F_GONE)
+		/* Truncate GONE bans */
+		*len = BANHEAD_LEN_TS;
+	else
+		*len = ban_len(ban->spec);
+}
+
+/*--------------------------------------------------------------------
  * All silos have read their bans, ready for action
  */
 
-- 
1.7.9.5




More information about the varnish-dev mailing list