[PATCH 05/15] Allow reload of truncated gone bans, which contain only the ban timestamp.
Martin Blix Grydeland
martin at varnish-software.com
Wed Nov 7 12:32:08 CET 2012
---
bin/varnishd/cache/cache_ban.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index f44d98d..afc9861 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -116,6 +116,7 @@ static int ban_shutdown = 0;
#define BANHEAD_O_LEN 8
#define BANHEAD_O_FLAGS 12
#define BANHEAD_LEN 13
+#define BANHEAD_LEN_TS (BANHEAD_O_LEN)
/*--------------------------------------------------------------------
* BAN string magic markers
@@ -550,8 +551,10 @@ BAN_Reload(const uint8_t *ban, unsigned len)
ASSERT_CLI();
AZ(ban_shutdown);
+ assert(len >= BANHEAD_LEN || len == BANHEAD_LEN_TS);
+ if (len >= BANHEAD_LEN)
+ assert(len == ban_len(ban));
t0 = ban_time(ban);
- assert(len == ban_len(ban));
Lck_Lock(&ban_mtx);
@@ -565,6 +568,9 @@ BAN_Reload(const uint8_t *ban, unsigned len)
}
if (t1 < t0)
break;
+ if (len == BANHEAD_LEN_TS)
+ /* Truncated ban - don't check */
+ continue;
if (!memcmp(b->spec + BANHEAD_O_LEN, ban + BANHEAD_O_LEN,
len - BANHEAD_O_LEN))
duplicate = 1;
@@ -575,9 +581,19 @@ BAN_Reload(const uint8_t *ban, unsigned len)
b2 = BAN_New();
AN(b2);
- b2->spec = malloc(len);
- AN(b2->spec);
- memcpy(b2->spec, ban, len);
+ if (len == BANHEAD_LEN_TS) {
+ /* Reload of truncated GONE ban, create an empty ban */
+ b2->spec = malloc(BANHEAD_LEN);
+ AN(b2->spec);
+ memcpy(b2->spec, ban, len);
+ b2->spec[BANHEAD_O_FLAGS] = 0;
+ vbe32enc(b2->spec + BANHEAD_O_LEN, BANHEAD_LEN);
+ b2->flags |= BAN_F_GONE;
+ } else {
+ b2->spec = malloc(len);
+ AN(b2->spec);
+ memcpy(b2->spec, ban, len);
+ }
if (duplicate) {
VSC_C_main->bans_dups++;
b2->flags |= BAN_F_GONE;
--
1.7.9.5
More information about the varnish-dev
mailing list