r4836 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

phk at varnish-cache.org phk at varnish-cache.org
Thu May 20 10:05:28 CEST 2010


Author: phk
Date: 2010-05-20 10:05:27 +0200 (Thu, 20 May 2010)
New Revision: 4836

Added:
   trunk/varnish-cache/bin/varnishtest/tests/b00032.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/mgt_cli.c
   trunk/varnish-cache/bin/varnishd/mgt_cli.h
   trunk/varnish-cache/bin/varnishd/stevedore.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/bin/varnishd/storage_malloc.c
Log:
Make it possible to name storage devices.

The syntax is:

	-s [name=]type[, args]

Add storage.list command to show storage devices, more details will be
added later.



Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c	2010-05-20 07:32:24 UTC (rev 4835)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c	2010-05-20 08:05:27 UTC (rev 4836)
@@ -355,6 +355,7 @@
 	AZ(CLS_AddFunc(cls, MCF_NOAUTH, cli_auth));
 	AZ(CLS_AddFunc(cls, MCF_AUTH, cli_proto));
 	AZ(CLS_AddFunc(cls, MCF_AUTH, cli_debug));
+	AZ(CLS_AddFunc(cls, MCF_AUTH, cli_stv));
 	AZ(CLS_AddFunc(cls, MCF_AUTH, cli_askchild));
 }
 

Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.h	2010-05-20 07:32:24 UTC (rev 4835)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.h	2010-05-20 08:05:27 UTC (rev 4836)
@@ -44,3 +44,6 @@
 cli_func_t mcf_config_discard;
 cli_func_t mcf_config_list;
 cli_func_t mcf_config_show;
+
+/* stevedore.c */
+extern struct cli_proto cli_stv[];

Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2010-05-20 07:32:24 UTC (rev 4835)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2010-05-20 08:05:27 UTC (rev 4836)
@@ -38,6 +38,7 @@
 
 #include "cache.h"
 #include "stevedore.h"
+#include "cli_priv.h"
 
 static VTAILQ_HEAD(, stevedore)	stevedores =
     VTAILQ_HEAD_INITIALIZER(stevedores);
@@ -271,11 +272,20 @@
 STV_config(const char *spec)
 {
 	char **av;
+	const char *p, *q;
 	struct stevedore *stv;
 	const struct stevedore *stv2;
-	int ac;
+	int ac, l;
+	static unsigned seq = 0;
 
-	av = ParseArgv(spec, ARGV_COMMA);
+	p = strchr(spec, '=');
+	q = strchr(spec, ',');
+	if (p != NULL && (q == NULL || q > p)) {
+		av = ParseArgv(p + 1, ARGV_COMMA);
+	} else {
+		av = ParseArgv(spec, ARGV_COMMA);
+		p = NULL;
+	}
 	AN(av);
 
 	if (av[0] != NULL)
@@ -289,6 +299,8 @@
 
 	stv2 = pick(STV_choice, av[1], "storage");
 	AN(stv2);
+
+	/* Append to ident string */
 	vsb_printf(vident, ",-s%s", av[1]);
 
 	av += 2;
@@ -300,6 +312,16 @@
 	*stv = *stv2;
 	AN(stv->name);
 	AN(stv->alloc);
+
+	if (p == NULL)
+		bprintf(stv->ident, "storage_%u", seq++);
+	else {
+		l = p - spec;
+		if (l > sizeof stv->ident - 1)
+			l = sizeof stv->ident - 1;
+		bprintf(stv->ident, "%*.*s", l, l, spec);
+	}
+
 	stv->lru = LRU_Alloc();
 
 	if (stv->init != NULL)
@@ -312,3 +334,28 @@
 	if (!stv_next)
 		stv_next = VTAILQ_FIRST(&stevedores);
 }
+
+/*--------------------------------------------------------------------*/
+
+static void
+stv_cli_list(struct cli *cli, const char * const *av, void *priv)
+{
+	struct stevedore *stv;
+
+	ASSERT_MGT();
+	(void)av;
+	(void)priv;
+	cli_out(cli, "Storage devices:\n");
+	VTAILQ_FOREACH(stv, &stevedores, list) {
+		cli_out(cli, "\tstorage.%s.%s\n", stv->name, stv->ident);
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
+struct cli_proto cli_stv[] = {
+	{ "storage.list", "storage.list", "List storage devices\n",
+	    0, 0, "", stv_cli_list },
+	{ NULL}
+};
+

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2010-05-20 07:32:24 UTC (rev 4835)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2010-05-20 08:05:27 UTC (rev 4836)
@@ -65,6 +65,7 @@
 	void			*priv;
 
 	VTAILQ_ENTRY(stevedore)	list;
+	char			ident[16];
 };
 
 struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl,

Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c	2010-05-20 07:32:24 UTC (rev 4835)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c	2010-05-20 08:05:27 UTC (rev 4836)
@@ -174,7 +174,7 @@
 	if ((u != (uintmax_t)(size_t)u))
 		ARGV_ERR("(-smalloc) size \"%s\": too big\n", av[0]);
 
-	printf("storage_malloc: max size %ju MB.\n",
+	printf("storage.malloc.%s: max size %ju MB.\n", parent->ident,
 	    u / (1024 * 1024));
 	sc->sma_max = u;
 

Added: trunk/varnish-cache/bin/varnishtest/tests/b00032.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/b00032.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/b00032.vtc	2010-05-20 08:05:27 UTC (rev 4836)
@@ -0,0 +1,5 @@
+# $Id$
+
+test "CLI coverage test"
+
+varnish v1 -cliok storage.list




More information about the varnish-commit mailing list