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