Skip to content

Commit

Permalink
hash: New HSH_CheckBans() convenience
Browse files Browse the repository at this point in the history
This function is a thin wrapper around hsh_check_bans_locked() that
behaves just like BAN_CheckObject() used to before it got folded into
ban_check_object() in 5eeabe7.

It will allow evaluating bans outside of a lookup now that bans with
request criteria can be skipped (again) in BAN_CheckObject().
  • Loading branch information
dridi committed Mar 18, 2024
1 parent 8a81990 commit 46cdfce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
37 changes: 36 additions & 1 deletion bin/varnishd/cache/cache_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
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 46cdfce

Please sign in to comment.