Commit 84fe7970 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Reza Naghibi

Warn about too many (>100) VCLs.

Two new paramters allow the limit and than handling (ignore, warn, fail)
to be configured.

Fixes #2713
parent f11faf9e
......@@ -53,6 +53,7 @@
#include "tbl/vcl_states.h"
static const char * const VCL_STATE_LABEL = "label";
static int vcl_count;
struct vclprog;
struct vmodfile;
......@@ -252,6 +253,8 @@ mgt_vcl_add(const char *name, const char *state)
vp->warm = 1;
VTAILQ_INSERT_TAIL(&vclhead, vp, list);
if (vp->state != VCL_STATE_LABEL)
vcl_count++;
return (vp);
}
......@@ -269,6 +272,8 @@ mgt_vcl_del(struct vclprog *vp)
mgt_vcl_dep_del(VTAILQ_FIRST(&vp->dfrom));
VTAILQ_REMOVE(&vclhead, vp, list);
if (vp->state != VCL_STATE_LABEL)
vcl_count--;
if (vp->fname != NULL) {
if (!MGT_DO_DEBUG(DBG_VCL_KEEP))
AZ(unlink(vp->fname));
......@@ -566,6 +571,12 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
if (C_flag) {
bprintf(buf, ".CflagTest.%d", (int)getpid());
vclname = buf;
} else if (vcl_count >= mgt_param.max_vcl &&
mgt_param.max_vcl_handling == 2) {
VCLI_Out(cli, "Too many (%d) VCLs already loaded\n", vcl_count);
VCLI_Out(cli, "(See max_vcl and max_vcl_handling parameters)");
VCLI_SetResult(cli, CLIS_CANT);
return;
}
if (state == NULL)
......@@ -592,6 +603,14 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
if (active_vcl == NULL)
active_vcl = vp;
if (cli->result == CLIS_OK &&
vcl_count > mgt_param.max_vcl &&
mgt_param.max_vcl_handling == 1) {
VCLI_Out(cli, "%d VCLs loaded\n", vcl_count);
VCLI_Out(cli, "Remember to vcl.discard the old/unused VCLs.\n");
VCLI_Out(cli, "(See max_vcl and max_vcl_handling parameters)");
}
if (!MCH_Running())
return;
......
......@@ -7,7 +7,23 @@ server s1 {
txresp
} -start
varnish v1 -syntax 4.0 -arg "-i J.F.Nobody" -vcl+backend {
# Test max_vcl param
varnish v1 -arg "-i J.F.Nobody" -vcl+backend { } -start
varnish v1 -cliok "param.set max_vcl 2"
varnish v1 -cliok "param.set max_vcl_handling 2"
varnish v1 -vcl+backend { }
varnish v1 -errvcl {Too many (2) VCLs already loaded} {}
varnish v1 -cliok "param.set max_vcl_handling 1"
varnish v1 -cliexpect "Remember to vcl.discard the old/unused VCLs." \
{vcl.inline foobar "vcl 4.1; backend b1 {.host=\"${s1_addr}\";}"}
varnish v1 -cliok "param.set max_vcl 100"
varnish v1 -syntax 4.0 -vcl+backend {
import std;
import directors;
......@@ -78,7 +94,7 @@ varnish v1 -syntax 4.0 -arg "-i J.F.Nobody" -vcl+backend {
set bereq.connect_timeout = 10s;
}
} -start
}
client c1 {
txreq
......
......@@ -1537,6 +1537,38 @@ PARAM(
/* func */ NULL
)
PARAM(
/* name */ max_vcl_handling,
/* typ */ uint,
/* min */ "0",
/* max */ "2",
/* default */ "1",
/* units */ NULL,
/* flags */ 0,
/* s-text */
"Behaviour when attempting to exceed max_vcl loaded VCL.\n"
"\n* 0 - Ignore max_vcl parameter.\n"
"\n* 1 - Issue warning.\n"
"\n* 2 - Refuse loading VCLs.",
/* l-text */ "",
/* func */ NULL
)
PARAM(
/* name */ max_vcl,
/* typ */ uint,
/* min */ "0",
/* max */ NULL,
/* default */ "100",
/* units */ NULL,
/* flags */ 0,
/* s-text */
"Threshold of loaded VCL programs. (VCL labels are not counted.)"
" Parameter max_vcl_handling determines behaviour.",
/* l-text */ "",
/* func */ NULL
)
PARAM(
/* name */ vsm_free_cooldown,
/* typ */ timeout,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment