Commit 4c2344ba authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Add a facility to export a complete ban list to the stevedores. Call

this on startup, after reading the persisted ban lists, to make sure
all stevedores has all the bans from every stevedore stored.
parent 53e74e4d
......@@ -1061,6 +1061,7 @@ void STV_open(void);
void STV_close(void);
void STV_Freestore(struct object *o);
int STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len);
void STV_BanExport(const uint8_t *bans, unsigned len);
/* storage_synth.c */
struct vsb *SMS_Makesynth(struct object *obj);
......
......@@ -573,6 +573,29 @@ BAN_RefBan(struct objcore *oc, double t0, const struct ban *tail)
return (b);
}
/*--------------------------------------------------------------------
* Compile a full ban list and export this area to the stevedores for
* persistence.
*/
static void
ban_export(void)
{
struct ban *b;
struct vsb vsb;
Lck_AssertHeld(&ban_mtx);
/* XXX: Use the ban entry size measurements to hit the target
* and avoid multiple allocations */
AN(VSB_new(&vsb, NULL, 64 * VSC_C_main->bans, VSB_AUTOEXTEND));
VTAILQ_FOREACH_REVERSE(b, &ban_head, banhead_s, list) {
AZ(VSB_bcat(&vsb, b->spec, ban_len(b->spec)));
}
AZ(VSB_finish(&vsb));
STV_BanExport((const uint8_t *)VSB_data(&vsb), VSB_len(&vsb));
VSB_delete(&vsb);
}
/*--------------------------------------------------------------------
* Put a skeleton ban in the list, unless there is an identical,
* time & condition, ban already in place.
......@@ -689,9 +712,17 @@ BAN_Compile(void)
ASSERT_CLI();
AZ(ban_shutdown);
Lck_Lock(&ban_mtx);
/* Do late reporting of ban_magic */
AZ(STV_BanInfo(BI_NEW, ban_magic->spec, ban_len(ban_magic->spec)));
/* All bans have been read from all persistent stevedores. Export
the compiled list */
ban_export();
Lck_Unlock(&ban_mtx);
ban_start = VTAILQ_FIRST(&ban_head);
WRK_BgThread(&ban_thread, "ban-lurker", ban_lurker, NULL);
}
......
......@@ -472,6 +472,22 @@ STV_BanInfo(enum baninfo event, const uint8_t *ban, unsigned len)
return (r);
}
/*-------------------------------------------------------------------
* Export a complete ban list to the stevedores for persistence.
* The stevedores should clear any previous ban lists and replace
* them with this list.
*/
void
STV_BanExport(const uint8_t *bans, unsigned len)
{
struct stevedore *stv;
VTAILQ_FOREACH(stv, &stv_stevedores, list)
if (stv->banexport != NULL)
stv->banexport(stv, bans, len);
}
/*--------------------------------------------------------------------
* VRT functions for stevedores
*/
......
......@@ -50,6 +50,8 @@ typedef void storage_close_f(const struct stevedore *);
typedef void storage_signal_close_f(const struct stevedore *);
typedef int storage_baninfo_f(struct stevedore *, enum baninfo event,
const uint8_t *ban, unsigned len);
typedef void storage_banexport_f(struct stevedore *, const uint8_t *bans,
unsigned len);
/* Prototypes for VCL variable responders */
#define VRTSTVTYPE(ct) typedef ct storage_var_##ct(const struct stevedore *);
......@@ -74,6 +76,7 @@ struct stevedore {
storage_allocobj_f *allocobj; /* --//-- */
storage_signal_close_f *signal_close; /* --//-- */
storage_baninfo_f *baninfo; /* --//-- */
storage_banexport_f *banexport; /* --//-- */
struct lru *lru;
......
......@@ -107,6 +107,26 @@ smp_baninfo(struct stevedore *stv, enum baninfo event,
return (r);
}
static void
smp_banexport_spc(struct smp_signspace *spc, const uint8_t *bans, unsigned len)
{
smp_reset_signspace(spc);
assert(SIGNSPACE_FREE(spc) >= len);
memcpy(SIGNSPACE_DATA(spc), bans, len);
smp_append_signspace(spc, len);
smp_sync_sign(&spc->ctx);
}
static void
smp_banexport(struct stevedore *stv, const uint8_t *bans, unsigned len)
{
struct smp_sc *sc;
CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
smp_banexport_spc(&sc->ban1, bans, len);
smp_banexport_spc(&sc->ban2, bans, len);
}
/*--------------------------------------------------------------------
* Attempt to open and read in a ban list
*/
......@@ -579,6 +599,7 @@ const struct stevedore smp_stevedore = {
.free = smp_free,
.signal_close = smp_signal_close,
.baninfo = smp_baninfo,
.banexport = smp_banexport,
};
/*--------------------------------------------------------------------
......
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