Commit 52ef5676 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Almost complete reimplementation of the internals of bans.

-spersistent changed the requirements a fair bit, and amongst other
things introduced a ban timestamp as a unique identifier of a ban,
and the need to save and reinstate a ban.

The way this was implemented somewhat less than elegant, but we had
little choice due to the way regexps work, and amongst other horrors
it involved too much parsing and quoting of bans as text strings.

Since then we have switched to PCRE, which compiles regexps to
a bytestream which can be saved offline, and this paved the way
for this rewrite.

Instead of a datastructure with a list of tests to be carried out,
build a byte-string which encodes the same information, along with
additional information (the uncompiled regexp) to allow the ban to
be reconstructed for display in ban.list.

Include the ban timestamp as the first 8 bytes of the ban specification,
to eliminate obj->ban_t, saving 8 bytes per object.

Additional polishing to be expected.
parent 1bf7f620
......@@ -94,6 +94,7 @@ noinst_HEADERS = \
vparam.h
varnishd_CFLAGS = \
@PCRE_CFLAGS@ \
-DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' \
-DVARNISH_VMOD_DIR='"${pkglibdir}/vmods"' \
-DVARNISH_VCL_DIR='"${varnishconfdir}"'
......@@ -106,6 +107,7 @@ varnishd_LDADD = \
$(top_builddir)/lib/libvcl/libvcl.la \
$(top_builddir)/lib/libvgz/libvgz.la \
@JEMALLOC_LDADD@ \
@PCRE_LIBS@ \
${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${LIBM} ${LIBUMEM}
EXTRA_DIST = default.vcl
......
......@@ -480,7 +480,6 @@ struct object {
struct ws ws_o[1];
unsigned char *vary;
double ban_t;
unsigned response;
/* XXX: make bitmap */
......@@ -649,14 +648,15 @@ int BAN_AddTest(struct cli *, struct ban *, const char *, const char *,
void BAN_Free(struct ban *b);
void BAN_Insert(struct ban *b);
void BAN_Init(void);
void BAN_NewObj(struct object *o);
void BAN_NewObjCore(struct objcore *oc);
void BAN_DestroyObj(struct objcore *oc);
int BAN_CheckObject(struct object *o, const struct sess *sp);
void BAN_Reload(double t0, unsigned flags, const char *ban);
void BAN_Reload(const uint8_t *ban, unsigned len);
struct ban *BAN_TailRef(void);
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);
/* cache_center.c [CNT] */
void CNT_Session(struct sess *sp);
......@@ -931,7 +931,7 @@ void SMS_Finish(struct object *obj);
/* storage_persistent.c */
void SMP_Init(void);
void SMP_Ready(void);
void SMP_NewBan(double t0, const char *ban);
void SMP_NewBan(const uint8_t *ban, unsigned len);
/*
* A normal pointer difference is signed, but we never want a negative value
......
This diff is collapsed.
......@@ -257,7 +257,7 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
o->objcore = sp->objcore;
sp->objcore = NULL; /* refcnt follows pointer. */
BAN_NewObj(o);
BAN_NewObjCore(o->objcore);
o->objcore->methods = &default_oc_methods;
o->objcore->priv = o;
......
......@@ -50,6 +50,7 @@
#include "vsha256.h"
#include "cli.h"
#include "cli_priv.h"
#include "vend.h"
#include "persistent.h"
#include "storage_persistent.h"
......@@ -67,8 +68,8 @@ static VTAILQ_HEAD(,smp_sc) silos = VTAILQ_HEAD_INITIALIZER(silos);
*/
static void
smp_appendban(struct smp_sc *sc, struct smp_signctx *ctx, double t0,
uint32_t flags, uint32_t len, const char *ban)
smp_appendban(struct smp_sc *sc, struct smp_signctx *ctx,
uint32_t len, const uint8_t *ban)
{
uint8_t *ptr, *ptr2;
......@@ -78,14 +79,8 @@ smp_appendban(struct smp_sc *sc, struct smp_signctx *ctx, double t0,
memcpy(ptr, "BAN", 4);
ptr += 4;
memcpy(ptr, &t0, sizeof t0);
ptr += sizeof t0;
memcpy(ptr, &flags, sizeof flags);
ptr += sizeof flags;
memcpy(ptr, &len, sizeof len);
ptr += sizeof len;
vbe32enc(ptr, len);
ptr += 4;
memcpy(ptr, ban, len);
ptr += len;
......@@ -96,14 +91,13 @@ smp_appendban(struct smp_sc *sc, struct smp_signctx *ctx, double t0,
/* Trust that cache_ban.c takes care of locking */
void
SMP_NewBan(double t0, const char *ban)
SMP_NewBan(const uint8_t *ban, unsigned ln)
{
struct smp_sc *sc;
uint32_t l = strlen(ban) + 1;
VTAILQ_FOREACH(sc, &silos, list) {
smp_appendban(sc, &sc->ban1, t0, 0, l, ban);
smp_appendban(sc, &sc->ban2, t0, 0, l, ban);
smp_appendban(sc, &sc->ban1, ln, ban);
smp_appendban(sc, &sc->ban2, ln, ban);
}
}
......@@ -115,8 +109,7 @@ static int
smp_open_bans(struct smp_sc *sc, struct smp_signctx *ctx)
{
uint8_t *ptr, *pe;
double t0;
uint32_t flags, length;
uint32_t length;
int i, retval = 0;
ASSERT_CLI();
......@@ -134,29 +127,15 @@ smp_open_bans(struct smp_sc *sc, struct smp_signctx *ctx)
}
ptr += 4;
memcpy(&t0, ptr, sizeof t0);
ptr += sizeof t0;
memcpy(&flags, ptr, sizeof flags);
ptr += sizeof flags;
if (flags != 0) {
retval = 1002;
break;
}
length = vbe32dec(ptr);
ptr += 4;
memcpy(&length, ptr, sizeof length);
ptr += sizeof length;
if (ptr + length > pe) {
retval = 1003;
break;
}
if (ptr[length - 1] != '\0') {
retval = 1004;
break;
}
BAN_Reload(t0, flags, (const char *)ptr);
BAN_Reload(ptr, length);
ptr += length;
}
......@@ -523,7 +502,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
memcpy(so->hash, oc->objhead->digest, DIGEST_LEN);
so->ttl = EXP_Grace(NULL, o);
so->ptr = (uint8_t*)o - sc->base;
so->ban = o->ban_t;
so->ban = BAN_Time(oc->ban);
smp_init_oc(oc, sg, objidx);
......
......@@ -463,11 +463,11 @@ smp_oc_updatemeta(struct objcore *oc)
if (sg == sg->sc->cur_seg) {
/* Lock necessary, we might race close_seg */
Lck_Lock(&sg->sc->mtx);
so->ban = o->ban_t;
so->ban = BAN_Time(oc->ban);
so->ttl = mttl;
Lck_Unlock(&sg->sc->mtx);
} else {
so->ban = o->ban_t;
so->ban = BAN_Time(oc->ban);
so->ttl = mttl;
}
}
......
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