[master] bfb5813 Split BAN_RefBan into BAN_FindBan and BAN_RefBan
Martin Blix Grydeland
martin at varnish-software.com
Tue Feb 23 17:44:46 CET 2016
commit bfb5813ef441c1da6d89603571d34a2edf9bc29c
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Tue Feb 23 16:23:58 2016 +0100
Split BAN_RefBan into BAN_FindBan and BAN_RefBan
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.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index d735df2..cbeccbf 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -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 */
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index f091abf..aa4c68f 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -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);
}
/*--------------------------------------------------------------------
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 9478702..0e1637f 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -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];
@@ -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++;
More information about the varnish-commit
mailing list