[master] b57ee0f Add vcl.state CLI command to force vcl state

Poul-Henning Kamp phk at FreeBSD.org
Sat Mar 7 14:32:39 CET 2015


commit b57ee0f7fc28e653d4104b51375f34951a73a61c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Mar 7 13:01:42 2015 +0000

    Add vcl.state CLI command to force vcl state

diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index 5267065..6af906f 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -96,6 +96,7 @@ static struct cli_proto cli_proto[] = {
 	{ CLI_VCL_LOAD,		"", mcf_vcl_load, NULL },
 	{ CLI_VCL_INLINE,	"", mcf_vcl_inline, NULL },
 	{ CLI_VCL_USE,		"", mcf_vcl_use, NULL },
+	{ CLI_VCL_STATE,	"", mcf_vcl_state, NULL },
 	{ CLI_VCL_DISCARD,	"", mcf_vcl_discard, NULL },
 	{ CLI_VCL_LIST,		"", mcf_vcl_list, NULL },
 	{ CLI_PARAM_SHOW,	"", mcf_param_show, NULL },
diff --git a/bin/varnishd/mgt/mgt_cli.h b/bin/varnishd/mgt/mgt_cli.h
index 0782bf6..0210aa1 100644
--- a/bin/varnishd/mgt/mgt_cli.h
+++ b/bin/varnishd/mgt/mgt_cli.h
@@ -42,6 +42,7 @@ cli_func_t mcf_param_set;
 cli_func_t mcf_vcl_load;
 cli_func_t mcf_vcl_inline;
 cli_func_t mcf_vcl_use;
+cli_func_t mcf_vcl_state;
 cli_func_t mcf_vcl_discard;
 cli_func_t mcf_vcl_list;
 
diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index abd805a..8de6583 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -298,6 +298,36 @@ mcf_find_vcl(struct cli *cli, const char *name)
 }
 
 void
+mcf_vcl_state(struct cli *cli, const char * const *av, void *priv)
+{
+	struct vclprog *vp;
+
+	(void)priv;
+	vp = mcf_find_vcl(cli, av[2]);
+	if (vp == NULL)
+		return;
+
+	if (!strcmp(vp->state, av[3]))
+		return;
+
+	if (!strcmp(av[3], "auto")) {
+		bprintf(vp->state, "%s", "auto");
+	} else if (!strcmp(av[3], "cold")) {
+		if (vp->active) {
+			VCLI_Out(cli, "Cannot set active VCL cold.");
+			VCLI_SetResult(cli, CLIS_PARAM);
+			return;
+		}
+		bprintf(vp->state, "%s", "auto");
+	} else if (!strcmp(av[3], "warm")) {
+		bprintf(vp->state, "%s", av[3]);
+	} else {
+		VCLI_Out(cli, "State must be one of auto, cold or warm.");
+		VCLI_SetResult(cli, CLIS_PARAM);
+	}
+}
+
+void
 mcf_vcl_use(struct cli *cli, const char * const *av, void *priv)
 {
 	unsigned status;
@@ -374,8 +404,8 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv)
 				flg = "active";
 			} else
 				flg = "available";
-			VCLI_Out(cli, "%-10s %6s %s\n",
-			    flg, "N/A", vp->name);
+			VCLI_Out(cli, "%-10s %4s/?    %6s %s\n",
+			    flg, vp->state, "N/A", vp->name);
 		}
 	}
 }
diff --git a/include/vcli.h b/include/vcli.h
index 5bc604c..bd5d726 100644
--- a/include/vcli.h
+++ b/include/vcli.h
@@ -70,6 +70,12 @@
 	"\tCompile and load the VCL data under the name provided.",	\
 	2, 3
 
+#define CLI_VCL_STATE							\
+	"vcl.state",							\
+	"vcl.state <configname> [auto,cold,warm]",			\
+	"\tForce the state of the named configuration.",		\
+	2, 2
+
 #define CLI_VCL_DISCARD							\
 	"vcl.discard",							\
 	"vcl.discard <configname>",					\



More information about the varnish-commit mailing list