[experimental-ims] 71a1806 Add a "vsl_mask" parameter, that allows individual SLT tags to be suppressed so the never take up space/bandwidth in the VSL.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Dec 18 10:27:54 CET 2014
commit 71a18061e026ecde6b319e798b1e61cf887f0829
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Aug 27 10:30:46 2012 +0000
Add a "vsl_mask" parameter, that allows individual SLT tags to be
suppressed so the never take up space/bandwidth in the VSL.
Reimplement vcl_trace using this:
param.set vsl_mask +VCL_trace
param.set vsl_mask -VCL_trace
XXX: doc-update needed
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 967d3bb..78f253c 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -61,6 +61,7 @@ varnishd_SOURCES = \
mgt/mgt_cli.c \
mgt/mgt_main.c \
mgt/mgt_param.c \
+ mgt/mgt_param_vsl.c \
mgt/mgt_pool.c \
mgt/mgt_sandbox.c \
mgt/mgt_sandbox_solaris.c \
diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index f5cc879..167c25e 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -50,6 +50,18 @@ static uint32_t *vsl_ptr;
struct VSC_C_main *VSC_C_main;
+static inline int
+vsl_tag_is_masked(enum VSL_tag_e tag)
+{
+ volatile uint8_t *bm = &cache_param->vsl_mask[0];
+ uint8_t b;
+
+ assert(tag < SLT_Reserved);
+ bm += ((unsigned)tag >> 3);
+ b = (0x80 >> ((unsigned)tag & 7));
+ return (*bm & b);
+}
+
static inline uint32_t
vsl_w0(uint32_t type, uint32_t length)
{
@@ -159,6 +171,8 @@ VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...)
unsigned n, mlen = cache_param->shm_reclen;
char buf[mlen];
+ if (vsl_tag_is_masked(tag))
+ return;
AN(fmt);
va_start(ap, fmt);
@@ -281,6 +295,8 @@ VSLb(struct vsl_log *vsl, enum VSL_tag_e tag, const char *fmt, ...)
va_list ap;
AN(fmt);
+ if (vsl_tag_is_masked(tag))
+ return;
va_start(ap, fmt);
wsl(vsl, tag, vsl->wid, fmt, ap);
va_end(ap);
@@ -293,6 +309,9 @@ VSLb(struct vsl_log *vsl, enum VSL_tag_e tag, const char *fmt, ...)
void
VSLbt(struct vsl_log *vsl, enum VSL_tag_e tag, txt t)
{
+
+ if (vsl_tag_is_masked(tag))
+ return;
wslr(vsl, tag, -1, t);
}
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 8cc2920..477d337 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -75,9 +75,8 @@ VRT_count(struct req *req, unsigned u)
if (req == NULL)
return;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- if (cache_param->vcl_trace)
- VSLb(req->vsl, SLT_VCL_trace, "%u %u.%u", u,
- req->vcl->ref[u].line, req->vcl->ref[u].pos);
+ VSLb(req->vsl, SLT_VCL_trace, "%u %u.%u", u,
+ req->vcl->ref[u].line, req->vcl->ref[u].pos);
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h
index a66bcf8..79de607 100644
--- a/bin/varnishd/common/params.h
+++ b/bin/varnishd/common/params.h
@@ -103,10 +103,6 @@ struct params {
ssize_t fetch_maxchunksize;
unsigned nuke_limit;
-
- /* VCL traces */
- unsigned vcl_trace;
-
unsigned accept_filter;
/* Listen address */
@@ -204,4 +200,6 @@ struct params {
struct poolparam req_pool;
struct poolparam sess_pool;
struct poolparam vbo_pool;
+
+ uint8_t vsl_mask[256/8];
};
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 2f090dc..026207c 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -872,14 +872,6 @@ static const struct parspec input_parspec[] = {
"fragmentation.\n",
EXPERIMENTAL,
"256m", "bytes" },
- { "vcl_trace", tweak_bool, &mgt_param.vcl_trace, 0, 0,
- "Trace VCL execution in the shmlog.\n"
- "Enabling this will allow you to see the path each "
- "request has taken through the VCL program.\n"
- "This generates a lot of logrecords so it is off by "
- "default.",
- 0,
- "off", "bool" },
{ "accept_filter", tweak_bool, &mgt_param.accept_filter, 0, 0,
"Enable kernel accept-filters, if supported by the kernel.",
MUST_RESTART,
@@ -1318,7 +1310,7 @@ mcf_param_show(struct cli *cli, const char * const *av, void *priv)
continue;
}
pp->func(cli, pp, NULL);
- if (pp->units != NULL)
+ if (pp->units != NULL && *pp->units != '\0')
VCLI_Out(cli, " [%s]\n", pp->units);
else
VCLI_Out(cli, "\n");
@@ -1496,6 +1488,7 @@ MCF_ParamInit(struct cli *cli)
MCF_AddParams(input_parspec);
MCF_AddParams(WRK_parspec);
+ MCF_AddParams(VSL_parspec);
/* XXX: We do this twice, to get past any interdependencies */
MCF_SetDefaults(NULL);
diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h
index ee1ad52..d25411d 100644
--- a/bin/varnishd/mgt/mgt_param.h
+++ b/bin/varnishd/mgt/mgt_param.h
@@ -57,5 +57,8 @@ void tweak_timeout_double(struct cli *cli,
const struct parspec *par, const char *arg);
void tweak_bytes(struct cli *cli, const struct parspec *par, const char *arg);
+/* mgt_param_vsl.c */
+extern const struct parspec VSL_parspec[];
+
/* mgt_pool.c */
extern const struct parspec WRK_parspec[];
diff --git a/bin/varnishd/mgt/mgt_param_vsl.c b/bin/varnishd/mgt/mgt_param_vsl.c
new file mode 100644
index 0000000..6338d49
--- /dev/null
+++ b/bin/varnishd/mgt/mgt_param_vsl.c
@@ -0,0 +1,137 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 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.
+ */
+
+#include "config.h"
+
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "common/params.h"
+#include "mgt/mgt.h"
+#include "mgt/mgt_param.h"
+
+#include "vav.h"
+#include "vcli.h"
+#include "vcli_common.h"
+#include "vcli_priv.h"
+
+#include "vapi/vsl_int.h"
+
+static const char * const VSL_tags[256] = {
+# define SLTM(foo,sdesc,ldesc) [SLT_##foo] = #foo,
+# include "tbl/vsl_tags.h"
+# undef SLTM
+};
+
+enum bit_do {BSET, BCLR, BTST};
+
+static int
+vsl_bit(unsigned no, enum bit_do act)
+{
+ volatile uint8_t *bm = &mgt_param.vsl_mask[0];
+ uint8_t b;
+
+ assert(no < (unsigned)SLT_Reserved);
+
+ bm += (no >> 3);
+ b = (0x80 >> (no & 7));
+ if (act == BSET)
+ *bm |= b;
+ else if (act == BCLR)
+ *bm &= ~b;
+ return (*bm & b);
+}
+
+static void
+tweak_vsl_mask(struct cli *cli, const struct parspec *par, const char *arg)
+{
+ int i, n;
+ unsigned j;
+ const char *s;
+ char **av;
+ (void)par;
+
+ if (arg != NULL) {
+ if (!strcmp(arg, "default")) {
+ (void)vsl_bit(SLT_VCL_trace, BSET);
+ (void)vsl_bit(SLT_WorkThread, BSET);
+ } else if (*arg != 0) {
+ av = VAV_Parse(arg, &n, ARGV_COMMA);
+ if (av[0] != NULL) {
+ VCLI_Out(cli, "Cannot parse: %s\n", av[0]);
+ VCLI_SetResult(cli, CLIS_PARAM);
+ return;
+ }
+ for (i = 1; av[i] != NULL; i++) {
+ s = av[i];
+ if (*s != '-' && *s != '+') {
+ VCLI_Out(cli,
+ "Missing '+' or '-' (%s)\n", s);
+ VCLI_SetResult(cli, CLIS_PARAM);
+ VAV_Free(av);
+ return;
+ }
+ for (j = 0; j < 256; j++)
+ if (VSL_tags[j] != NULL &&
+ !strcasecmp(s + 1, VSL_tags[j]))
+ break;
+ if (j == 256) {
+ VCLI_Out(cli,
+ "Unknown VSL tag (%s)\n", s);
+ VCLI_SetResult(cli, CLIS_PARAM);
+ VAV_Free(av);
+ return;
+ }
+ if (s[0] == '+')
+ (void)vsl_bit(j, BCLR);
+ else
+ (void)vsl_bit(j, BSET);
+ }
+ VAV_Free(av);
+ }
+ } else {
+ s = "";
+ for (j = 0; j < 256; j++) {
+ if (vsl_bit(j, BTST)) {
+ VCLI_Out(cli, "%s-%s", s, VSL_tags[j]);
+ s = ",";
+ }
+ }
+ if (*s == '\0')
+ VCLI_Out(cli, "(all enabled)");
+ }
+}
+
+const struct parspec VSL_parspec[] = {
+ { "vsl_mask", tweak_vsl_mask, NULL, 0, 0,
+ "Mask individual VSL messages from being logged",
+ 0, "default", "" },
+ { NULL, NULL, NULL }
+};
diff --git a/bin/varnishtest/tests/c00005.vtc b/bin/varnishtest/tests/c00005.vtc
index 7a7965c..846b283 100644
--- a/bin/varnishtest/tests/c00005.vtc
+++ b/bin/varnishtest/tests/c00005.vtc
@@ -9,7 +9,7 @@ server s1 {
txresp -body "2222\n"
} -start
-varnish v1 -arg "-p vcl_trace=on" -vcl+backend {
+varnish v1 -arg "-p vsl_mask=+VCL_trace" -vcl+backend {
acl acl1 {
"localhost";
}
diff --git a/bin/varnishtest/tests/c00054.vtc b/bin/varnishtest/tests/c00054.vtc
new file mode 100644
index 0000000..3299604
--- /dev/null
+++ b/bin/varnishtest/tests/c00054.vtc
@@ -0,0 +1,23 @@
+varnishtest "SLT masking"
+
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+varnish v1 -vcl+backend {} -start
+
+varnish v1 -cliok "param.show vsl_mask"
+varnish v1 -cliok "param.set vsl_mask +VCL_trace"
+varnish v1 -cliok "param.show vsl_mask"
+varnish v1 -cliok "param.set vsl_mask -WorkThread,-TTL"
+varnish v1 -cliok "param.show vsl_mask"
+varnish v1 -cliok "param.set vsl_mask +WorkThread"
+varnish v1 -clierr 106 "param.set vsl_mask FooBar"
+varnish v1 -clierr 106 "param.set vsl_mask -FooBar"
+
+client c1 {
+ txreq
+ rxresp
+} -run
More information about the varnish-commit
mailing list