Commit 218de765 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move the ban pointer to objcore, as long planned.

Clean up assert for proper use of busy flag



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5552 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 2e849df0
...@@ -383,7 +383,6 @@ struct object { ...@@ -383,7 +383,6 @@ struct object {
unsigned char *vary; unsigned char *vary;
double ban_t; double ban_t;
struct ban *ban; /* XXX --> objcore */
unsigned response; unsigned response;
unsigned cacheable; unsigned cacheable;
...@@ -549,7 +548,7 @@ void BAN_Free(struct ban *b); ...@@ -549,7 +548,7 @@ void BAN_Free(struct ban *b);
void BAN_Insert(struct ban *b); void BAN_Insert(struct ban *b);
void BAN_Init(void); void BAN_Init(void);
void BAN_NewObj(struct object *o); void BAN_NewObj(struct object *o);
void BAN_DestroyObj(struct object *o); void BAN_DestroyObj(struct objcore *oc);
int BAN_CheckObject(struct object *o, const struct sess *sp); int BAN_CheckObject(struct object *o, const struct sess *sp);
void BAN_Reload(double t0, unsigned flags, const char *ban); void BAN_Reload(double t0, unsigned flags, const char *ban);
struct ban *BAN_TailRef(void); struct ban *BAN_TailRef(void);
...@@ -832,10 +831,16 @@ Tadd(txt *t, const char *p, int l) ...@@ -832,10 +831,16 @@ Tadd(txt *t, const char *p, int l)
} }
} }
static inline unsigned static inline void
ObjIsBusy(const struct object *o) AssertObjBusy(const struct object *o)
{
AN(o->objcore);
AN (o->objcore->flags & OC_F_BUSY);
}
static inline void
AssertObjPassOrBusy(const struct object *o)
{ {
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); if (o->objcore != NULL)
CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC); AN (o->objcore->flags & OC_F_BUSY);
return (o->objcore->flags & OC_F_BUSY);
} }
...@@ -359,16 +359,18 @@ BAN_Insert(struct ban *b) ...@@ -359,16 +359,18 @@ BAN_Insert(struct ban *b)
void void
BAN_NewObj(struct object *o) BAN_NewObj(struct object *o)
{ {
struct objcore *oc;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC); oc = o->objcore;
AZ(o->ban); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
AZ(oc->ban);
Lck_Lock(&ban_mtx); Lck_Lock(&ban_mtx);
o->ban = ban_start; oc->ban = ban_start;
ban_start->refcount++; ban_start->refcount++;
VTAILQ_INSERT_TAIL(&ban_start->objcore, o->objcore, ban_list); VTAILQ_INSERT_TAIL(&ban_start->objcore, oc, ban_list);
Lck_Unlock(&ban_mtx); Lck_Unlock(&ban_mtx);
o->ban_t = o->ban->t0; o->ban_t = oc->ban->t0;
} }
static struct ban * static struct ban *
...@@ -389,19 +391,19 @@ BAN_CheckLast(void) ...@@ -389,19 +391,19 @@ BAN_CheckLast(void)
} }
void void
BAN_DestroyObj(struct object *o) BAN_DestroyObj(struct objcore *oc)
{ {
struct ban *b; struct ban *b;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
if (o->ban == NULL) if (oc->ban == NULL)
return; return;
CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC); CHECK_OBJ_NOTNULL(oc->ban, BAN_MAGIC);
Lck_Lock(&ban_mtx); Lck_Lock(&ban_mtx);
assert(o->ban->refcount > 0); assert(oc->ban->refcount > 0);
o->ban->refcount--; oc->ban->refcount--;
VTAILQ_REMOVE(&o->ban->objcore, o->objcore, ban_list); VTAILQ_REMOVE(&oc->ban->objcore, oc, ban_list);
o->ban = NULL; oc->ban = NULL;
/* Attempt to purge last ban entry */ /* Attempt to purge last ban entry */
b = BAN_CheckLast(); b = BAN_CheckLast();
...@@ -415,17 +417,20 @@ static int ...@@ -415,17 +417,20 @@ static int
ban_check_object(struct object *o, const struct sess *sp, int has_req) ban_check_object(struct object *o, const struct sess *sp, int has_req)
{ {
struct ban *b; struct ban *b;
struct objcore *oc;
struct ban_test *bt; struct ban_test *bt;
struct ban * volatile b0; struct ban * volatile b0;
unsigned tests; unsigned tests;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC); oc = o->objcore;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(oc->ban, BAN_MAGIC);
b0 = ban_start; b0 = ban_start;
if (b0 == o->ban) if (b0 == oc->ban)
return (0); return (0);
/* /*
...@@ -434,7 +439,7 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req) ...@@ -434,7 +439,7 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req)
* inspect the list past that ban. * inspect the list past that ban.
*/ */
tests = 0; tests = 0;
for (b = b0; b != o->ban; b = VTAILQ_NEXT(b, list)) { for (b = b0; b != oc->ban; b = VTAILQ_NEXT(b, list)) {
if (b->flags & BAN_F_GONE) if (b->flags & BAN_F_GONE)
continue; continue;
if (!has_req && (b->flags & BAN_F_REQ)) if (!has_req && (b->flags & BAN_F_REQ))
...@@ -449,26 +454,26 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req) ...@@ -449,26 +454,26 @@ ban_check_object(struct object *o, const struct sess *sp, int has_req)
} }
Lck_Lock(&ban_mtx); Lck_Lock(&ban_mtx);
o->ban->refcount--; oc->ban->refcount--;
VTAILQ_REMOVE(&o->ban->objcore, o->objcore, ban_list); VTAILQ_REMOVE(&oc->ban->objcore, oc, ban_list);
if (b == o->ban) { /* not banned */ if (b == oc->ban) { /* not banned */
VTAILQ_INSERT_TAIL(&b0->objcore, o->objcore, ban_list); VTAILQ_INSERT_TAIL(&b0->objcore, oc, ban_list);
b0->refcount++; b0->refcount++;
} }
VSC_main->n_purge_obj_test++; VSC_main->n_purge_obj_test++;
VSC_main->n_purge_re_test += tests; VSC_main->n_purge_re_test += tests;
Lck_Unlock(&ban_mtx); Lck_Unlock(&ban_mtx);
if (b == o->ban) { /* not banned */ if (b == oc->ban) { /* not banned */
o->ban = b0; oc->ban = b0;
o->ban_t = o->ban->t0; o->ban_t = oc->ban->t0;
oc_updatemeta(o->objcore); oc_updatemeta(oc);
return (0); return (0);
} else { } else {
o->ttl = 0; o->ttl = 0;
o->cacheable = 0; o->cacheable = 0;
o->ban = NULL; oc->ban = NULL;
oc_updatemeta(o->objcore); oc_updatemeta(oc);
/* BAN also changed, but that is not important any more */ /* BAN also changed, but that is not important any more */
WSP(sp, SLT_ExpBan, "%u was banned", o->xid); WSP(sp, SLT_ExpBan, "%u was banned", o->xid);
EXP_Rearm(o); EXP_Rearm(o);
......
...@@ -671,7 +671,8 @@ cnt_fetch(struct sess *sp) ...@@ -671,7 +671,8 @@ cnt_fetch(struct sess *sp)
sp->obj->cacheable = 1; sp->obj->cacheable = 1;
if (sp->wrk->cacheable) { if (sp->wrk->cacheable) {
EXP_Insert(sp->obj); EXP_Insert(sp->obj);
AN(sp->obj->ban); AN(sp->obj->objcore);
AN(sp->obj->objcore->ban);
HSH_Unbusy(sp); HSH_Unbusy(sp);
} }
sp->acct_tmp.fetch++; sp->acct_tmp.fetch++;
......
...@@ -704,8 +704,7 @@ ESI_Parse(struct sess *sp) ...@@ -704,8 +704,7 @@ ESI_Parse(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
if (sp->obj->objcore != NULL) /* Pass has no objcore */ AssertObjPassOrBusy(sp->obj);
AN(ObjIsBusy(sp->obj));
if (VTAILQ_EMPTY(&sp->obj->store)) if (VTAILQ_EMPTY(&sp->obj->store))
return; return;
......
...@@ -125,10 +125,10 @@ EXP_Insert(struct object *o) ...@@ -125,10 +125,10 @@ EXP_Insert(struct object *o)
struct lru *lru; struct lru *lru;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC);
AN(ObjIsBusy(o));
assert(o->cacheable);
oc = o->objcore; oc = o->objcore;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
AssertObjBusy(o);
assert(o->cacheable);
HSH_Ref(oc); HSH_Ref(oc);
assert(o->entered != 0 && !isnan(o->entered)); assert(o->entered != 0 && !isnan(o->entered));
......
...@@ -469,8 +469,7 @@ FetchBody(struct sess *sp) ...@@ -469,8 +469,7 @@ FetchBody(struct sess *sp)
/* We use the unmodified headers */ /* We use the unmodified headers */
hp = sp->wrk->beresp1; hp = sp->wrk->beresp1;
AN(sp->director); AN(sp->director);
if (sp->obj->objcore != NULL) /* pass has no objcore */ AssertObjPassOrBusy(sp->obj);
AN(ObjIsBusy(sp->obj));
/* /*
* Determine if we have a body or not * Determine if we have a body or not
......
...@@ -127,7 +127,7 @@ HSH_Object(const struct sess *sp) ...@@ -127,7 +127,7 @@ HSH_Object(const struct sess *sp)
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj->objstore, STORAGE_MAGIC); CHECK_OBJ_NOTNULL(sp->obj->objstore, STORAGE_MAGIC);
CHECK_OBJ_NOTNULL(sp->obj->objstore->stevedore, STEVEDORE_MAGIC); CHECK_OBJ_NOTNULL(sp->obj->objstore->stevedore, STEVEDORE_MAGIC);
AN(ObjIsBusy(sp->obj)); AssertObjBusy(sp->obj);
if (sp->obj->objstore->stevedore->object != NULL) if (sp->obj->objstore->stevedore->object != NULL)
sp->obj->objstore->stevedore->object(sp); sp->obj->objstore->stevedore->object(sp);
} }
...@@ -605,12 +605,9 @@ HSH_Drop(struct sess *sp) ...@@ -605,12 +605,9 @@ HSH_Drop(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
o = sp->obj; o = sp->obj;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
if (o->objcore != NULL) { /* Pass has no objcore */ AssertObjPassOrBusy(o);
assert(o->objcore->refcnt > 0);
AN(ObjIsBusy(o));
o->ttl = 0;
}
o->cacheable = 0; o->cacheable = 0;
o->ttl = 0;
if (o->objcore != NULL) /* Pass has no objcore */ if (o->objcore != NULL) /* Pass has no objcore */
HSH_Unbusy(sp); HSH_Unbusy(sp);
(void)HSH_Deref(sp->wrk, NULL, &sp->obj); (void)HSH_Deref(sp->wrk, NULL, &sp->obj);
...@@ -621,18 +618,20 @@ HSH_Unbusy(const struct sess *sp) ...@@ -621,18 +618,20 @@ HSH_Unbusy(const struct sess *sp)
{ {
struct object *o; struct object *o;
struct objhead *oh; struct objhead *oh;
struct objcore *oc;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
o = sp->obj; o = sp->obj;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC); oc = o->objcore;
oh = o->objcore->objhead; CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
oh = oc->objhead;
CHECK_OBJ(oh, OBJHEAD_MAGIC); CHECK_OBJ(oh, OBJHEAD_MAGIC);
AN(ObjIsBusy(o)); AssertObjBusy(o);
AN(o->ban); AN(oc->ban);
assert(oc_getobj(sp->wrk, o->objcore) == o); assert(oc_getobj(sp->wrk, oc) == o);
assert(o->objcore->refcnt > 0); assert(oc->refcnt > 0);
assert(oh->refcnt > 0); assert(oh->refcnt > 0);
if (o->ws_o->overflow) if (o->ws_o->overflow)
sp->wrk->stats.n_objoverflow++; sp->wrk->stats.n_objoverflow++;
...@@ -642,9 +641,9 @@ HSH_Unbusy(const struct sess *sp) ...@@ -642,9 +641,9 @@ HSH_Unbusy(const struct sess *sp)
Lck_Lock(&oh->mtx); Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0); assert(oh->refcnt > 0);
o->objcore->flags &= ~OC_F_BUSY; oc->flags &= ~OC_F_BUSY;
hsh_rush(oh); hsh_rush(oh);
AN(o->ban); AN(oc->ban);
Lck_Unlock(&oh->mtx); Lck_Unlock(&oh->mtx);
} }
...@@ -715,9 +714,10 @@ HSH_Deref(struct worker *w, struct objcore *oc, struct object **oo) ...@@ -715,9 +714,10 @@ HSH_Deref(struct worker *w, struct objcore *oc, struct object **oo)
} }
if (o != NULL) { if (o != NULL) {
if (oc != NULL) if (oc != NULL) {
BAN_DestroyObj(o); BAN_DestroyObj(oc);
AZ(o->ban); AZ(oc->ban);
}
DSL(0x40, SLT_Debug, 0, "Object %u workspace min free %u", DSL(0x40, SLT_Debug, 0, "Object %u workspace min free %u",
o->xid, WS_Free(o->ws_o)); o->xid, WS_Free(o->ws_o));
......
...@@ -678,7 +678,6 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc) ...@@ -678,7 +678,6 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc)
/* refcnt is one because the object is in the hash */ /* refcnt is one because the object is in the hash */
o->objcore = oc; o->objcore = oc;
o->ban = oc->ban;
sg->nfixed++; sg->nfixed++;
wrk->stats.n_object++; wrk->stats.n_object++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment