Commit 445f3c53 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Generalize the ban reporting to the stevedores using their API. This

way any stevedore interested in new bans can request to be notified
(not just the persistent).

Also report dropped bans to the stevedores.
parent c6e3eae7
......@@ -188,6 +188,15 @@ enum httpwhence {
HTTP_Obj
};
/*--------------------------------------------------------------------
* Ban info event types
*/
enum baninfo {
BI_NEW,
BI_DROP
};
/* NB: remember to update http_Copy() if you add fields */
struct http {
unsigned magic;
......@@ -1054,6 +1063,7 @@ void STV_free(struct storage *st);
void STV_open(void);
void STV_close(void);
void STV_Freestore(struct object *o);
void STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len);
/* storage_synth.c */
struct vsb *SMS_Makesynth(struct object *obj);
......@@ -1063,7 +1073,6 @@ void SMS_Init(void);
/* storage_persistent.c */
void SMP_Init(void);
void SMP_Ready(void);
void SMP_NewBan(const uint8_t *ban, unsigned len);
/*
* A normal pointer difference is signed, but we never want a negative value
......
......@@ -66,6 +66,7 @@
#include <stdio.h>
#include "cache.h"
#include "storage/storage.h"
#include "hash/hash_slinger.h"
#include "vcli.h"
......@@ -413,7 +414,7 @@ BAN_Insert(struct ban *b)
else
be = NULL;
SMP_NewBan(b->spec, ln);
STV_BanInfo(BI_NEW, b->spec, ln); /* Notify stevedores */
Lck_Unlock(&ban_mtx);
if (be == NULL)
......@@ -595,7 +596,9 @@ BAN_Compile(void)
ASSERT_CLI();
SMP_NewBan(ban_magic->spec, ban_len(ban_magic->spec));
/* Notify stevedores */
STV_BanInfo(BI_NEW, ban_magic->spec, ban_len(ban_magic->spec));
ban_start = VTAILQ_FIRST(&ban_head);
WRK_BgThread(&ban_thread, "ban-lurker", ban_lurker, NULL);
}
......@@ -812,6 +815,9 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl, unsigned pass)
do {
Lck_Lock(&ban_mtx);
b2 = ban_CheckLast();
if (b2 != NULL)
/* Notify stevedores */
STV_BanInfo(BI_DROP, b2->spec, ban_len(b2->spec));
Lck_Unlock(&ban_mtx);
if (b2 != NULL)
BAN_Free(b2);
......@@ -959,6 +965,10 @@ ban_lurker(struct worker *wrk, void *priv)
*/
Lck_Lock(&ban_mtx);
bf = ban_CheckLast();
if (bf != NULL)
/* Notify stevedores */
STV_BanInfo(BI_DROP, bf->spec,
ban_len(bf->spec));
Lck_Unlock(&ban_mtx);
if (bf != NULL)
BAN_Free(bf);
......
......@@ -453,6 +453,15 @@ STV_close(void)
stv->close(stv);
}
void
STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len)
{
struct stevedore *stv;
VTAILQ_FOREACH(stv, &stv_stevedores, list)
if (stv->baninfo != NULL)
stv->baninfo(stv, event, ban, len);
}
/*--------------------------------------------------------------------
* VRT functions for stevedores
......
......@@ -38,6 +38,7 @@ struct busyobj;
struct objcore;
struct worker;
struct lru;
enum baninfo;
typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
typedef void storage_open_f(const struct stevedore *);
......@@ -48,6 +49,8 @@ typedef struct object *storage_allocobj_f(struct stevedore *, struct busyobj *,
struct objcore **, unsigned ltot, const struct stv_objsecrets *);
typedef void storage_close_f(const struct stevedore *);
typedef void storage_signal_close_f(const struct stevedore *);
typedef void storage_baninfo_f(struct stevedore *, enum baninfo event,
const uint8_t *ban, unsigned len);
/* Prototypes for VCL variable responders */
#define VRTSTVTYPE(ct) typedef ct storage_var_##ct(const struct stevedore *);
......@@ -71,6 +74,7 @@ struct stevedore {
storage_close_f *close; /* --//-- */
storage_allocobj_f *allocobj; /* --//-- */
storage_signal_close_f *signal_close; /* --//-- */
storage_baninfo_f *baninfo; /* --//-- */
struct lru *lru;
......
......@@ -92,14 +92,23 @@ smp_appendban(struct smp_sc *sc, struct smp_signspace *spc,
/* Trust that cache_ban.c takes care of locking */
void
SMP_NewBan(const uint8_t *ban, unsigned ln)
static void
smp_baninfo(struct stevedore *stv, enum baninfo event,
const uint8_t *ban, unsigned len)
{
struct smp_sc *sc;
VTAILQ_FOREACH(sc, &silos, list) {
smp_appendban(sc, &sc->ban1, ln, ban);
smp_appendban(sc, &sc->ban2, ln, ban);
(void)stv;
switch (event) {
case BI_NEW:
VTAILQ_FOREACH(sc, &silos, list) {
smp_appendban(sc, &sc->ban1, len, ban);
smp_appendban(sc, &sc->ban2, len, ban);
}
break;
default:
/* Ignored */
break;
}
}
......@@ -584,6 +593,7 @@ const struct stevedore smp_stevedore = {
.allocobj = smp_allocobj,
.free = smp_free,
.signal_close = smp_signal_close,
.baninfo = smp_baninfo,
};
/*--------------------------------------------------------------------
......
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