diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 8627c7a95f5..728d8a4b639 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -276,6 +276,41 @@ hsh_testmagic(void *result) fprintf(stderr, ">\n"); } +/*--------------------------------------------------------------------- + */ + +static int +hsh_check_bans_locked(struct worker *wrk, struct objcore *oc, struct req *req) +{ + struct objhead *oh; + + oh = oc->objhead; + Lck_AssertHeld(&oh->mtx); + + return (BAN_CheckObject(wrk, oc, req) > 0); +} + +void +HSH_CheckBans(struct worker *wrk, struct objcore *oc) +{ + struct objhead *oh; + + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); + oh = oc->objhead; + CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + + if (oc->flags & OC_F_DYING) + return; + + Lck_Lock(&oh->mtx); + if (hsh_check_bans_locked(wrk, oc, NULL)) { + oc->flags |= OC_F_DYING; + EXP_Remove(oc, NULL); + } + Lck_Unlock(&oh->mtx); +} + /*--------------------------------------------------------------------- * Insert an object which magically appears out of nowhere or, more likely, * comes off some persistent storage device. @@ -451,7 +486,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp) if (oc->ttl <= 0.) continue; - if (BAN_CheckObject(wrk, oc, req)) { + if (hsh_check_bans_locked(wrk, oc, req)) { oc->flags |= OC_F_DYING; EXP_Remove(oc, NULL); continue; diff --git a/bin/varnishd/cache/cache_objhead.h b/bin/varnishd/cache/cache_objhead.h index 2edfb5a883b..1821a3b59b4 100644 --- a/bin/varnishd/cache/cache_objhead.h +++ b/bin/varnishd/cache/cache_objhead.h @@ -86,3 +86,4 @@ unsigned HSH_Purge(struct worker *, struct objhead *, vtim_real ttl_now, vtim_dur ttl, vtim_dur grace, vtim_dur keep); struct objcore *HSH_Private(const struct worker *wrk); void HSH_Cancel(struct worker *, struct objcore *, struct boc *); +void HSH_CheckBans(struct worker *, struct objcore *);