From: phk Date: Thu, 18 Dec 2008 10:04:15 +0000 (+0000) Subject: A bit of cleanup while I ponder ticket 412: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c196d7b74195f8da524199641cc5146fe7c919f;p=varnish A bit of cleanup while I ponder ticket 412: make VBE_free_bereq() and HSH_Deref() null their argument pointer. Add HSH_Drop() for deorbiting unwanted busy objects. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3464 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 8803dba5..aeee3d55 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -407,7 +407,7 @@ void VBE_GetFd(struct sess *sp); void VBE_ClosedFd(struct sess *sp); void VBE_RecycleFd(struct sess *sp); struct bereq * VBE_new_bereq(void); -void VBE_free_bereq(struct bereq *bereq); +void VBE_free_bereq(struct bereq **bereq); void VBE_AddHostHeader(const struct sess *sp); void VBE_Poll(void); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index ee6eb207..e691b534 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -172,8 +172,13 @@ VBE_new_bereq(void) */ void -VBE_free_bereq(struct bereq *bereq) +VBE_free_bereq(struct bereq **bereqp) { + struct bereq *bereq; + + AN(bereqp); + bereq = *bereqp; + *bereqp = NULL; CHECK_OBJ_NOTNULL(bereq, BEREQ_MAGIC); WS_Reset(bereq->ws, NULL); diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 8a5a07c9..e16ecc36 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -177,8 +177,7 @@ cnt_deliver(struct sess *sp) RES_WriteObj(sp); AZ(sp->wrk->wfd); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Deref(&sp->obj); sp->step = STP_DONE; return (0); } @@ -391,13 +390,9 @@ cnt_fetch(struct sess *sp) if (i) { sp->err_code = 503; sp->step = STP_ERROR; - VBE_free_bereq(sp->bereq); - sp->bereq = NULL; - sp->obj->ttl = 0; - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; + VBE_free_bereq(&sp->bereq); + HSH_Drop(sp); + AZ(sp->obj); return (0); } @@ -406,16 +401,11 @@ cnt_fetch(struct sess *sp) sp->err_code = http_GetStatus(sp->obj->http); VCL_fetch_method(sp); - VBE_free_bereq(sp->bereq); - sp->bereq = NULL; + VBE_free_bereq(&sp->bereq); switch (sp->handling) { case VCL_RET_RESTART: - sp->obj->ttl = 0; - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Drop(sp); sp->director = NULL; sp->restarts++; sp->step = STP_RECV; @@ -427,11 +417,7 @@ cnt_fetch(struct sess *sp) break; case VCL_RET_ERROR: sp->step = STP_ERROR; - sp->obj->ttl = 0; - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Drop(sp); return (0); default: WRONG("Illegal action in vcl_fetch{}"); @@ -535,8 +521,7 @@ cnt_hit(struct sess *sp) } /* Drop our object, we won't need it */ - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Deref(&sp->obj); switch(sp->handling) { case VCL_RET_PASS: @@ -625,8 +610,7 @@ cnt_lookup(struct sess *sp) if (sp->obj->pass) { VSL_stats->cache_hitpass++; WSP(sp, SLT_HitPass, "%u", sp->obj->xid); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Deref(&sp->obj); sp->step = STP_PASS; return (0); } @@ -670,24 +654,17 @@ cnt_miss(struct sess *sp) http_FilterHeader(sp, HTTPH_R_FETCH); VCL_miss_method(sp); + AZ(sp->obj->cacheable); switch(sp->handling) { case VCL_RET_ERROR: - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; - VBE_free_bereq(sp->bereq); - sp->bereq = NULL; + HSH_Drop(sp); + VBE_free_bereq(&sp->bereq); sp->step = STP_ERROR; return (0); case VCL_RET_PASS: - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Drop(sp); + VBE_free_bereq(&sp->bereq); sp->step = STP_PASS; - VBE_free_bereq(sp->bereq); - sp->bereq = NULL; return (0); case VCL_RET_FETCH: sp->step = STP_FETCH; diff --git a/varnish-cache/bin/varnishd/cache_expire.c b/varnish-cache/bin/varnishd/cache_expire.c index 4fa9b067..458ba74e 100644 --- a/varnish-cache/bin/varnishd/cache_expire.c +++ b/varnish-cache/bin/varnishd/cache_expire.c @@ -337,7 +337,7 @@ exp_timer(void *arg) VSL_stats->n_expired++; Lck_Unlock(&exp_mtx); del_objexp(o); - HSH_Deref(o); + HSH_Deref(&o); } } } @@ -406,7 +406,7 @@ EXP_NukeOne(struct sess *sp) if (sp->handling == VCL_RET_DISCARD) { WSL(sp->wrk, SLT_ExpKill, 0, "%u LRU", o->xid); del_objexp(o); - HSH_Deref(o); + HSH_Deref(&o); return (1); } diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 83fbbda3..7d90c5f1 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -322,7 +322,7 @@ Fetch(struct sess *sp) CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC); AN(sp->director); - assert(sp->obj->busy != 0); + AN(sp->obj->busy); w = sp->wrk; bereq = sp->bereq; hp = bereq->http; diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 083027fb..9f49c465 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -378,6 +378,22 @@ hsh_rush(struct objhead *oh) } } +void +HSH_Drop(struct sess *sp) +{ + struct object *o; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + o = sp->obj; + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + assert(o->busy); + assert(o->refcnt > 0); + o->ttl = 0; + o->cacheable = 0; + HSH_Unbusy(sp); + HSH_Deref(&sp->obj); +} + void HSH_Unbusy(const struct sess *sp) { @@ -411,7 +427,7 @@ HSH_Unbusy(const struct sess *sp) if (oh != NULL) Lck_Unlock(&oh->mtx); if (parent != NULL) - HSH_Deref(parent); + HSH_Deref(&parent); } void @@ -429,11 +445,15 @@ HSH_Ref(struct object *o) } void -HSH_Deref(struct object *o) +HSH_Deref(struct object **oo) { + struct object *o; struct objhead *oh; unsigned r; + AN(oo); + o = *oo; + *oo = NULL; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oh = o->objhead; if (oh != NULL) { diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index 6be1dd1d..5ed25ff2 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -96,8 +96,7 @@ PipeSession(struct sess *sp) return; } - VBE_free_bereq(bereq); - bereq = NULL; + VBE_free_bereq(&bereq); sp->t_resp = TIM_real(); diff --git a/varnish-cache/bin/varnishd/hash_slinger.h b/varnish-cache/bin/varnishd/hash_slinger.h index 81dfcf1f..4ae04b5d 100644 --- a/varnish-cache/bin/varnishd/hash_slinger.h +++ b/varnish-cache/bin/varnishd/hash_slinger.h @@ -56,7 +56,8 @@ void HSH_Copy(const struct sess *sp, struct objhead *o); struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(const struct sess *sp); void HSH_Ref(struct object *o); -void HSH_Deref(struct object *o); +void HSH_Deref(struct object **o); +void HSH_Drop(struct sess *sp); double HSH_Grace(double g); void HSH_Init(void); void HSH_AddString(struct sess *sp, const char *str);