[master] a721685 Use struct transport to get back from session-waiter.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Feb 9 21:51:21 CET 2016
commit a721685093d5eeb70ff38fae9fe92f900d34a388
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Feb 9 20:50:44 2016 +0000
Use struct transport to get back from session-waiter.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index ed69cf6..0582f5b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -635,6 +635,7 @@ struct sess {
#define SESS_MAGIC 0x2c2f9c5a
enum sess_step sess_step;
+ const struct transport *transport;
struct lock mtx;
int fd;
uint32_t vxid;
@@ -948,7 +949,6 @@ void SES_Wait(struct sess *sp);
void SES_Delete(struct sess *sp, enum sess_close reason, double now);
void SES_NewPool(struct pool *pp, unsigned pool_no);
int SES_Reschedule_Req(struct req *);
-task_func_t SES_New_Session;
task_func_t SES_Proto_Req;
enum htc_status_e {
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 78ff8cc..2fecb7b 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -364,7 +364,8 @@ vca_make_session(struct worker *wrk, void *arg)
}
vca_tcp_opt_set(sp->fd, 0);
- wrk->task.func = wa->acceptlsock->transport->new_session;
+ sp->transport = wa->acceptlsock->transport;
+ wrk->task.func = sp->transport->new_session;
wrk->task.priv = sp;
}
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 0a85637..97a697e 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -40,6 +40,7 @@
#include <signal.h>
#include "cache.h"
+#include "cache_transport.h"
#include "cache_filter.h"
#include "common/heritage.h"
@@ -448,7 +449,8 @@ pan_sess(struct vsb *vsb, const struct sess *sp)
if (pan_already(vsb, sp))
return;
VSB_indent(vsb, 2);
- VSB_printf(vsb, "fd = %d, vxid = %u,\n", sp->fd, VXID(sp->vxid));
+ VSB_printf(vsb, "fd = %d, vxid = %u, xport = %s\n",
+ sp->fd, VXID(sp->vxid), sp->transport->name);
AZ(SES_Get_client_ip(sp, &ci));
AZ(SES_Get_client_port(sp, &cp));
VSB_printf(vsb, "client = %s %s,\n", ci, cp);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index c3802c6..a944d4b 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -46,7 +46,7 @@
#include "cache.h"
#include "cache_pool.h"
-#include "http1/cache_http1.h"
+#include "cache_transport.h"
#include "vsa.h"
#include "vtcp.h"
@@ -301,77 +301,6 @@ SES_New(struct pool *pp)
}
/*--------------------------------------------------------------------
- * Call protocol for this request
- */
-
-void __match_proto__(task_func_t)
-SES_Proto_Req(struct worker *wrk, void *arg)
-{
- struct req *req;
-
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC);
-
- THR_SetRequest(req);
- AZ(wrk->aws->r);
- HTTP1_Session(wrk, req);
- AZ(wrk->v1l);
- WS_Assert(wrk->aws);
- THR_SetRequest(NULL);
-}
-
-/*--------------------------------------------------------------------
- * Call protocol for this session (new or from waiter)
- *
- * When sessions are rescheduled from the waiter, a struct pool_task
- * is put on the reserved session workspace (for reasons of memory
- * conservation). This reservation is released as the first thing.
- * The acceptor and any other code which schedules this function
- * must obey this calling convention with a dummy reservation.
- */
-
-void __match_proto__(task_func_t)
-SES_New_Session(struct worker *wrk, void *arg)
-{
- struct sess *sp;
- struct req *req;
-
- CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC);
-
- /*
- * Assume we're going to receive something that will likely
- * involve a request...
- */
- if (VTCP_blocking(sp->fd)) {
- if (errno == ECONNRESET)
- SES_Close(sp, SC_REM_CLOSE);
- else
- SES_Close(sp, SC_TX_ERROR);
- return;
- }
- req = Req_New(wrk, sp);
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- req->htc->fd = sp->fd;
- SES_RxInit(req->htc, req->ws,
- cache_param->http_req_size, cache_param->http_req_hdr_len);
-
- sp->sess_step = S_STP_H1NEWREQ;
- wrk->task.func = SES_Proto_Req;
- wrk->task.priv = req;
-}
-
-static void __match_proto__(task_func_t)
-SES_Proto_Sess(struct worker *wrk, void *arg)
-{
- struct sess *sp;
-
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC);
- WS_Release(sp->ws, 0);
- SES_New_Session(wrk, arg);
-}
-
-/*--------------------------------------------------------------------
* Reschedule a request on a work-thread from its sessions pool
*
* This is used to reschedule requests waiting on busy objects
@@ -426,7 +355,7 @@ ses_handle(struct waited *wp, enum wait_event ev, double now)
CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
assert(sizeof *tp <= WS_Reserve(sp->ws, sizeof *tp));
tp = (void*)sp->ws->f;
- tp->func = SES_Proto_Sess;
+ tp->func = sp->transport->unwait;
tp->priv = sp;
if (Pool_Task(pp, tp, TASK_QUEUE_REQ))
SES_Delete(sp, SC_OVERLOAD, now);
diff --git a/bin/varnishd/cache/cache_transport.h b/bin/varnishd/cache/cache_transport.h
index 04440fc..6b8d7e9 100644
--- a/bin/varnishd/cache/cache_transport.h
+++ b/bin/varnishd/cache/cache_transport.h
@@ -39,7 +39,10 @@ struct transport {
unsigned magic;
#define TRANSPORT_MAGIC 0xf157f32f
+ const char *name;
+
task_func_t *new_session;
+ task_func_t *unwait;
vtr_deliver_f *deliver;
};
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 71516a0..7313101 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -44,10 +44,83 @@
#include "vtcp.h"
+/*--------------------------------------------------------------------
+ * Call protocol for this request
+ */
+
+void __match_proto__(task_func_t)
+SES_Proto_Req(struct worker *wrk, void *arg)
+{
+ struct req *req;
+
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC);
+
+ THR_SetRequest(req);
+ AZ(wrk->aws->r);
+ HTTP1_Session(wrk, req);
+ AZ(wrk->v1l);
+ WS_Assert(wrk->aws);
+ THR_SetRequest(NULL);
+}
+
+/*--------------------------------------------------------------------
+ * Call protocol for this session (new or from waiter)
+ *
+ * When sessions are rescheduled from the waiter, a struct pool_task
+ * is put on the reserved session workspace (for reasons of memory
+ * conservation). This reservation is released as the first thing.
+ * The acceptor and any other code which schedules this function
+ * must obey this calling convention with a dummy reservation.
+ */
+
+static void __match_proto__(task_func_t)
+http1_new_session(struct worker *wrk, void *arg)
+{
+ struct sess *sp;
+ struct req *req;
+
+ CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC);
+
+ /*
+ * Assume we're going to receive something that will likely
+ * involve a request...
+ */
+ if (VTCP_blocking(sp->fd)) {
+ if (errno == ECONNRESET)
+ SES_Close(sp, SC_REM_CLOSE);
+ else
+ SES_Close(sp, SC_TX_ERROR);
+ return;
+ }
+ req = Req_New(wrk, sp);
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ req->htc->fd = sp->fd;
+ SES_RxInit(req->htc, req->ws,
+ cache_param->http_req_size, cache_param->http_req_hdr_len);
+
+ sp->sess_step = S_STP_H1NEWREQ;
+ wrk->task.func = SES_Proto_Req;
+ wrk->task.priv = req;
+}
+
+static void __match_proto__(task_func_t)
+http1_unwait(struct worker *wrk, void *arg)
+{
+ struct sess *sp;
+
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC);
+ WS_Release(sp->ws, 0);
+ http1_new_session(wrk, arg);
+}
+
const struct transport HTTP1_transport = {
+ .name = "HTTP/1",
.magic = TRANSPORT_MAGIC,
.deliver = V1D_Deliver,
- .new_session = SES_New_Session,
+ .unwait = http1_unwait,
+ .new_session = http1_new_session,
};
/*----------------------------------------------------------------------
diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index c8faa64..9d1db5b 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -41,6 +41,8 @@
#include "../cache/cache.h"
#include "../cache/cache_transport.h"
+#include "../common/heritage.h"
+
#include "vend.h"
#include "vsa.h"
#include "vtcp.h"
@@ -381,12 +383,14 @@ vpx_new_session(struct worker *wrk, void *arg)
else
req->htc->pipeline_e = req->htc->rxbuf_e;
SES_RxReInit(req->htc);
+ sp->transport = &HTTP1_transport;
req->sp->sess_step = S_STP_H1NEWREQ;
wrk->task.func = SES_Proto_Req;
wrk->task.priv = req;
}
const struct transport PROXY_transport = {
+ .name = "PROXY",
.magic = TRANSPORT_MAGIC,
.new_session = vpx_new_session,
};
More information about the varnish-commit
mailing list