[master] 7d9ca7d Eliminate the "first" step, merge it with "wait"

Poul-Henning Kamp phk at varnish-cache.org
Tue Jun 19 13:46:41 CEST 2012


commit 7d9ca7de9a3b7fe44c92431c7a22038897e6acde
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Jun 19 11:46:24 2012 +0000

    Eliminate the "first" step, merge it with "wait"

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 8d45641..5c2c923 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -665,6 +665,7 @@ struct sess {
 	struct sockaddr_storage	sockaddr;
 	struct sockaddr_storage	mysockaddr;
 	struct listen_sock	*mylsock;
+	int			init_done;
 
 	/* formatted ascii client address */
 	char			addr[ADDR_BUFSIZE];
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 0d4e93b..4f97c60 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -80,58 +80,6 @@ DOT acceptor -> first [style=bold,color=green]
 static unsigned xids;
 
 /*--------------------------------------------------------------------
- * A freshly accepted socket
- *
-DOT subgraph xcluster_first {
-DOT	first [
-DOT		shape=box
-DOT		label="cnt_first:\nrender\naddresses"
-DOT	]
-DOT }
-DOT first -> wait [style=bold,color=green]
- */
-
-static int
-cnt_first(struct sess *sp, struct worker *wrk)
-{
-	struct req *req;
-	char laddr[ADDR_BUFSIZE];
-	char lport[PORT_BUFSIZE];
-
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-
-	/* Allocate a request already now, so we can VSL to it */
-	AZ(sp->req);
-	req = SES_GetReq(sp);
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	assert(req->sp == sp);
-
-	VTCP_name(&sp->sockaddr, sp->sockaddrlen,
-	    sp->addr, sizeof sp->addr, sp->port, sizeof sp->port);
-	if (cache_param->log_local_addr) {
-		AZ(getsockname(sp->fd, (void*)&sp->mysockaddr,
-		    &sp->mysockaddrlen));
-		VTCP_name(&sp->mysockaddr, sp->mysockaddrlen,
-		    laddr, sizeof laddr, lport, sizeof lport);
-		/* XXX: have no req yet */
-		VSLb(req->vsl, SLT_SessionOpen, "%s %s %s %s",
-		    sp->addr, sp->port, laddr, lport);
-	} else {
-		/* XXX: have no req yet */
-		VSLb(req->vsl, SLT_SessionOpen, "%s %s %s",
-		    sp->addr, sp->port, sp->mylsock->name);
-	}
-
-	wrk->acct_tmp.sess++;
-
-	sp->t_rx = sp->t_open;
-	sp->t_idle = sp->t_open;
-	sp->step = STP_WAIT;
-	return (0);
-}
-
-/*--------------------------------------------------------------------
  * WAIT
  * Collect the request from the client.
  *
@@ -155,18 +103,44 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req)
 	struct pollfd pfd[1];
 	double now, when;
 	const char *why = NULL;
+	char laddr[ADDR_BUFSIZE];
+	char lport[PORT_BUFSIZE];
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
-	assert(!isnan(sp->t_rx));
-
 	if (req == NULL) {
 		req = SES_GetReq(sp);
 		CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	}
 	assert(req->sp == sp);
 
+	if (!sp->init_done) {
+		VTCP_name(&sp->sockaddr, sp->sockaddrlen,
+		    sp->addr, sizeof sp->addr, sp->port, sizeof sp->port);
+		if (cache_param->log_local_addr) {
+			AZ(getsockname(sp->fd, (void*)&sp->mysockaddr,
+			    &sp->mysockaddrlen));
+			VTCP_name(&sp->mysockaddr, sp->mysockaddrlen,
+			    laddr, sizeof laddr, lport, sizeof lport);
+			/* XXX: have no req yet */
+			VSLb(req->vsl, SLT_SessionOpen, "%s %s %s %s",
+			    sp->addr, sp->port, laddr, lport);
+		} else {
+			/* XXX: have no req yet */
+			VSLb(req->vsl, SLT_SessionOpen, "%s %s %s",
+			    sp->addr, sp->port, sp->mylsock->name);
+		}
+
+		wrk->acct_tmp.sess++;
+
+		sp->t_rx = sp->t_open;
+		sp->t_idle = sp->t_open;
+		sp->init_done = 1;
+	}
+
+	assert(!isnan(sp->t_rx));
+
 	AZ(req->vcl);
 	AZ(req->obj);
 	AZ(req->esi_level);
@@ -1591,7 +1565,6 @@ CNT_Session(struct sess *sp)
 	 * Possible entrance states
 	 */
 	assert(
-	    sp->step == STP_FIRST ||
 	    sp->step == STP_WAIT ||
 	    sp->step == STP_LOOKUP ||
 	    sp->step == STP_RECV);
@@ -1604,7 +1577,7 @@ CNT_Session(struct sess *sp)
 	 * rather do the syscall in the worker thread.
 	 * On systems which return errors for ioctl, we close early
 	 */
-	if ((sp->step == STP_FIRST || sp->step == STP_START) &&
+	if ((sp->step == STP_WAIT || sp->step == STP_START) &&
 	    VTCP_blocking(sp->fd)) {
 		if (errno == ECONNRESET)
 			SES_Close(sp, "remote closed");
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 08f77f2..34dad47 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -159,7 +159,7 @@ SES_pool_accept_task(struct worker *wrk, void *arg)
 		VCA_FailSess(wrk);
 	} else {
 		VCA_SetupSess(wrk, sp);
-		sp->step = STP_FIRST;
+		sp->step = STP_WAIT;
 		ses_pool_task(wrk, sp);
 	}
 }
diff --git a/include/tbl/steps.h b/include/tbl/steps.h
index ba4133c..6750cd3 100644
--- a/include/tbl/steps.h
+++ b/include/tbl/steps.h
@@ -30,19 +30,18 @@
 
 /*lint -save -e525 -e539 */
 SESS_STEP(wait,		WAIT,		(sp, sp->wrk, sp->req))
-SESS_STEP(first,		FIRST,		(sp, sp->wrk))
-SESS_STEP(restart,		RESTART,	(sp, sp->wrk, sp->req))
+SESS_STEP(restart,	RESTART,	(sp, sp->wrk, sp->req))
 SESS_STEP(recv,		RECV,		(sp, sp->wrk, sp->req))
-SESS_STEP(start,		START,		(sp, sp->wrk, sp->req))
+SESS_STEP(start,	START,		(sp, sp->wrk, sp->req))
 SESS_STEP(pipe,		PIPE,		(sp, sp->wrk, sp->req))
 SESS_STEP(pass,		PASS,		(sp, sp->wrk, sp->req))
-SESS_STEP(lookup,		LOOKUP,		(sp, sp->wrk, sp->req))
+SESS_STEP(lookup,	LOOKUP,		(sp, sp->wrk, sp->req))
 SESS_STEP(miss,		MISS,		(sp, sp->wrk, sp->req))
 SESS_STEP(hit,		HIT,		(sp, sp->wrk, sp->req))
-SESS_STEP(fetch,		FETCH,		(sp, sp->wrk, sp->req))
-SESS_STEP(fetchbody,		FETCHBODY,	(sp, sp->wrk, sp->req))
-SESS_STEP(prepresp,		PREPRESP,	(sp, sp->wrk, sp->req))
-SESS_STEP(deliver,		DELIVER,	(sp, sp->wrk, sp->req))
-SESS_STEP(error,		ERROR,		(sp, sp->wrk, sp->req))
+SESS_STEP(fetch,	FETCH,		(sp, sp->wrk, sp->req))
+SESS_STEP(fetchbody,	FETCHBODY,	(sp, sp->wrk, sp->req))
+SESS_STEP(prepresp,	PREPRESP,	(sp, sp->wrk, sp->req))
+SESS_STEP(deliver,	DELIVER,	(sp, sp->wrk, sp->req))
+SESS_STEP(error,	ERROR,		(sp, sp->wrk, sp->req))
 SESS_STEP(done,		DONE,		(sp, sp->wrk, sp->req))
 /*lint -restore */



More information about the varnish-commit mailing list