[master] 27d63c2 Eliminate the "init_done" and listen socket fields from struct sess by moving the VSL'ing of socket endpoints earlier in the processing.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Jul 2 10:22:30 CEST 2012
commit 27d63c26da9b445bf6994228668fbe9fdb6bcd2b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jul 2 08:21:23 2012 +0000
Eliminate the "init_done" and listen socket fields from struct sess
by moving the VSL'ing of socket endpoints earlier in the processing.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 1d991f1..d19dc32 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -670,8 +670,6 @@ struct sess {
socklen_t mysockaddrlen;
struct sockaddr_storage sockaddr;
struct sockaddr_storage mysockaddr;
- struct listen_sock *mylsock;
- int init_done;
/* formatted ascii client address */
char addr[ADDR_BUFSIZE];
@@ -695,7 +693,7 @@ struct sess {
void VCA_Init(void);
void VCA_Shutdown(void);
int VCA_Accept(struct listen_sock *ls, struct wrk_accept *wa);
-void VCA_SetupSess(struct worker *w, struct sess *sp);
+const char *VCA_SetupSess(struct worker *w, struct sess *sp);
void VCA_FailSess(struct worker *w);
/* cache_backend.c */
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 3ca79c1..5e71d00 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -239,10 +239,11 @@ VCA_FailSess(struct worker *wrk)
* We have allocated a session, move our info into it.
*/
-void
+const char *
VCA_SetupSess(struct worker *wrk, struct sess *sp)
{
struct wrk_accept *wa;
+ const char *retval;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -252,9 +253,7 @@ VCA_SetupSess(struct worker *wrk, struct sess *sp)
sp->fd = wa->acceptsock;
sp->vsl_id = wa->acceptsock | VSL_CLIENTMARKER ;
wa->acceptsock = -1;
- sp->t_open = VTIM_real();
- sp->mylsock = wa->acceptlsock;
- CHECK_OBJ_NOTNULL(sp->mylsock, LISTEN_SOCK_MAGIC);
+ retval = wa->acceptlsock->name;
assert(wa->acceptaddrlen <= sp->sockaddrlen);
memcpy(&sp->sockaddr, &wa->acceptaddr, wa->acceptaddrlen);
sp->sockaddrlen = wa->acceptaddrlen;
@@ -277,6 +276,7 @@ VCA_SetupSess(struct worker *wrk, struct sess *sp)
VTCP_Assert(setsockopt(sp->fd, SOL_SOCKET, SO_RCVTIMEO,
&tv_rcvtimeo, sizeof tv_rcvtimeo));
#endif
+ return (retval);
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 004f815..84fc3ea 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -73,8 +73,6 @@ DOT acceptor -> first [style=bold,color=green]
#include "cache.h"
-#include "common/heritage.h"
-
#include "hash/hash_slinger.h"
#include "vcl.h"
#include "vcli_priv.h"
@@ -112,8 +110,6 @@ 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);
@@ -121,30 +117,6 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req)
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);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 25dc687..3ed251d 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -42,6 +42,7 @@
#include "cache.h"
#include "waiter/waiter.h"
+#include "vtcp.h"
#include "vtim.h"
static unsigned ses_size = sizeof (struct sess);
@@ -148,7 +149,40 @@ ses_pool_task(struct worker *wrk, void *arg)
}
/*--------------------------------------------------------------------
+ */
+static void
+ses_vsl_socket(struct req *req, const char *lsockname)
+{
+ char laddr[ADDR_BUFSIZE];
+ char lport[PORT_BUFSIZE];
+ struct sess *sp;
+
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ AN(lsockname);
+ sp = req->sp;
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+
+ 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 %s",
+ sp->addr, sp->port, lsockname, laddr, lport);
+ } else {
+ /* XXX: have no req yet */
+ VSLb(req->vsl, SLT_SessionOpen, "%s %s %s - -",
+ sp->addr, sp->port, lsockname);
+ }
+}
+
+/*--------------------------------------------------------------------
* The pool-task for a newly accepted session
+ *
+ * Called from assigned worker thread
*/
void
@@ -157,6 +191,7 @@ SES_pool_accept_task(struct worker *wrk, void *arg)
struct sesspool *pp;
struct req *req;
struct sess *sp;
+ const char *lsockname;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CAST_OBJ_NOTNULL(pp, arg, SESSPOOL_MAGIC);
@@ -168,10 +203,21 @@ SES_pool_accept_task(struct worker *wrk, void *arg)
VCA_FailSess(wrk);
return;
}
- VCA_SetupSess(wrk, sp);
- sp->sess_step = S_STP_NEWREQ;
+
+ sp->t_open = VTIM_real();
+ sp->t_rx = sp->t_open;
+ sp->t_idle = sp->t_open;
+
+ lsockname = VCA_SetupSess(wrk, sp);
+
req = ses_GetReq(sp);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+
+ ses_vsl_socket(req, lsockname);
+
+ wrk->acct_tmp.sess++;
+
+ sp->sess_step = S_STP_NEWREQ;
ses_pool_task(wrk, req);
}
More information about the varnish-commit
mailing list