r3658 - branches/2.0/varnish-cache/bin/varnishd

tfheen at projects.linpro.no tfheen at projects.linpro.no
Fri Feb 6 13:08:44 CET 2009


Author: tfheen
Date: 2009-02-06 13:08:44 +0100 (Fri, 06 Feb 2009)
New Revision: 3658

Modified:
   branches/2.0/varnish-cache/bin/varnishd/cache.h
   branches/2.0/varnish-cache/bin/varnishd/cache_backend.c
   branches/2.0/varnish-cache/bin/varnishd/cache_center.c
   branches/2.0/varnish-cache/bin/varnishd/cache_expire.c
   branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c
   branches/2.0/varnish-cache/bin/varnishd/cache_hash.c
   branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c
   branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h
Log:
Merge r3464: Cleanup

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.



Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache.h	2009-02-06 12:04:59 UTC (rev 3657)
+++ branches/2.0/varnish-cache/bin/varnishd/cache.h	2009-02-06 12:08:44 UTC (rev 3658)
@@ -407,7 +407,7 @@
 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);
 

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_backend.c	2009-02-06 12:04:59 UTC (rev 3657)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_backend.c	2009-02-06 12:08:44 UTC (rev 3658)
@@ -172,9 +172,14 @@
  */
 
 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);
 	Lck_Lock(&VBE_mtx);

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_center.c	2009-02-06 12:04:59 UTC (rev 3657)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c	2009-02-06 12:08:44 UTC (rev 3658)
@@ -177,8 +177,7 @@
 
 	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 @@
 	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 @@
 	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 @@
 		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 @@
 	}
 
 	/* 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 @@
 	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 @@
 
 	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;

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c	2009-02-06 12:04:59 UTC (rev 3657)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c	2009-02-06 12:08:44 UTC (rev 3658)
@@ -337,7 +337,7 @@
 			VSL_stats->n_expired++;
 			Lck_Unlock(&exp_mtx);
 			del_objexp(o);
-			HSH_Deref(o);
+			HSH_Deref(&o);
 		}
 	}
 }
@@ -406,7 +406,7 @@
 	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);
 	}
 

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c	2009-02-06 12:04:59 UTC (rev 3657)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c	2009-02-06 12:08:44 UTC (rev 3658)
@@ -322,7 +322,7 @@
 	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;

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c	2009-02-06 12:04:59 UTC (rev 3657)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c	2009-02-06 12:08:44 UTC (rev 3658)
@@ -379,6 +379,22 @@
 }
 
 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)
 {
 	struct object *o;
@@ -411,7 +427,7 @@
 	if (oh != NULL)
 		Lck_Unlock(&oh->mtx);
 	if (parent != NULL)
-		HSH_Deref(parent);
+		HSH_Deref(&parent);
 }
 
 void
@@ -429,11 +445,15 @@
 }
 
 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) {

Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c	2009-02-06 12:04:59 UTC (rev 3657)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c	2009-02-06 12:08:44 UTC (rev 3658)
@@ -96,8 +96,7 @@
 		return;
 	}
 
-	VBE_free_bereq(bereq);
-	bereq = NULL;
+	VBE_free_bereq(&bereq);
 
 	sp->t_resp = TIM_real();
 

Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h	2009-02-06 12:04:59 UTC (rev 3657)
+++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h	2009-02-06 12:08:44 UTC (rev 3658)
@@ -56,7 +56,8 @@
 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);



More information about the varnish-commit mailing list