Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Split BAN_RefBan into BAN_FindBan and BAN_RefBan
Browse files Browse the repository at this point in the history
BAN_FindBan looks up a ban based on a ban timestamp and returns a
pointer to the ban. Returns NULL if no ban with that timestamp is
present.

BAN_RefBan takes an objcore and a ban. It grabs a reference to the ban
and associates the objcore with that ban.
  • Loading branch information
mbgrydeland committed Feb 23, 2016
1 parent eacc469 commit bfb5813
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bin/varnishd/cache/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ void BAN_Abandon(struct ban_proto *b);
void BAN_Hold(void);
void BAN_Release(void);
void BAN_Reload(const uint8_t *ban, unsigned len);
struct ban *BAN_RefBan(struct objcore *oc, double t0);
struct ban *BAN_FindBan(double t0);
void BAN_RefBan(struct objcore *oc, struct ban *);
double BAN_Time(const struct ban *ban);

/* cache_busyobj.c */
Expand Down
28 changes: 22 additions & 6 deletions bin/varnishd/cache/cache_ban.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,29 +249,45 @@ BAN_DestroyObj(struct objcore *oc)
}

/*--------------------------------------------------------------------
* Find and/or Grab a reference to an objects ban based on timestamp
* Find a ban based on timestamp a ban timestamp.
* Assume we have a BAN_Hold, so list traversal is safe.
*/

struct ban *
BAN_RefBan(struct objcore *oc, double t0)
BAN_FindBan(double t0)
{
struct ban *b;
double t1 = 0;
double t1;

assert(ban_holds > 0);
VTAILQ_FOREACH(b, &ban_head, list) {
t1 = ban_time(b->spec);
if (t1 == t0)
return (b);
if (t1 <= t0)
break;
}
AN(b);
assert(t1 == t0);
return (NULL);
}

/*--------------------------------------------------------------------
* Grab a reference to a ban and associate the objcore with that ban.
* Assume we have a BAN_Hold, so list traversal is safe.
*/

void
BAN_RefBan(struct objcore *oc, struct ban *b)
{

Lck_Lock(&ban_mtx);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
AZ(oc->ban);
CHECK_OBJ_NOTNULL(b, BAN_MAGIC);
assert(ban_holds > 0);
b->refcount++;
VTAILQ_INSERT_TAIL(&b->objcore, oc, ban_list);
oc->ban = b;
Lck_Unlock(&ban_mtx);
return (b);
}

/*--------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion bin/varnishd/storage/storage_persistent_silo.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
{
struct smp_object *so;
struct objcore *oc;
struct ban *ban;
uint32_t no;
double t_now = VTIM_real();
struct smp_signctx ctx[1];
Expand All @@ -159,13 +160,16 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
for (;no > 0; so++,no--) {
if (EXP_WHEN(so) < t_now)
continue;
ban = BAN_FindBan(so->ban);
AN(ban);
oc = ObjNew(wrk);
oc->flags &= ~OC_F_BUSY;
oc->stobj->stevedore = sc->parent;
smp_init_oc(oc, sg, no);
VTAILQ_INSERT_TAIL(&sg->objcores, oc, lru_list);
oc->stobj->priv2 |= NEED_FIXUP;
oc->ban = BAN_RefBan(oc, so->ban);
BAN_RefBan(oc, ban);
AN(oc->ban);
EXP_COPY(oc, so);
sg->nobj++;
oc->refcnt++;
Expand Down

0 comments on commit bfb5813

Please sign in to comment.