[PATCH 10/15] Add a BAN_Prev function that can be used to iterate over the live ban list

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


---
 bin/varnishd/cache/cache.h     |    1 +
 bin/varnishd/cache/cache_ban.c |   17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 40f8388..c38de0a 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -759,6 +759,7 @@ 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);
+const struct ban *BAN_Prev(const struct ban *ban);
 
 /* cache_busyobj.c */
 void VBO_Init(void);
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 1820f94..d13e5a6 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -659,6 +659,23 @@ BAN_Spec(const struct ban *ban, const uint8_t **spec, unsigned *len)
 }
 
 /*--------------------------------------------------------------------
+ * Return the ban before 'ban'. Returns the tail if 'ban' is NULL.
+ * Returns NULL if 'ban' is the first ban.
+ *
+ * Note: Caller should have a ref to a ban at 'ban' or later in the
+ * list, or be running under the ban mtx.
+ */
+
+const struct ban *
+BAN_Prev(const struct ban *ban)
+{
+	if (ban == NULL)
+		return (VTAILQ_LAST(&ban_head, banhead_s));
+	CHECK_OBJ_NOTNULL(ban, BAN_MAGIC);
+	return (VTAILQ_PREV(ban, banhead_s, list));
+}
+
+/*--------------------------------------------------------------------
  * All silos have read their bans, ready for action
  */
 
-- 
1.7.9.5




More information about the varnish-dev mailing list