[master] 09bf441 Mostly move sp->wrk to req->wrk

Poul-Henning Kamp phk at varnish-cache.org
Mon Jun 25 10:00:06 CEST 2012


commit 09bf441ebdd412d0b77001343273699c2391e54f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jun 25 07:59:54 2012 +0000

    Mostly move sp->wrk to req->wrk

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 3673823..3a8559f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -568,6 +568,7 @@ struct req {
 	uint8_t			hash_always_miss;
 
 	struct sess		*sp;
+	struct worker		*wrk;
 	enum req_step		req_step;
 	VTAILQ_ENTRY(req)	w_list;
 
@@ -744,7 +745,7 @@ void VBO_Free(struct busyobj **vbo);
 
 /* cache_center.c [CNT] */
 int CNT_Request(struct worker *, struct req *);
-void CNT_Session(struct sess *);
+void CNT_Session(struct worker *, struct sess *);
 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 24e6e37..1eb397e 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -323,15 +323,13 @@ cnt_sess_done(struct sess *sp, struct worker *wrk, struct req *req)
  */
 
 void
-CNT_Session(struct sess *sp)
+CNT_Session(struct worker *wrk, struct sess *sp)
 {
 	int done;
 	enum cnt_sess_done_ret sdr;
-	struct worker *wrk;
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	wrk = sp->wrk;
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 
 	/*
 	 * Whenever we come in from the acceptor or waiter, we need to set
@@ -363,8 +361,10 @@ CNT_Session(struct sess *sp)
 
 		if (sp->sess_step == S_STP_WORKING) {
 			done = CNT_Request(sp->wrk, sp->req);
-			if (done == 2)
+			if (done == 2) {
+				sp->wrk = NULL;
 				return;
+			}
 			assert(done == 1);
 			sdr = cnt_sess_done(sp, wrk, sp->req);
 			switch (sdr) {
@@ -1598,6 +1598,8 @@ CNT_Request(struct worker *wrk, struct req *req)
 	    req->req_step == R_STP_START ||
 	    req->req_step == R_STP_RECV);
 
+	req->wrk = wrk;
+
 	for (done = 0; !done; ) {
 		/*
 		 * This is a good place to be paranoid about the various
@@ -1626,6 +1628,8 @@ CNT_Request(struct worker *wrk, struct req *req)
 	if (done == 1)
 		SES_Charge(req->sp);
 
+	req->wrk = NULL;
+
 	assert(WRW_IsReleased(wrk));
 	return (done);
 }
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 7f06dd4..7e4305e 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -51,7 +51,7 @@ ved_include(struct req *req, const char *src, const char *host)
 	unsigned sxid, res_mode;
 	int i;
 
-	wrk = req->sp->wrk;
+	wrk = req->wrk;
 
 	if (req->esi_level >= cache_param->max_esi_depth)
 		return;
@@ -94,17 +94,17 @@ ved_include(struct req *req, const char *src, const char *host)
 
 	sxid = req->xid;
 	while (1) {
-		req->sp->wrk = wrk;
+		req->wrk = wrk;
 		i = CNT_Request(wrk, req);
 		if (i == 1)
 			break;
 		assert(i == 2);
-		AZ(req->sp->wrk);
+		AZ(req->wrk);
 		DSL(0x20, SLT_Debug, req->sp->vsl_id, "loop waiting for ESI");
 		(void)usleep(10000);
 	}
 	req->xid = sxid;
-	AN(req->sp->wrk);
+	req->wrk = wrk;
 	req->esi_level--;
 	req->obj = obj;
 	req->res_mode = res_mode;
@@ -113,9 +113,9 @@ ved_include(struct req *req, const char *src, const char *host)
 	WS_Reset(req->ws, sp_ws_wm);
 	WS_Reset(wrk->aws, wrk_ws_wm);	/* XXX ? */
 
-	WRW_Reserve(req->sp->wrk, &req->sp->fd, req->vsl, req->t_resp);
+	WRW_Reserve(req->wrk, &req->sp->fd, req->vsl, req->t_resp);
 	if (req->res_mode & RES_CHUNKED)
-		WRW_Chunked(req->sp->wrk);
+		WRW_Chunked(req->wrk);
 }
 
 /*--------------------------------------------------------------------*/
@@ -185,22 +185,22 @@ ved_pretend_gzip(struct req *req, const uint8_t *p, ssize_t l)
 	while (l > 0) {
 		if (l >= 65535) {
 			lx = 65535;
-			(void)WRW_Write(req->sp->wrk, buf1, sizeof buf1);
+			(void)WRW_Write(req->wrk, buf1, sizeof buf1);
 		} else {
 			lx = (uint16_t)l;
 			buf2[0] = 0;
 			vle16enc(buf2 + 1, lx);
 			vle16enc(buf2 + 3, ~lx);
-			(void)WRW_Write(req->sp->wrk, buf2, sizeof buf2);
+			(void)WRW_Write(req->wrk, buf2, sizeof buf2);
 		}
-		(void)WRW_Write(req->sp->wrk, p, lx);
+		(void)WRW_Write(req->wrk, p, lx);
 		req->crc = crc32(req->crc, p, lx);
 		req->l_crc += lx;
 		l -= lx;
 		p += lx;
 	}
 	/* buf2 is local, have to flush */
-	(void)WRW_Flush(req->sp->wrk);
+	(void)WRW_Flush(req->wrk);
 }
 
 /*---------------------------------------------------------------------
@@ -250,7 +250,7 @@ ESI_Deliver(struct req *req)
 		if (isgzip && !(req->res_mode & RES_GUNZIP)) {
 			assert(sizeof gzip_hdr == 10);
 			/* Send out the gzip header */
-			(void)WRW_Write(req->sp->wrk, gzip_hdr, 10);
+			(void)WRW_Write(req->wrk, gzip_hdr, 10);
 			req->l_crc = 0;
 			req->gzip_resp = 1;
 			req->crc = crc32(0L, Z_NULL, 0);
@@ -306,7 +306,7 @@ ESI_Deliver(struct req *req)
 					 * We have a gzip'ed VEC and delivers
 					 * a gzip'ed ESI response.
 					 */
-					(void)WRW_Write(req->sp->wrk,
+					(void)WRW_Write(req->wrk,
 					    st->ptr + off, l2);
 				} else if (req->gzip_resp) {
 					/*
@@ -321,9 +321,9 @@ ESI_Deliver(struct req *req)
 					 * response
 					 */
 					AN(vgz);
-					i = VGZ_WrwGunzip(req->sp->wrk, vgz,
+					i = VGZ_WrwGunzip(req->wrk, vgz,
 						st->ptr + off, l2);
-					if (WRW_Error(req->sp->wrk)) {
+					if (WRW_Error(req->wrk)) {
 						SES_Close(req->sp,
 						    "remote closed");
 						p = e;
@@ -334,7 +334,7 @@ ESI_Deliver(struct req *req)
 					/*
 					 * Ungzip'ed VEC, ungzip'ed ESI response
 					 */
-					(void)WRW_Write(req->sp->wrk,
+					(void)WRW_Write(req->wrk,
 					    st->ptr + off, l2);
 				}
 				off += l2;
@@ -374,8 +374,8 @@ ESI_Deliver(struct req *req)
 			r = (void*)strchr((const char*)q, '\0');
 			AN(r);
 			if (vgz != NULL)
-				VGZ_WrwFlush(req->sp->wrk, vgz);
-			if (WRW_Flush(req->sp->wrk)) {
+				VGZ_WrwFlush(req->wrk, vgz);
+			if (WRW_Flush(req->wrk)) {
 				SES_Close(req->sp, "remote closed");
 				p = e;
 				break;
@@ -391,7 +391,7 @@ ESI_Deliver(struct req *req)
 		}
 	}
 	if (vgz != NULL) {
-		VGZ_WrwFlush(req->sp->wrk, vgz);
+		VGZ_WrwFlush(req->wrk, vgz);
 		(void)VGZ_Destroy(&vgz);
 	}
 	if (req->gzip_resp && req->esi_level == 0) {
@@ -408,9 +408,9 @@ ESI_Deliver(struct req *req)
 		/* MOD(2^32) length */
 		vle32enc(tailbuf + 9, req->l_crc);
 
-		(void)WRW_Write(req->sp->wrk, tailbuf, 13);
+		(void)WRW_Write(req->wrk, tailbuf, 13);
 	}
-	(void)WRW_Flush(req->sp->wrk);
+	(void)WRW_Flush(req->wrk);
 }
 
 /*---------------------------------------------------------------------
@@ -444,7 +444,7 @@ ved_deliver_byterange(const struct req *req, ssize_t low, ssize_t high)
 			l = high - lx;
 		assert(lx >= low && lx + l <= high);
 		if (l != 0)
-			(void)WRW_Write(req->sp->wrk, p, l);
+			(void)WRW_Write(req->wrk, p, l);
 		if (p + l < st->ptr + st->len)
 			return(p[l]);
 		lx += l;
@@ -499,7 +499,7 @@ ESI_DeliverChild(struct req *req)
 	 */
 	*dbits = ved_deliver_byterange(req, start/8, last/8);
 	*dbits &= ~(1U << (last & 7));
-	(void)WRW_Write(req->sp->wrk, dbits, 1);
+	(void)WRW_Write(req->wrk, dbits, 1);
 	cc = ved_deliver_byterange(req, 1 + last/8, stop/8);
 	switch((int)(stop & 7)) {
 	case 0: /* xxxxxxxx */
@@ -543,7 +543,7 @@ ESI_DeliverChild(struct req *req)
 		INCOMPL();
 	}
 	if (lpad > 0)
-		(void)WRW_Write(req->sp->wrk, dbits + 1, lpad);
+		(void)WRW_Write(req->wrk, dbits + 1, lpad);
 
 	/* We need the entire tail, but it may not be in one storage segment */
 	st = VTAILQ_LAST(&req->obj->store, storagehead);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 0e2fa5f..ab2aabc 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -406,8 +406,8 @@ FetchReqBody(struct req *req, int sendbody)
 			content_length -= rdcnt;
 			if (sendbody) {
 				/* XXX: stats ? */
-				(void)WRW_Write(req->sp->wrk, buf, rdcnt);
-				if (WRW_Flush(req->sp->wrk))
+				(void)WRW_Write(req->wrk, buf, rdcnt);
+				if (WRW_Flush(req->wrk))
 					return (2);
 			}
 		}
@@ -441,7 +441,7 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody)
 	int i;
 	struct http_conn *htc;
 
-	wrk = req->sp->wrk;
+	wrk = req->wrk;
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	bo = req->busyobj;
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index e7c2a49..c6f56e3 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -299,7 +299,7 @@ HSH_Lookup(struct req *req)
 	int busy_found;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	wrk = req->sp->wrk;
+	wrk = req->wrk;
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(req->http, HTTP_MAGIC);
 	AN(req->director);
@@ -431,7 +431,6 @@ HSH_Lookup(struct req *req)
 		 * calls us again
 		 */
 		req->hash_objhead = oh;
-		req->sp->wrk = NULL;
 		Lck_Unlock(&oh->mtx);
 		return (NULL);
 	}
@@ -482,9 +481,9 @@ hsh_rush(struct dstat *ds, struct objhead *oh)
 		if (req == NULL)
 			break;
 		CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+		AZ(req->wrk);
 		sp = req->sp;
 		CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-		AZ(sp->wrk);
 		VTAILQ_REMOVE(&wl->list, req, w_list);
 		DSL(0x20, SLT_Debug, sp->vsl_id, "off waiting list");
 		if (SES_Schedule(sp)) {
@@ -533,7 +532,7 @@ HSH_Purge(struct req *req, struct objhead *oh, double ttl, double grace)
 			continue;
 		}
 
-		(void)oc_getobj(&req->sp->wrk->stats, oc);
+		(void)oc_getobj(&req->wrk->stats, oc);
 		    /* XXX: still needed ? */
 
 		xxxassert(spc >= sizeof *ocp);
@@ -551,14 +550,14 @@ HSH_Purge(struct req *req, struct objhead *oh, double ttl, double grace)
 	for (n = 0; n < nobj; n++) {
 		oc = ocp[n];
 		CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-		o = oc_getobj(&req->sp->wrk->stats, oc);
+		o = oc_getobj(&req->wrk->stats, oc);
 		if (o == NULL)
 			continue;
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 		o->exp.ttl = ttl;
 		o->exp.grace = grace;
 		EXP_Rearm(o);
-		(void)HSH_Deref(&req->sp->wrk->stats, NULL, &o);
+		(void)HSH_Deref(&req->wrk->stats, NULL, &o);
 	}
 	WS_Release(req->ws, 0);
 }
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index c4511e8..411b8e9 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -261,8 +261,8 @@ pan_req(const struct req *req)
 	VSB_printf(pan_vsp, "  restarts = %d, esi_level = %d\n",
 	    req->restarts, req->esi_level);
 
-	if (req->busyobj != NULL)
-		pan_busyobj(req->busyobj);
+	if (req->wrk != NULL)
+		pan_wrk(req->wrk);
 
 	pan_ws(req->ws, 2);
 	pan_http("req", req->http, 2);
@@ -272,6 +272,9 @@ pan_req(const struct req *req)
 	if (VALID_OBJ(req->vcl, VCL_CONF_MAGIC))
 		pan_vcl(req->vcl);
 
+	if (req->busyobj != NULL)
+		pan_busyobj(req->busyobj);
+
 	if (VALID_OBJ(req->obj, OBJECT_MAGIC))
 		pan_object(req->obj);
 
@@ -302,9 +305,6 @@ pan_sess(const struct sess *sp)
 	else
 		VSB_printf(pan_vsp, "  step = 0x%x,\n", sp->sess_step);
 
-	if (sp->wrk != NULL)
-		pan_wrk(sp->wrk);
-
 	VSB_printf(pan_vsp, "},\n");
 }
 
diff --git a/bin/varnishd/cache/cache_pipe.c b/bin/varnishd/cache/cache_pipe.c
index 13a8c10..8fa9e3c 100644
--- a/bin/varnishd/cache/cache_pipe.c
+++ b/bin/varnishd/cache/cache_pipe.c
@@ -70,7 +70,7 @@ PipeRequest(struct req *req)
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
-	wrk = req->sp->wrk;
+	wrk = req->wrk;
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	bo = req->busyobj;
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
diff --git a/bin/varnishd/cache/cache_response.c b/bin/varnishd/cache/cache_response.c
index 85c8233..cdad653 100644
--- a/bin/varnishd/cache/cache_response.c
+++ b/bin/varnishd/cache/cache_response.c
@@ -171,11 +171,11 @@ res_WriteGunzipObj(struct req *req)
 		CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
 		u += st->len;
 
-		i = VGZ_WrwGunzip(req->sp->wrk, vg, st->ptr, st->len);
+		i = VGZ_WrwGunzip(req->wrk, vg, st->ptr, st->len);
 		/* XXX: error check */
 		(void)i;
 	}
-	VGZ_WrwFlush(req->sp->wrk, vg);
+	VGZ_WrwFlush(req->wrk, vg);
 	(void)VGZ_Destroy(&vg);
 	assert(u == req->obj->len);
 }
@@ -215,8 +215,8 @@ res_WriteDirObj(const struct req *req, ssize_t low, ssize_t high)
 
 		ptr += len;
 
-		req->sp->wrk->acct_tmp.bodybytes += len;
-		(void)WRW_Write(req->sp->wrk, st->ptr + off, len);
+		req->wrk->acct_tmp.bodybytes += len;
+		(void)WRW_Write(req->wrk, st->ptr + off, len);
 	}
 	assert(u == req->obj->len);
 }
@@ -248,20 +248,20 @@ RES_WriteObj(struct req *req)
 	    http_GetHdr(req->http, H_Range, &r))
 		res_dorange(req, r, &low, &high);
 
-	WRW_Reserve(req->sp->wrk, &req->sp->fd, req->vsl, req->t_resp);
+	WRW_Reserve(req->wrk, &req->sp->fd, req->vsl, req->t_resp);
 
 	/*
 	 * Send HTTP protocol header, unless interior ESI object
 	 */
 	if (!(req->res_mode & RES_ESI_CHILD))
-		req->sp->wrk->acct_tmp.hdrbytes +=
-		    http_Write(req->sp->wrk, req->resp, 1);
+		req->wrk->acct_tmp.hdrbytes +=
+		    http_Write(req->wrk, req->resp, 1);
 
 	if (!req->wantbody)
 		req->res_mode &= ~RES_CHUNKED;
 
 	if (req->res_mode & RES_CHUNKED)
-		WRW_Chunked(req->sp->wrk);
+		WRW_Chunked(req->wrk);
 
 	if (!req->wantbody) {
 		/* This was a HEAD or conditional request */
@@ -282,8 +282,8 @@ RES_WriteObj(struct req *req)
 
 	if (req->res_mode & RES_CHUNKED &&
 	    !(req->res_mode & RES_ESI_CHILD))
-		WRW_EndChunk(req->sp->wrk);
+		WRW_EndChunk(req->wrk);
 
-	if (WRW_FlushRelease(req->sp->wrk) && req->sp->fd >= 0)
+	if (WRW_FlushRelease(req->wrk) && req->sp->fd >= 0)
 		SES_Close(req->sp, "remote closed");
 }
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index aee58b0..01b0b18 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -128,7 +128,7 @@ ses_pool_task(struct worker *wrk, void *arg)
 	THR_SetSession(sp);
 	AZ(sp->wrk);
 	sp->wrk = wrk;
-	CNT_Session(sp);
+	CNT_Session(wrk, sp);
 	sp = NULL;			/* Cannot access sp any longer */
 	THR_SetSession(NULL);
 	WS_Assert(wrk->aws);



More information about the varnish-commit mailing list