Skip to content

Commit

Permalink
hash: New HSH_CheckBans() convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
dridi committed Mar 15, 2024
1 parent 85614e3 commit 44827f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
34 changes: 33 additions & 1 deletion bin/varnishd/cache/cache_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,38 @@ 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);

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.
Expand Down Expand Up @@ -451,7 +483,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;
Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/cache/cache_objhead.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

0 comments on commit 44827f5

Please sign in to comment.