Commit 374f0b19 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Do proper duplicate detection when we load the bans from the silo.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4122 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 9a54838f
...@@ -60,8 +60,8 @@ SVNID("$Id$") ...@@ -60,8 +60,8 @@ SVNID("$Id$")
#include "cache_ban.h" #include "cache_ban.h"
struct banhead ban_head = VTAILQ_HEAD_INITIALIZER(ban_head); static VTAILQ_HEAD(banhead,ban) ban_head = VTAILQ_HEAD_INITIALIZER(ban_head);
struct lock ban_mtx; static struct lock ban_mtx;
static struct ban *ban_magic; static struct ban *ban_magic;
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -529,23 +529,31 @@ BAN_RefBan(double t0, const struct ban *tail) ...@@ -529,23 +529,31 @@ BAN_RefBan(double t0, const struct ban *tail)
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Put a skeleton ban in the list, unless there is an indentical one * Put a skeleton ban in the list, unless there is an identical,
* already. * time & condition, ban already in place.
*
* If a newer ban has same condition, mark the new ban GONE, and
* mark any older bans, with the same condition, GONE as well.
*/ */
void void
BAN_Reload(double t0, unsigned flags, const char *ban) BAN_Reload(double t0, unsigned flags, const char *ban)
{ {
struct ban *b, *b2; struct ban *b, *b2;
int gone = 0;
ASSERT_CLI(); ASSERT_CLI();
(void)flags; /* for future use */ (void)flags; /* for future use */
VTAILQ_FOREACH(b, &ban_head, list) { VTAILQ_FOREACH(b, &ban_head, list) {
if (b->t0 > t0) if (!strcmp(b->test, ban)) {
if (b->t0 > t0)
gone |= BAN_F_GONE;
else if (b->t0 == t0)
return;
} else if (b->t0 > t0)
continue; continue;
if (b->t0 == t0 && !strcmp(b->test, ban))
return;
if (b->t0 < t0) if (b->t0 < t0)
break; break;
} }
...@@ -558,17 +566,23 @@ BAN_Reload(double t0, unsigned flags, const char *ban) ...@@ -558,17 +566,23 @@ BAN_Reload(double t0, unsigned flags, const char *ban)
b2->test = strdup(ban); b2->test = strdup(ban);
AN(b2->test); AN(b2->test);
b2->t0 = t0; b2->t0 = t0;
b2->flags |= BAN_F_PENDING; b2->flags |= BAN_F_PENDING | gone;
if (b == NULL) if (b == NULL)
VTAILQ_INSERT_TAIL(&ban_head, b2, list); VTAILQ_INSERT_TAIL(&ban_head, b2, list);
else else
VTAILQ_INSERT_BEFORE(b, b2, list); VTAILQ_INSERT_BEFORE(b, b2, list);
/* XXX: Hunt duplicates down */ /* Hunt down older duplicates */
for (b = VTAILQ_NEXT(b2, list); b != NULL; b = VTAILQ_NEXT(b, list)) {
if (b->flags & BAN_F_GONE)
continue;
if (!strcmp(b->test, b2->test))
b->flags |= BAN_F_GONE;
}
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* All silos have read their bans now compile them. * All silos have read their bans, now compile them.
*/ */
void void
...@@ -585,6 +599,8 @@ BAN_Compile(void) ...@@ -585,6 +599,8 @@ BAN_Compile(void)
if (!(b->flags & BAN_F_PENDING)) if (!(b->flags & BAN_F_PENDING))
continue; continue;
b->flags &= ~BAN_F_PENDING; b->flags &= ~BAN_F_PENDING;
if (b->flags & BAN_F_GONE)
continue;
av = ParseArgv(b->test, 0); av = ParseArgv(b->test, 0);
XXXAN(av); XXXAN(av);
XXXAZ(av[0]); XXXAZ(av[0]);
......
...@@ -62,8 +62,3 @@ struct ban { ...@@ -62,8 +62,3 @@ struct ban {
struct vsb *vsb; struct vsb *vsb;
char *test; char *test;
}; };
VTAILQ_HEAD(banhead,ban);
extern struct banhead ban_head;
extern struct lock ban_mtx;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment