[master] 720d0d5 Move waiter selection from param to command-line and pave the road for them taking parameters.
Poul-Henning Kamp
phk at FreeBSD.org
Tue May 26 10:28:52 CEST 2015
commit 720d0d5ae205465cd6ca6e03522579945c5fff64
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue May 26 08:28:10 2015 +0000
Move waiter selection from param to command-line and pave the road
for them taking parameters.
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 1bf3355..1a5c13f 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -109,6 +109,7 @@ noinst_HEADERS = \
storage/storage_persistent.h \
waiter/waiter.h \
waiter/waiter_priv.h
+ waiter/mgt_waiter.h
# Headers for use with vmods
nobase_pkginclude_HEADERS = \
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 533ec80..9aa5ef3 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -57,6 +57,7 @@
#include "vrnd.h"
#include "vsha256.h"
#include "vtim.h"
+#include "waiter/mgt_waiter.h"
#include "compat/daemon.h"
@@ -186,6 +187,18 @@ usage(void)
"Telnet listen address and port");
fprintf(stderr, FMT, "-t", "Default TTL");
fprintf(stderr, FMT, "-V", "version");
+ fprintf(stderr, FMT, "-W waiter", "Waiter implementation");
+#if defined(HAVE_KQUEUE)
+ fprintf(stderr, FMT, "", " -W kqueue");
+#endif
+#if defined(HAVE_EPOLL_CTL)
+ fprintf(stderr, FMT, "", " -W epoll");
+#endif
+#if defined(HAVE_PORT_CREATE)
+ fprintf(stderr, FMT, "", " -W ports");
+#endif
+ fprintf(stderr, FMT, "", " -W poll");
+
#undef FMT
exit(1);
}
@@ -438,6 +451,7 @@ main(int argc, char * const *argv)
const char *P_arg = NULL;
const char *S_arg = NULL;
const char *s_arg = "malloc,100m";
+ const char *W_arg = NULL;
int s_arg_given = 0;
const char *T_arg = "localhost:0";
char *p, *vcl = NULL;
@@ -496,7 +510,7 @@ main(int argc, char * const *argv)
cli_check(cli);
while ((o = getopt(argc, argv,
- "a:b:Cdf:Fh:i:j:l:M:n:P:p:r:S:s:T:t:Vx:")) != -1) {
+ "a:b:Cdf:Fh:i:j:l:M:n:P:p:r:S:s:T:t:VW:x:")) != -1) {
/*
* -j must be the first argument if specified, because
* it (may) affect subsequent argument processing.
@@ -593,6 +607,9 @@ main(int argc, char * const *argv)
/* XXX: we should print the ident here */
VCS_Message("varnishd");
exit(0);
+ case 'W':
+ W_arg = optarg;
+ break;
case 'x':
if (!strcmp(optarg, "dumprstparam")) {
MCF_DumpRstParam();
@@ -708,6 +725,8 @@ main(int argc, char * const *argv)
HSH_config(h_arg);
+ Wait_config(W_arg);
+
mgt_SHM_Init();
AZ(VSB_finish(vident));
diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c
index 5ddbf37..c97d3ff 100644
--- a/bin/varnishd/mgt/mgt_param_tbl.c
+++ b/bin/varnishd/mgt/mgt_param_tbl.c
@@ -35,7 +35,6 @@
#include "common/params.h"
#include "mgt/mgt_param.h"
-#include "waiter/waiter.h"
#define MEMPOOL_TEXT \
@@ -370,11 +369,6 @@ struct parspec mgt_parspec[] = {
"more sessions take a detour around the waiter.",
EXPERIMENTAL,
"0.050", "seconds" },
- { "waiter", tweak_waiter, NULL,
- NULL, NULL,
- "Select the waiter kernel interface.",
- WIZARD | MUST_RESTART,
- WAITER_DEFAULT, NULL },
{ "ban_dups", tweak_bool, &mgt_param.ban_dups,
NULL, NULL,
"Eliminate older identical bans when new bans are created."
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index f75a5b5..b5f653c 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -43,7 +43,6 @@
#include "common/params.h"
#include "mgt/mgt_param.h"
-#include "waiter/waiter.h"
#include "vav.h"
#include "vnum.h"
@@ -381,17 +380,6 @@ tweak_string(struct vsb *vsb, const struct parspec *par, const char *arg)
/*--------------------------------------------------------------------*/
int
-tweak_waiter(struct vsb *vsb, const struct parspec *par, const char *arg)
-{
-
- /* XXX should have tweak_generic_string */
- (void)par;
- return (Wait_Argument(vsb, arg));
-}
-
-/*--------------------------------------------------------------------*/
-
-int
tweak_poolparam(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile struct poolparam *pp, px;
diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index 3373d0c..5965c8a 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -38,6 +38,7 @@
#include "waiter/waiter.h"
#include "waiter/waiter_priv.h"
+#include "waiter/mgt_waiter.h"
int
Wait_Enter(const struct waiter *w, struct waited *wp)
diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c
index 0452fe9..01f568c 100644
--- a/bin/varnishd/waiter/cache_waiter_epoll.c
+++ b/bin/varnishd/waiter/cache_waiter_epoll.c
@@ -43,6 +43,7 @@
#include "waiter/waiter.h"
#include "waiter/waiter_priv.h"
+#include "waiter/mgt_waiter.h"
#include "vtim.h"
#include "vfil.h"
diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c
index 34aae98..b52ded0 100644
--- a/bin/varnishd/waiter/cache_waiter_kqueue.c
+++ b/bin/varnishd/waiter/cache_waiter_kqueue.c
@@ -42,6 +42,7 @@
#include "waiter/waiter.h"
#include "waiter/waiter_priv.h"
+#include "waiter/mgt_waiter.h"
#include "vtim.h"
#define NKEV 256
diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c
index b54d695..210cd78 100644
--- a/bin/varnishd/waiter/cache_waiter_poll.c
+++ b/bin/varnishd/waiter/cache_waiter_poll.c
@@ -38,6 +38,7 @@
#include "waiter/waiter.h"
#include "waiter/waiter_priv.h"
+#include "waiter/mgt_waiter.h"
#include "vtim.h"
struct vwp {
diff --git a/bin/varnishd/waiter/cache_waiter_ports.c b/bin/varnishd/waiter/cache_waiter_ports.c
index a41c8fa..eb3ad4a 100644
--- a/bin/varnishd/waiter/cache_waiter_ports.c
+++ b/bin/varnishd/waiter/cache_waiter_ports.c
@@ -45,6 +45,7 @@
#include "waiter/waiter.h"
#include "waiter/waiter_priv.h"
+#include "waiter/mgt_waiter.h"
#include "vtim.h"
#define MAX_EVENTS 256
diff --git a/bin/varnishd/waiter/mgt_waiter.c b/bin/varnishd/waiter/mgt_waiter.c
index 3f344fd..18b3269 100644
--- a/bin/varnishd/waiter/mgt_waiter.c
+++ b/bin/varnishd/waiter/mgt_waiter.c
@@ -33,59 +33,35 @@
#include <unistd.h>
#include <string.h>
-#include "common/common.h"
+#include "mgt/mgt.h"
+#include "waiter/mgt_waiter.h"
-#include "waiter/waiter.h"
-#include "waiter/waiter_priv.h"
-
-static const struct waiter_impl *const waiter_impls[] = {
+static const struct choice waiter_choice[] = {
#if defined(HAVE_KQUEUE)
- &waiter_kqueue,
+ { "kqueue", &waiter_kqueue },
#endif
#if defined(HAVE_EPOLL_CTL)
- &waiter_epoll,
+ { "epoll", &waiter_epoll },
#endif
#if 0
#if defined(HAVE_PORT_CREATE)
- &waiter_ports,
+ { "ports", &waiter_ports },
#endif
#endif
- &waiter_poll,
- NULL,
+ { "poll", &waiter_poll },
+ { NULL, NULL}
};
struct waiter_impl const *waiter;
-int
-Wait_Argument(struct vsb *vsb, const char *arg)
+void
+Wait_config(const char *arg)
{
- int i;
ASSERT_MGT();
- if (arg == NULL) {
- if (waiter == NULL)
- VSB_printf(vsb, "default");
- else
- VSB_printf(vsb, "%s", waiter->name);
-
- VSB_printf(vsb, " (possible values: ");
- for (i = 0; waiter_impls[i] != NULL; i++)
- VSB_printf(vsb, "%s%s", i == 0 ? "" : ", ",
- waiter_impls[i]->name);
- VSB_printf(vsb, ")");
- return(0);
- }
- if (!strcmp(arg, WAITER_DEFAULT)) {
- waiter = waiter_impls[0];
- return(0);
- }
- for (i = 0; waiter_impls[i]; i++) {
- if (!strcmp(arg, waiter_impls[i]->name)) {
- waiter = waiter_impls[i];
- return(0);
- }
- }
- VSB_printf(vsb, "Unknown waiter");
- return (-1);
+ if (arg != NULL)
+ waiter = pick(waiter_choice, arg, "waiter");
+ else
+ waiter = waiter_choice[0].ptr;
}
diff --git a/bin/varnishd/waiter/mgt_waiter.h b/bin/varnishd/waiter/mgt_waiter.h
new file mode 100644
index 0000000..0106427
--- /dev/null
+++ b/bin/varnishd/waiter/mgt_waiter.h
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2015 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Private interfaces
+ */
+
+struct waiter_impl;
+
+/* mgt_waiter.c */
+extern struct waiter_impl const * waiter;
+
+#if defined(HAVE_EPOLL_CTL)
+extern const struct waiter_impl waiter_epoll;
+#endif
+
+#if defined(HAVE_KQUEUE)
+extern const struct waiter_impl waiter_kqueue;
+#endif
+
+#if defined(HAVE_PORT_CREATE)
+extern const struct waiter_impl waiter_ports;
+#endif
+
+extern const struct waiter_impl waiter_poll;
+
+void Wait_config(const char *arg);
diff --git a/bin/varnishd/waiter/waiter.h b/bin/varnishd/waiter/waiter.h
index 5b5620b..c211fd6 100644
--- a/bin/varnishd/waiter/waiter.h
+++ b/bin/varnishd/waiter/waiter.h
@@ -61,6 +61,3 @@ int Wait_Enter(const struct waiter *, struct waited *);
struct waiter *Waiter_New(waiter_handle_f *, volatile double *timeout);
void Waiter_Destroy(struct waiter **);
const char *Waiter_GetName(void);
-
-/* mgt_waiter.c */
-int Wait_Argument(struct vsb *vsb, const char *arg);
diff --git a/bin/varnishd/waiter/waiter_priv.h b/bin/varnishd/waiter/waiter_priv.h
index ed369c4..61ff970 100644
--- a/bin/varnishd/waiter/waiter_priv.h
+++ b/bin/varnishd/waiter/waiter_priv.h
@@ -63,20 +63,3 @@ struct waiter_impl {
waiter_inject_f *inject;
size_t size;
};
-
-/* mgt_waiter.c */
-extern struct waiter_impl const * waiter;
-
-#if defined(HAVE_EPOLL_CTL)
-extern const struct waiter_impl waiter_epoll;
-#endif
-
-#if defined(HAVE_KQUEUE)
-extern const struct waiter_impl waiter_kqueue;
-#endif
-
-#if defined(HAVE_PORT_CREATE)
-extern const struct waiter_impl waiter_ports;
-#endif
-
-extern const struct waiter_impl waiter_poll;
diff --git a/bin/varnishtest/tests/b00008.vtc b/bin/varnishtest/tests/b00008.vtc
index dbadb1b..2448aa4 100644
--- a/bin/varnishtest/tests/b00008.vtc
+++ b/bin/varnishtest/tests/b00008.vtc
@@ -24,8 +24,6 @@ varnish v1 -start
varnish v1 -cliok "help"
-varnish v1 -cliok "param.set waiter poll"
-
varnish v1 -clierr 106 "param.set waiter HASH(0x8839c4c)"
varnish v1 -cliok "param.set cli_limit 128"
diff --git a/bin/varnishtest/tests/b00009.vtc b/bin/varnishtest/tests/b00009.vtc
index f30fd01..cbd4b1e 100644
--- a/bin/varnishtest/tests/b00009.vtc
+++ b/bin/varnishtest/tests/b00009.vtc
@@ -5,7 +5,7 @@ server s1 {
txresp -hdr "Connection: close" -body "012345\n"
} -start
-varnish v1 -arg "-p waiter=poll" -vcl+backend {} -start
+varnish v1 -arg "-Wpoll" -vcl+backend {} -start
client c1 {
txreq -url "/"
diff --git a/bin/varnishtest/tests/b00048.vtc b/bin/varnishtest/tests/b00048.vtc
index ab9089c..e2a4b95 100644
--- a/bin/varnishtest/tests/b00048.vtc
+++ b/bin/varnishtest/tests/b00048.vtc
@@ -10,7 +10,7 @@ server s0 {
expect_close
} -dispatch
-varnish v1 -arg "-p waiter=poll" -vcl+backend {
+varnish v1 -arg "-Wpoll" -vcl+backend {
sub vcl_recv {
return (pass);
}
More information about the varnish-commit
mailing list