r3464 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu Dec 18 11:04:16 CET 2008


Author: phk
Date: 2008-12-18 11:04:15 +0100 (Thu, 18 Dec 2008)
New Revision: 3464

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_expire.c
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_pipe.c
   trunk/varnish-cache/bin/varnishd/hash_slinger.h
Log:
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: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-12-18 09:47:05 UTC (rev 3463)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-12-18 10:04:15 UTC (rev 3464)
@@ -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: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2008-12-18 09:47:05 UTC (rev 3463)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2008-12-18 10:04:15 UTC (rev 3464)
@@ -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: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2008-12-18 09:47:05 UTC (rev 3463)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2008-12-18 10:04:15 UTC (rev 3464)
@@ -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: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2008-12-18 09:47:05 UTC (rev 3463)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2008-12-18 10:04:15 UTC (rev 3464)
@@ -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: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2008-12-18 09:47:05 UTC (rev 3463)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2008-12-18 10:04:15 UTC (rev 3464)
@@ -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: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-12-18 09:47:05 UTC (rev 3463)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2008-12-18 10:04:15 UTC (rev 3464)
@@ -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: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c	2008-12-18 09:47:05 UTC (rev 3463)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c	2008-12-18 10:04:15 UTC (rev 3464)
@@ -96,8 +96,7 @@
 		return;
 	}
 
-	VBE_free_bereq(bereq);
-	bereq = NULL;
+	VBE_free_bereq(&bereq);
 
 	sp->t_resp = TIM_real();
 

Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_slinger.h	2008-12-18 09:47:05 UTC (rev 3463)
+++ trunk/varnish-cache/bin/varnishd/hash_slinger.h	2008-12-18 10:04:15 UTC (rev 3464)
@@ -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