Commit b4aef74f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

A minor preemptive cleanup before the ban-lurker gets remodelled.

parent 561be2ef
...@@ -445,6 +445,7 @@ struct objcore { ...@@ -445,6 +445,7 @@ struct objcore {
#define OC_F_PASS (1<<2) #define OC_F_PASS (1<<2)
#define OC_F_LRUDONTMOVE (1<<4) #define OC_F_LRUDONTMOVE (1<<4)
#define OC_F_PRIV (1<<5) /* Stevedore private flag */ #define OC_F_PRIV (1<<5) /* Stevedore private flag */
#define OC_F_LURK (3<<6) /* Ban-lurker-color */
unsigned timer_idx; unsigned timer_idx;
VTAILQ_ENTRY(objcore) list; VTAILQ_ENTRY(objcore) list;
VTAILQ_ENTRY(objcore) lru_list; VTAILQ_ENTRY(objcore) lru_list;
......
...@@ -81,6 +81,7 @@ struct ban { ...@@ -81,6 +81,7 @@ struct ban {
unsigned flags; unsigned flags;
#define BAN_F_GONE (1 << 0) #define BAN_F_GONE (1 << 0)
#define BAN_F_REQ (1 << 2) #define BAN_F_REQ (1 << 2)
#define BAN_F_LURK (3 << 3) /* ban-lurker-color */
VTAILQ_HEAD(,objcore) objcore; VTAILQ_HEAD(,objcore) objcore;
struct vsb *vsb; struct vsb *vsb;
uint8_t *spec; uint8_t *spec;
...@@ -164,23 +165,6 @@ BAN_Free(struct ban *b) ...@@ -164,23 +165,6 @@ BAN_Free(struct ban *b)
FREE_OBJ(b); FREE_OBJ(b);
} }
static struct ban *
ban_CheckLast(void)
{
struct ban *b;
Lck_AssertHeld(&ban_mtx);
b = VTAILQ_LAST(&ban_head, banhead_s);
if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) {
VSC_C_main->n_ban--;
VSC_C_main->n_ban_retire++;
VTAILQ_REMOVE(&ban_head, b, list);
} else {
b = NULL;
}
return (b);
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Get & Release a tail reference, used to hold the list stable for * Get & Release a tail reference, used to hold the list stable for
* traversals etc. * traversals etc.
...@@ -473,7 +457,6 @@ BAN_NewObjCore(struct objcore *oc) ...@@ -473,7 +457,6 @@ BAN_NewObjCore(struct objcore *oc)
void void
BAN_DestroyObj(struct objcore *oc) BAN_DestroyObj(struct objcore *oc)
{ {
struct ban *b;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
if (oc->ban == NULL) if (oc->ban == NULL)
...@@ -484,12 +467,7 @@ BAN_DestroyObj(struct objcore *oc) ...@@ -484,12 +467,7 @@ BAN_DestroyObj(struct objcore *oc)
oc->ban->refcount--; oc->ban->refcount--;
VTAILQ_REMOVE(&oc->ban->objcore, oc, ban_list); VTAILQ_REMOVE(&oc->ban->objcore, oc, ban_list);
oc->ban = NULL; oc->ban = NULL;
/* Attempt to purge last ban entry */
b = ban_CheckLast();
Lck_Unlock(&ban_mtx); Lck_Unlock(&ban_mtx);
if (b != NULL)
BAN_Free(b);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -750,6 +728,23 @@ BAN_CheckObject(struct object *o, const struct sess *sp) ...@@ -750,6 +728,23 @@ BAN_CheckObject(struct object *o, const struct sess *sp)
return (ban_check_object(o, sp, 1)); return (ban_check_object(o, sp, 1));
} }
static struct ban *
ban_CheckLast(void)
{
struct ban *b;
Lck_AssertHeld(&ban_mtx);
b = VTAILQ_LAST(&ban_head, banhead_s);
if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) {
VSC_C_main->n_ban--;
VSC_C_main->n_ban_retire++;
VTAILQ_REMOVE(&ban_head, b, list);
} else {
b = NULL;
}
return (b);
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Ban tail lurker thread * Ban tail lurker thread
*/ */
...@@ -763,9 +758,6 @@ ban_lurker_work(const struct sess *sp) ...@@ -763,9 +758,6 @@ ban_lurker_work(const struct sess *sp)
struct object *o; struct object *o;
int i; int i;
WSL_Flush(sp->wrk, 0);
WRK_SumStat(sp->wrk);
Lck_Lock(&ban_mtx); Lck_Lock(&ban_mtx);
/* First try to route the last ban */ /* First try to route the last ban */
...@@ -831,21 +823,34 @@ ban_lurker_work(const struct sess *sp) ...@@ -831,21 +823,34 @@ ban_lurker_work(const struct sess *sp)
static void * __match_proto__(bgthread_t) static void * __match_proto__(bgthread_t)
ban_lurker(struct sess *sp, void *priv) ban_lurker(struct sess *sp, void *priv)
{ {
struct ban *bf;
int i = 0; int i = 0;
(void)priv; (void)priv;
while (1) { while (1) {
if (params->ban_lurker_sleep == 0.0) {
/* Lurker is disabled. */ while (params->ban_lurker_sleep == 0.0) {
VTIM_sleep(1.0); /*
continue; * Ban-lurker is disabled:
* Clean the last ban, if possible, and sleep
*/
Lck_Lock(&ban_mtx);
bf = ban_CheckLast();
Lck_Unlock(&ban_mtx);
if (bf != NULL)
BAN_Free(bf);
else
VTIM_sleep(1.0);
} }
i = ban_lurker_work(sp);
WSL_Flush(sp->wrk, 0);
WRK_SumStat(sp->wrk);
if (i != 0) if (i != 0)
VTIM_sleep(params->ban_lurker_sleep); VTIM_sleep(params->ban_lurker_sleep);
else else
VTIM_sleep(1.0); VTIM_sleep(1.0);
i = ban_lurker_work(sp);
WSL_Flush(sp->wrk, 0);
WRK_SumStat(sp->wrk);
} }
NEEDLESS_RETURN(NULL); NEEDLESS_RETURN(NULL);
} }
...@@ -957,10 +962,11 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv) ...@@ -957,10 +962,11 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv)
/* Get a reference so we are safe to traverse the list */ /* Get a reference so we are safe to traverse the list */
bl = BAN_TailRef(); bl = BAN_TailRef();
VCLI_Out(cli, "Present bans:\n");
VTAILQ_FOREACH(b, &ban_head, list) { VTAILQ_FOREACH(b, &ban_head, list) {
if (b == bl) if (b == bl)
break; break;
VCLI_Out(cli, "%p %10.6f %5u%s\t", b, ban_time(b->spec), VCLI_Out(cli, "%10.6f %5u%s\t", ban_time(b->spec),
bl == b ? b->refcount - 1 : b->refcount, bl == b ? b->refcount - 1 : b->refcount,
b->flags & BAN_F_GONE ? "G" : " "); b->flags & BAN_F_GONE ? "G" : " ");
ban_render(cli, b->spec); ban_render(cli, b->spec);
......
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