r5653 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Fri Dec 17 21:00:22 CET 2010


Author: phk
Date: 2010-12-17 21:00:21 +0100 (Fri, 17 Dec 2010)
New Revision: 5653

Added:
   trunk/varnish-cache/bin/varnishtest/tests/v00032.vtc
   trunk/varnish-cache/lib/libvcl/vcc_storage.c
Modified:
   trunk/varnish-cache/bin/varnishd/stevedore.c
   trunk/varnish-cache/include/vrt.h
   trunk/varnish-cache/lib/libvcl/Makefile.am
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
Log:
Add the first bit of VCL control of choice of storage for an object.

Presently, you can only test for the existence of a given stevedore,
but it gets a lot of support code in place.



Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2010-12-17 17:15:35 UTC (rev 5652)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2010-12-17 20:00:21 UTC (rev 5653)
@@ -489,7 +489,7 @@
 
 	ASSERT_MGT();
 	VTAILQ_FOREACH(stv, &stevedores, list)
-		if (!strcmp(stv->name, TRANSIENT_NAME))
+		if (!strcmp(stv->ident, TRANSIENT_NAME))
 			return;
 	STV_Config(TRANSIENT_NAME "=malloc");
 }
@@ -505,9 +505,8 @@
 	(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);
-	}
+	VTAILQ_FOREACH(stv, &stevedores, list)
+		cli_out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
 }
 
 /*--------------------------------------------------------------------*/
@@ -517,3 +516,32 @@
 	    0, 0, "", stv_cli_list },
 	{ NULL}
 };
+
+/*--------------------------------------------------------------------
+ * VRT functions for stevedores
+ */
+
+#include "vrt.h"
+
+static const struct stevedore *
+stv_find(const char *nm)
+{
+	const struct stevedore *stv;
+
+	VTAILQ_FOREACH(stv, &stevedores, list)
+		if (!strcmp(stv->ident, nm))
+			return (stv);
+	if (!strcmp(TRANSIENT_NAME, nm))
+		return (stv_transient);
+	return (NULL);
+}
+
+int
+VRT_Stv(struct sess *sp, const char *nm)
+{
+	(void)sp;
+
+	if (stv_find(nm) != NULL)
+		return (1);
+	return (0);
+}

Added: trunk/varnish-cache/bin/varnishtest/tests/v00032.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00032.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00032.vtc	2010-12-17 20:00:21 UTC (rev 5653)
@@ -0,0 +1,26 @@
+# $Id$
+
+test "Storage related vcl variables"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_fetch {
+		set beresp.http.has_s0 = storage.s0;
+		set beresp.http.has_foo = storage.foo;
+		set beresp.http.has_Transient = storage.Transient;
+	}
+} -start
+
+varnish v1 -cliok "storage.list"
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.has_s0 == true
+	expect resp.http.has_foo == false
+	expect resp.http.has_Transient == true
+} -run

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h	2010-12-17 17:15:35 UTC (rev 5652)
+++ trunk/varnish-cache/include/vrt.h	2010-12-17 20:00:21 UTC (rev 5653)
@@ -206,6 +206,9 @@
 		p->free(p->priv);
 }
 
+/* Stevedore related functions */
+int VRT_Stv(struct sess *sp, const char *nm);
+
 /* Convert things to string */
 
 char *VRT_IP_string(const struct sess *sp, const struct sockaddr_storage *sa);

Modified: trunk/varnish-cache/lib/libvcl/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvcl/Makefile.am	2010-12-17 17:15:35 UTC (rev 5652)
+++ trunk/varnish-cache/lib/libvcl/Makefile.am	2010-12-17 20:00:21 UTC (rev 5653)
@@ -25,6 +25,7 @@
 	vcc_parse.c \
 	vcc_fixed_token.c \
 	vcc_obj.c \
+	vcc_storage.c \
 	vcc_string.c \
 	vcc_symb.c \
 	vcc_token.c \

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-12-17 17:15:35 UTC (rev 5652)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-12-17 20:00:21 UTC (rev 5653)
@@ -605,6 +605,9 @@
 		sym->r_methods = v->r_methods;
 	}
 
+	sym = VCC_AddSymbolStr(tl, "storage", SYM_WILDCARD);
+	sym->wildcard = vcc_Stv_Wildcard;
+
 	vcl_output_lang_h(tl->fh);
 	Fh(tl, 0, "\n/* ---===### VCC generated below here ###===---*/\n");
 	Fh(tl, 0, "\nextern const struct VCL_conf VCL_conf;\n");

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-12-17 17:15:35 UTC (rev 5652)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-12-17 20:00:21 UTC (rev 5653)
@@ -262,6 +262,9 @@
 /* vcc_parse.c */
 void vcc_Parse(struct vcc *tl);
 
+/* vcc_storage.c */
+sym_wildcard_t vcc_Stv_Wildcard;
+
 /* vcc_string.c */
 char *vcc_regexp(struct vcc *tl);
 int vcc_StringVal(struct vcc *tl);

Added: trunk/varnish-cache/lib/libvcl/vcc_storage.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_storage.c	                        (rev 0)
+++ trunk/varnish-cache/lib/libvcl/vcc_storage.c	2010-12-17 20:00:21 UTC (rev 5653)
@@ -0,0 +1,133 @@
+/*-
+ * Copyright (c) 2010 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.
+ *
+ * All stuff related to the storage.* part of the namespace.
+ *
+ * "All" is actually only a wildcard function, which instantiates variables
+ * on demand under the storage.* tree of the namespace.
+ *
+ * About the syntax:
+ * -----------------
+ *
+ * One of our long term goals is to have dynamic storage configuration, such
+ * as the ability to add or remove a stevedore on the fly, without restarting
+ * the worker process.
+ *
+ * Even though this goal is far out in the future, it influences the syntax
+ * design of storage selection from VCL.
+ *
+ * In difference from backends, where we know the possible set of backends at
+ * compile time, we will not in the future know the identity of the stevedores
+ * available at compile time, so we have to rely on VRT name resolution.
+ *
+ * This indicates a namespace on the form storage.<stevedore>.<property>
+ *
+ * For each property, we must define a default value if the named stevedore
+ * does not exists, such that for instance stevedore.forgetit.freespace
+ * returns zero etc.
+ *
+ */
+
+#include "config.h"
+
+#include "svnid.h"
+SVNID("$Id: vcc_expr.c 5537 2010-11-11 11:31:35Z phk $")
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "vsb.h"
+
+#include "vcc_priv.h"
+#include "vcc_compile.h"
+#include "libvarnish.h"
+
+#define PFX "storage."
+
+/*--------------------------------------------------------------------
+ * 
+ */
+
+static struct var *
+vcc_Stv_mkvar(struct vcc *tl, const struct token *t, enum var_type fmt)
+{
+	struct var *v;
+
+	v = TlAlloc(tl, sizeof *v);
+	AN(v);
+
+	v->name = TlDupTok(tl, t);
+	v->r_methods = VCL_MET_FETCH;		/* XXX ? */
+	v->fmt = fmt;
+
+	return (v);
+}
+
+struct symbol *
+vcc_Stv_Wildcard(struct vcc *tl, const struct token *t,
+    const struct symbol *wcsym)
+{
+	const char *p, *q;
+	struct var *v = NULL;
+	struct symbol *sym;
+	char stv[1024];
+	char buf[1024];
+
+	(void)wcsym;
+	assert((t->e - t->b) > strlen(PFX));
+	assert(!memcmp(t->b, PFX, strlen(PFX)));
+
+	p = t->b + strlen(PFX);
+	for (q = p; q < t->e && *q != '.'; q++)
+		continue;
+	bprintf(stv, "%.*s", (int)(q - p), p);
+
+	if (q == t->e) {
+		v = vcc_Stv_mkvar(tl, t, BOOL);
+		bprintf(buf, "VRT_Stv(sp, \"%s\")", stv);
+		v->rname = TlDup(tl, buf);
+#if 0
+	} else {
+		q++;
+fprintf(stderr, "Q: %s <%.*s>\n", stv, (int)(t->e - q), q);
+#endif
+	}
+
+	if (v == NULL)
+		return (NULL);
+
+	sym = VCC_AddSymbolTok(tl, t, SYM_VAR);
+	AN(sym);
+	sym->var = v;
+	sym->fmt = v->fmt;
+	sym->eval = vcc_Eval_Var;
+	sym->r_methods = v->r_methods;
+
+	return (sym);
+}




More information about the varnish-commit mailing list