[master] 5894995 Always allocate a request before calling CNT_Session()

Poul-Henning Kamp phk at varnish-cache.org
Mon Jun 25 11:03:43 CEST 2012


commit 5894995f139a4cf9b131978d83508450dbe836e4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jun 25 09:03:12 2012 +0000

    Always allocate a request before calling CNT_Session()

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 646ee9d..1d83dab 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -744,7 +744,7 @@ void VBO_Free(struct busyobj **vbo);
 
 /* cache_center.c [CNT] */
 int CNT_Request(struct worker *, struct req *);
-void CNT_Session(struct worker *, struct sess *);
+void CNT_Session(struct worker *, struct req *);
 void CNT_Init(void);
 
 /* cache_cli.c [CLI] */
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 88eef23..5c76ac9 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -117,11 +117,8 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req)
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 
-	if (req == NULL) {
-		req = SES_GetReq(sp);
-		CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	}
 	assert(req->sp == sp);
 
 	if (!sp->init_done) {
@@ -327,13 +324,17 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req)
  */
 
 void
-CNT_Session(struct worker *wrk, struct sess *sp)
+CNT_Session(struct worker *wrk, struct req *req)
 {
 	int done;
+	struct sess *sp;
 	enum cnt_sess_done_ret sdr;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	sp = req->sp;
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	assert(sp->req == req);
 
 	/*
 	 * Whenever we come in from the acceptor or waiter, we need to set
@@ -348,7 +349,7 @@ CNT_Session(struct worker *wrk, struct sess *sp)
 			SES_Close(sp, "remote closed");
 		else
 			SES_Close(sp, "error");
-		sdr = cnt_sess_done(sp, wrk, sp->req);
+		sdr = cnt_sess_done(sp, wrk, req);
 		assert(sdr == SESS_DONE_RET_GONE);
 		return;
 	}
@@ -357,18 +358,19 @@ CNT_Session(struct worker *wrk, struct sess *sp)
 		/*
 		 * Possible entrance states
 		 */
+		assert(sp->req == req);
+
 		assert(
 		    sp->sess_step == S_STP_NEWREQ ||
-		    (sp->req != NULL &&
-		    (sp->req->req_step == R_STP_LOOKUP ||
-		    sp->req->req_step == R_STP_START)));
+		    req->req_step == R_STP_LOOKUP ||
+		    req->req_step == R_STP_START);
 
 		if (sp->sess_step == S_STP_WORKING) {
-			done = CNT_Request(wrk, sp->req);
+			done = CNT_Request(wrk, req);
 			if (done == 2)
 				return;
 			assert(done == 1);
-			sdr = cnt_sess_done(sp, wrk, sp->req);
+			sdr = cnt_sess_done(sp, wrk, req);
 			switch (sdr) {
 			case SESS_DONE_RET_GONE:
 				return;
@@ -377,7 +379,7 @@ CNT_Session(struct worker *wrk, struct sess *sp)
 				break;
 			case SESS_DONE_RET_START:
 				sp->sess_step = S_STP_WORKING;
-				sp->req->req_step = R_STP_START;
+				req->req_step = R_STP_START;
 				break;
 			default:
 				WRONG("Illegal enum cnt_sess_done_ret");
@@ -385,12 +387,11 @@ CNT_Session(struct worker *wrk, struct sess *sp)
 		}
 
 		if (sp->sess_step == S_STP_NEWREQ) {
-			done = cnt_wait(sp, wrk, sp->req);
-			if (done) {
+			done = cnt_wait(sp, wrk, req);
+			if (done)
 				return;
-			}
 			sp->sess_step = S_STP_WORKING;
-			sp->req->req_step = R_STP_START;
+			req->req_step = R_STP_START;
 		}
 	}
 }
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 9bf3382..2b384f6 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -124,16 +124,18 @@ ses_new(struct sesspool *pp)
 static void
 ses_pool_task(struct worker *wrk, void *arg)
 {
+	struct req *req;
 	struct sess *sp;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-	CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC);
+	CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC);
+	sp = req->sp;
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 
 	AZ(wrk->aws->r);
 	wrk->lastused = NAN;
 	THR_SetSession(sp);
-	CNT_Session(wrk, sp);
-	sp = NULL;			/* Cannot access sp any longer */
+	CNT_Session(wrk, req);
 	THR_SetSession(NULL);
 	WS_Assert(wrk->aws);
 	AZ(wrk->wrw);
@@ -151,6 +153,7 @@ void
 SES_pool_accept_task(struct worker *wrk, void *arg)
 {
 	struct sesspool *pp;
+	struct req *req;
 	struct sess *sp;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -161,11 +164,13 @@ SES_pool_accept_task(struct worker *wrk, void *arg)
 	sp = ses_new(pp);
 	if (sp == NULL) {
 		VCA_FailSess(wrk);
-	} else {
-		VCA_SetupSess(wrk, sp);
-		sp->sess_step = S_STP_NEWREQ;
-		ses_pool_task(wrk, sp);
-	}
+		return;
+	} 
+	VCA_SetupSess(wrk, sp);
+	sp->sess_step = S_STP_NEWREQ;
+	req = SES_GetReq(sp);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	ses_pool_task(wrk, req);
 }
 
 /*--------------------------------------------------------------------
@@ -186,7 +191,7 @@ SES_ScheduleReq(struct req *req)
 	AN(pp->pool);
 
 	sp->task.func = ses_pool_task;
-	sp->task.priv = sp;
+	sp->task.priv = req;
 
 	if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) {
 		VSC_C_main->client_drop_late++;
@@ -206,6 +211,7 @@ SES_ScheduleReq(struct req *req)
 void
 SES_Handle(struct sess *sp, double now)
 {
+	struct req *req;
 	struct sesspool *pp;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -213,8 +219,10 @@ SES_Handle(struct sess *sp, double now)
 	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
 	AN(pp->pool);
 	AZ(sp->req);
+	req = SES_GetReq(sp);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	sp->task.func = ses_pool_task;
-	sp->task.priv = sp;
+	sp->task.priv = req;
 	sp->sess_step = S_STP_NEWREQ;
 	sp->t_rx = now;
 	if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) {



More information about the varnish-commit mailing list