[master] 90846c4 Remove sp->req, sessions can now (almost) have more than one request at a time, paving the way for a lot of future fun...

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


commit 90846c4aa1c7be8bc9abbb7b78a2f589fc5638fd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jun 25 09:13:29 2012 +0000

    Remove sp->req, sessions can now (almost) have more than one request
    at a time, paving the way for a lot of future fun...
    
    It's painfully obvious that I set about doing this the wrong way:
    I should have renamed sess to req and made a new sess structure,
    that would have been much simpler.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 1d83dab..1d991f1 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -660,7 +660,6 @@ struct sess {
 	/* Cross references ------------------------------------------*/
 
 	struct sesspool		*sesspool;
-	struct req		*req;
 
 	struct pool_task	task;
 	VTAILQ_ENTRY(sess)	list;
@@ -866,8 +865,6 @@ void THR_SetName(const char *name);
 const char* THR_GetName(void);
 void THR_SetRequest(const struct req *);
 const struct req * THR_GetRequest(void);
-void THR_SetSession(const struct sess *);
-const struct sess * THR_GetSession(void);
 
 /* cache_lck.c */
 
@@ -930,7 +927,6 @@ struct sesspool *SES_NewPool(struct pool *pp, unsigned pool_no);
 void SES_DeletePool(struct sesspool *sp);
 int SES_ScheduleReq(struct req *);
 void SES_Handle(struct sess *sp, double now);
-struct req *SES_GetReq(struct sess *sp);
 void SES_ReleaseReq(struct req *);
 pool_func_t SES_pool_accept_task;
 
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 5c76ac9..004f815 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -334,7 +334,6 @@ CNT_Session(struct worker *wrk, struct req *req)
 	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
@@ -358,7 +357,6 @@ CNT_Session(struct worker *wrk, struct req *req)
 		/*
 		 * Possible entrance states
 		 */
-		assert(sp->req == req);
 
 		assert(
 		    sp->sess_step == S_STP_NEWREQ ||
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 041578b..20d12bc 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -49,20 +49,6 @@ static pthread_key_t sp_key;
 static pthread_key_t req_key;
 
 void
-THR_SetSession(const struct sess *sp)
-{
-
-	AZ(pthread_setspecific(sp_key, sp));
-}
-
-const struct sess *
-THR_GetSession(void)
-{
-
-	return (pthread_getspecific(sp_key));
-}
-
-void
 THR_SetRequest(const struct req *req)
 {
 
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 411b8e9..94b2aee 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -57,6 +57,8 @@
 static struct vsb pan_vsp_storage, *pan_vsp;
 static pthread_mutex_t panicstr_mtx = PTHREAD_MUTEX_INITIALIZER;
 
+static void pan_sess(const struct sess *sp);
+
 /*--------------------------------------------------------------------*/
 
 static void
@@ -261,6 +263,9 @@ pan_req(const struct req *req)
 	VSB_printf(pan_vsp, "  restarts = %d, esi_level = %d\n",
 	    req->restarts, req->esi_level);
 
+	if (req->sp != NULL)
+		pan_sess(req->sp);
+
 	if (req->wrk != NULL)
 		pan_wrk(req->wrk);
 
@@ -343,7 +348,6 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
     int err, int xxx)
 {
 	const char *q;
-	const struct sess *sp;
 	const struct req *req;
 
 	AZ(pthread_mutex_lock(&panicstr_mtx)); /* Won't be released,
@@ -385,9 +389,6 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 	pan_backtrace();
 
 	if (!(cache_param->diag_bitmap & 0x2000)) {
-		sp = THR_GetSession();
-		if (sp != NULL)
-			pan_sess(sp);
 		req = THR_GetRequest();
 		if (req != NULL)
 			pan_req(req);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 2b384f6..15b2d9a 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -46,6 +46,8 @@
 
 static unsigned ses_size = sizeof (struct sess);
 
+static struct req * ses_GetReq(struct sess *sp);
+
 /*--------------------------------------------------------------------*/
 
 struct sesspool {
@@ -134,9 +136,7 @@ ses_pool_task(struct worker *wrk, void *arg)
 
 	AZ(wrk->aws->r);
 	wrk->lastused = NAN;
-	THR_SetSession(sp);
 	CNT_Session(wrk, req);
-	THR_SetSession(NULL);
 	WS_Assert(wrk->aws);
 	AZ(wrk->wrw);
 	if (cache_param->diag_bitmap & 0x00040000) {
@@ -168,7 +168,7 @@ SES_pool_accept_task(struct worker *wrk, void *arg)
 	} 
 	VCA_SetupSess(wrk, sp);
 	sp->sess_step = S_STP_NEWREQ;
-	req = SES_GetReq(sp);
+	req = ses_GetReq(sp);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	ses_pool_task(wrk, req);
 }
@@ -218,8 +218,7 @@ SES_Handle(struct sess *sp, double now)
 	pp = sp->sesspool;
 	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
 	AN(pp->pool);
-	AZ(sp->req);
-	req = SES_GetReq(sp);
+	req = ses_GetReq(sp);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	sp->task.func = ses_pool_task;
 	sp->task.priv = req;
@@ -266,7 +265,6 @@ SES_Delete(struct sess *sp, const char *reason, double now)
 	struct sesspool *pp;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	AZ(sp->req);
 	pp = sp->sesspool;
 	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
 	AN(pp->pool);
@@ -296,11 +294,11 @@ SES_Delete(struct sess *sp, const char *reason, double now)
 }
 
 /*--------------------------------------------------------------------
- * Alloc/Free sp->req
+ * Alloc/Free a request
  */
 
-struct req *
-SES_GetReq(struct sess *sp)
+static struct req *
+ses_GetReq(struct sess *sp)
 {
 	struct sesspool *pp;
 	struct req *req;
@@ -313,11 +311,9 @@ SES_GetReq(struct sess *sp)
 	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
 	AN(pp->pool);
 
-	AZ(sp->req);
 	req = MPL_Get(pp->mpl_req, &sz);
 	AN(req);
 	req->magic = REQ_MAGIC;
-	sp->req = req;
 	req->sp = sp;
 	THR_SetRequest(req);
 
@@ -370,7 +366,6 @@ SES_ReleaseReq(struct req *req)
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	sp = req->sp;
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	assert(sp->req == req);
 	pp = sp->sesspool;
 	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
 	AN(pp->pool);
@@ -379,7 +374,6 @@ SES_ReleaseReq(struct req *req)
 	VSL_Flush(req->vsl, 0);
 	req->sp = NULL;
 	MPL_Free(pp->mpl_req, req);
-	sp->req = NULL;
 	THR_SetRequest(NULL);
 }
 
diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index 3816a26..e89d550 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -67,7 +67,6 @@ WAIT_Enter(struct sess *sp)
 {
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	AZ(sp->req);
 	assert(sp->fd >= 0);
 
 	/*



More information about the varnish-commit mailing list