[master] 2a7f495 Isolate mgr/worker better with respect to transport protocols.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Feb 12 11:33:13 CET 2016
commit 2a7f495ecbdc243f80dbdd3aacde2405afe94572
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Feb 12 10:17:30 2016 +0000
Isolate mgr/worker better with respect to transport protocols.
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 6a701ea..5acbb48 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -356,7 +356,8 @@ vca_make_session(struct worker *wrk, void *arg)
VTCP_name(sa, laddr, sizeof laddr, lport, sizeof lport);
- VSL(SLT_Begin, sp->vxid, "sess 0 %s", wa->acceptlsock->transport_name);
+ VSL(SLT_Begin, sp->vxid, "sess 0 %s",
+ wa->acceptlsock->transport->name);
VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d",
raddr, rport, wa->acceptlsock->name, laddr, lport,
sp->t_open, sp->fd);
@@ -610,3 +611,40 @@ VCA_Shutdown(void)
(void)close(i);
}
}
+
+/*--------------------------------------------------------------------
+ * Transport protocol registration
+ *
+ */
+
+static VTAILQ_HEAD(,transport) transports =
+ VTAILQ_HEAD_INITIALIZER(transports);
+
+void
+XPORT_Init(void)
+{
+ uint16_t n;
+ struct transport *xp;
+
+ ASSERT_MGT();
+
+ VTAILQ_INSERT_TAIL(&transports, &PROXY_transport, list);
+ VTAILQ_INSERT_TAIL(&transports, &HTTP1_transport, list);
+
+ n = 0;
+ VTAILQ_FOREACH(xp, &transports, list)
+ xp->number = ++n;
+}
+
+const struct transport *
+XPORT_Find(const char *name)
+{
+ struct transport *xp;
+
+ ASSERT_MGT();
+
+ VTAILQ_FOREACH(xp, &transports, list)
+ if (!strcasecmp(xp->name, name))
+ return (xp);
+ return (NULL);
+}
diff --git a/bin/varnishd/cache/cache_transport.h b/bin/varnishd/cache/cache_transport.h
index 268eac2..c756f07 100644
--- a/bin/varnishd/cache/cache_transport.h
+++ b/bin/varnishd/cache/cache_transport.h
@@ -33,18 +33,29 @@
*
*/
+struct req;
+struct boc;
+
typedef void vtr_deliver_f (struct req *, struct boc *, int sendbody);
typedef void vtr_req_body_f (struct req *);
struct transport {
- unsigned magic;
-#define TRANSPORT_MAGIC 0xf157f32f
+ unsigned magic;
+#define TRANSPORT_MAGIC 0xf157f32f
+
+ uint16_t number;
+
+ const char *name;
- const char *name;
+ task_func_t *new_session;
+ task_func_t *unwait;
- task_func_t *new_session;
- task_func_t *unwait;
+ vtr_req_body_f *req_body;
+ vtr_deliver_f *deliver;
- vtr_req_body_f *req_body;
- vtr_deliver_f *deliver;
+ VTAILQ_ENTRY(transport) list;
};
+
+extern struct transport PROXY_transport;
+extern struct transport HTTP1_transport;
+
diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h
index a5674a7..eb20956 100644
--- a/bin/varnishd/common/common.h
+++ b/bin/varnishd/common/common.h
@@ -62,6 +62,11 @@ void mgt_child_inherit(int fd, const char *what);
exit(2); \
} while (0)
+/* cache/cache_acceptor.c */
+struct transport;
+void XPORT_Init(void);
+const struct transport *XPORT_Find(const char *name);
+
/* cache/cache_vcl.c */
int VCL_TestLoad(const char *);
diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h
index 192d899..6a3d5a0 100644
--- a/bin/varnishd/common/heritage.h
+++ b/bin/varnishd/common/heritage.h
@@ -40,12 +40,8 @@ struct listen_sock {
char *name;
struct suckaddr *addr;
const struct transport *transport;
- const char *transport_name;
};
-extern const struct transport PROXY_transport;
-extern const struct transport HTTP1_transport;
-
VTAILQ_HEAD(listen_sock_head, listen_sock);
struct heritage {
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 592ba8f..faa1926 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -39,7 +39,6 @@
#include "cache/cache.h"
#include "cache/cache_filter.h"
-#include "common/heritage.h"
#include "cache/cache_transport.h"
#include "cache_http1.h"
#include "hash/hash_slinger.h"
@@ -128,7 +127,7 @@ http1_req_body(struct req *req)
}
}
-const struct transport HTTP1_transport = {
+struct transport HTTP1_transport = {
.name = "HTTP/1",
.magic = TRANSPORT_MAGIC,
.deliver = V1D_Deliver,
diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c
index bda2063..aa3ce5a 100644
--- a/bin/varnishd/mgt/mgt_acceptor.c
+++ b/bin/varnishd/mgt/mgt_acceptor.c
@@ -49,7 +49,6 @@
#include "vss.h"
#include "vtcp.h"
-
static int
mac_opensocket(struct listen_sock *ls, struct cli *cli)
{
@@ -116,7 +115,6 @@ struct mac_help {
#define MAC_HELP_MAGIC 0x1e00a9d9
int good;
const char *name;
- const char *transport_name;
const struct transport *transport;
};
@@ -140,7 +138,6 @@ mac_callback(void *priv, const struct suckaddr *sa)
AN(ls->addr);
ls->name = strdup(mh->name);
AN(ls->name);
- ls->transport_name = mh->transport_name;
ls->transport = mh->transport;
VTAILQ_INSERT_TAIL(&heritage.socks, ls, list);
mh->good++;
@@ -185,6 +182,7 @@ MAC_Arg(const char *arg)
struct mac_help *mh;
const char *err;
int error;
+ const struct transport *xp;
av = VAV_Parse(arg, NULL, ARGV_COMMA);
if (av == NULL)
@@ -196,19 +194,17 @@ MAC_Arg(const char *arg)
AN(mh);
mh->name = av[1];
- if (av[2] == NULL || !strcmp(av[2], "HTTP/1")) {
- mh->transport = &HTTP1_transport;
- mh->transport_name = "HTTP/1";
- if (av[2] != NULL && av[3] != NULL)
- ARGV_ERR("Too many sub-arguments to -a(HTTP/1)\n");
- } else if (!strcmp(av[2], "PROXY")) {
- mh->transport = &PROXY_transport;
- mh->transport_name = "PROXY";
- if (av[3] != NULL)
- ARGV_ERR("Too many sub-arguments to -a(PROXY)\n");
+ if (av[2] == NULL) {
+ xp = XPORT_Find("http/1");
} else {
- ARGV_ERR("Unknown protocol '%s'\n", av[2]);
+ xp = XPORT_Find(av[2]);
+ if (xp == NULL)
+ ARGV_ERR("Unknown protocol '%s'\n", av[2]);
+ if (av[3] != NULL)
+ ARGV_ERR("Too many sub-arguments to -a(%s)\n", av[2]);
}
+ AN(xp);
+ mh->transport = xp;
error = VSS_resolver(av[1], "80", mac_callback, mh, &err);
if (mh->good == 0 || error)
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index dab70fb..ec4ff5a 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -568,6 +568,8 @@ main(int argc, char * const *argv)
mgt_evb = vev_new_base();
AN(mgt_evb);
+ XPORT_Init();
+
init_params(cli);
cli_check(cli);
diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index 8290c7d..cd5bfcf 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -41,8 +41,6 @@
#include "../cache/cache.h"
#include "../cache/cache_transport.h"
-#include "../common/heritage.h"
-
#include "vend.h"
#include "vsa.h"
#include "vtcp.h"
@@ -383,7 +381,7 @@ vpx_new_session(struct worker *wrk, void *arg)
wrk->task.priv = req;
}
-const struct transport PROXY_transport = {
+struct transport PROXY_transport = {
.name = "PROXY",
.magic = TRANSPORT_MAGIC,
.new_session = vpx_new_session,
More information about the varnish-commit
mailing list