[master] f931117 Implement the storage.${stevedorename} VCL variables in a (not-quite-as-)hacky way
Poul-Henning Kamp
phk at FreeBSD.org
Thu Jun 9 10:45:10 CEST 2016
commit f93111722862bcb55901420ef51a126e9a4e6a4c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Jun 9 08:43:39 2016 +0000
Implement the storage.${stevedorename} VCL variables in a (not-quite-as-)hacky way
diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c
index fd8215b..1cfa281 100644
--- a/bin/varnishd/cache/cache_vrt_priv.c
+++ b/bin/varnishd/cache/cache_vrt_priv.c
@@ -136,7 +136,7 @@ VRT_priv_top(VRT_CTX, void *vmod_id)
return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
} else
WRONG("PRIV_TOP is only accessible in client VCL context");
- return (NULL);
+ NEEDLESS_RETURN(NULL);
}
/*--------------------------------------------------------------------
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index da7ece4..f977cdd 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -126,13 +126,20 @@ void
STV_open(void)
{
struct stevedore *stv;
+ char buf[1024];
ASSERT_CLI();
VTAILQ_FOREACH(stv, &stv_stevedores, list) {
+ bprintf(buf, "storage.%s", stv->ident);
+ stv->vclname = strdup(buf);
+ AN(stv->vclname);
if (stv->open != NULL)
stv->open(stv);
}
stv = stv_transient;
+ bprintf(buf, "storage.%s", stv->ident);
+ stv->vclname = strdup(buf);
+ AN(stv->vclname);
if (stv->open != NULL)
stv->open(stv);
stv_next = VTAILQ_FIRST(&stv_stevedores);
@@ -231,15 +238,19 @@ VRT_Stv(const char *nm)
return (0);
}
-struct stevedore *
-VRT_stevedore(const char *nm)
+const char * __match_proto__()
+VRT_STEVEDORE_string(VCL_STEVEDORE s)
{
- struct stevedore *stv;
+ if (s == NULL)
+ return (NULL);
+ CHECK_OBJ_NOTNULL(s, STEVEDORE_MAGIC);
+ return (s->vclname);
+}
- VTAILQ_FOREACH(stv, &stv_stevedores, list)
- if (!strcmp(stv->ident, nm))
- return (stv);
- WRONG("Unknown stevedore name");
+VCL_STEVEDORE
+VRT_stevedore(const char *nm)
+{
+ return (stv_find(nm));
}
#define VRTSTVVAR(nm, vtype, ctype, dval) \
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index 113b4da..0f85255 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -122,6 +122,7 @@ struct stevedore {
VTAILQ_ENTRY(stevedore) list;
char ident[16]; /* XXX: match VSM_chunk.ident */
+ char *vclname;
};
VTAILQ_HEAD(stevedore_head, stevedore);
diff --git a/bin/varnishtest/tests/v00032.vtc b/bin/varnishtest/tests/v00032.vtc
index f9adb77..47f1af8 100644
--- a/bin/varnishtest/tests/v00032.vtc
+++ b/bin/varnishtest/tests/v00032.vtc
@@ -8,7 +8,6 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.has_s0 = storage.s0;
- set beresp.http.has_foo = storage.foo;
set beresp.http.has_Transient = storage.Transient;
}
} -start
@@ -18,7 +17,6 @@ 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
+ expect resp.http.has_s0 == storage.s0
+ expect resp.http.has_Transient == storage.Transient
} -run
diff --git a/bin/varnishtest/tests/v00033.vtc b/bin/varnishtest/tests/v00033.vtc
index a10fac1..ca51ece 100644
--- a/bin/varnishtest/tests/v00033.vtc
+++ b/bin/varnishtest/tests/v00033.vtc
@@ -12,7 +12,7 @@ varnish v1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.foo =
- storage.nowhere.free_space +
+ storage.Transient.used_space +
1 B + 1 KB + 1 MB + 1GB + 1TB;
if (bereq.url == "/foo") {
set beresp.storage_hint = "Transient";
@@ -39,13 +39,13 @@ client c1 {
varnish v1 -errvcl {Expected BYTES unit (B, KB, MB...) got '"X"'} {
sub vcl_recv {
- if (storage.nowhere.free_space > 4 "X") {
+ if (storage.Transient.free_space > 4 "X") {
}
}
}
varnish v1 -errvcl {Unknown BYTES unit 'X'. Legal are 'B', 'KB', 'MB', 'GB' and 'TB'} {
sub vcl_recv {
- if (storage.nowhere.free_space > 4 X) {
+ if (storage.Transient.free_space > 4 X) {
}
}
}
diff --git a/include/vrt.h b/include/vrt.h
index 4ef7dec..fa90786 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -94,7 +94,7 @@ typedef long VCL_INT;
typedef const struct suckaddr * VCL_IP;
typedef const struct vrt_backend_probe * VCL_PROBE;
typedef double VCL_REAL;
-typedef struct stevedore * VCL_STEVEDORE;
+typedef const struct stevedore * VCL_STEVEDORE;
typedef const char * VCL_STRING;
typedef double VCL_TIME;
typedef void VCL_VOID;
@@ -334,7 +334,7 @@ struct vmod_priv *VRT_priv_top(VRT_CTX, void *vmod_id);
/* Stevedore related functions */
int VRT_Stv(const char *nm);
-struct stevedore *VRT_stevedore(const char *nm);
+VCL_STEVEDORE VRT_stevedore(const char *nm);
/* Convert things to string */
@@ -344,4 +344,5 @@ char *VRT_REAL_string(VRT_CTX, VCL_REAL);
char *VRT_TIME_string(VRT_CTX, VCL_TIME);
const char *VRT_BOOL_string(VCL_BOOL);
const char *VRT_BACKEND_string(VCL_BACKEND);
+const char *VRT_STEVEDORE_string(VCL_STEVEDORE);
const char *VRT_CollectString(VRT_CTX, const char *p, ...);
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 35cf4f0..a687cdc 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -444,7 +444,7 @@ vcc_new_source(const char *b, const char *e, const char *name)
/*--------------------------------------------------------------------*/
static struct source *
-vcc_file_source(struct vcc *tl, const char *fn)
+vcc_file_source(const struct vcc *tl, const char *fn)
{
char *f, *fnp;
struct source *sp;
@@ -574,9 +574,6 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
sym->lname = v->lname;
}
- sym = VCC_Symbol(tl, NULL, "storage", NULL, SYM_NONE, 1);
- sym->wildcard = vcc_Stv_Wildcard;
-
Fh(tl, 0, "/* ---===### VCC generated .h code ###===---*/\n");
Fc(tl, 0, "\n/* ---===### VCC generated .c code ###===---*/\n");
Fh(tl, 0, "\nextern const struct VCL_conf VCL_conf;\n");
@@ -818,25 +815,3 @@ VCC_Unsafe_Path(struct vcc *vcc, unsigned u)
CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
vcc->unsafe_path = u;
}
-
-void
-VCC_Stevedore(struct vcc *vcc, const char *stv_name)
-{
-#if 0
- struct symbol *sym;
- char stv[1024];
-
- CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
- ALLOC_OBJ(sym, SYMBOL_MAGIC);
- AN(sym);
- bprintf(stv, "stv.%s", stv_name);
- REPLACE(sym->name, stv); /* XXX storage.* ? */
- sym->kind = SYM_STEVEDORE;
- VCC_GlobalSymbol(sym, STEVEDORE, "VRT_stevedore(\"%s\")", stv_name);
- VTAILQ_INSERT_TAIL(&vcc->symbols, sym, list);
-#else
- (void)vcc;
- (void)stv_name;
-#endif
-}
-
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index b6c8f37..8a2b20e 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -292,9 +292,6 @@ extern const struct var vcc_vars[];
/* vcc_parse.c */
void vcc_Parse(struct vcc *tl);
-/* vcc_storage.c */
-sym_wildcard_t vcc_Stv_Wildcard;
-
/* vcc_utils.c */
const char *vcc_regexp(struct vcc *tl);
void Resolve_Sockaddr(struct vcc *tl, const char *host, const char *defport,
@@ -310,7 +307,6 @@ struct symbol *VCC_Symbol(struct vcc *, struct symbol *,
const char * VCC_SymKind(struct vcc *tl, const struct symbol *s);
typedef void symwalk_f(struct vcc *tl, const struct symbol *s);
void VCC_WalkSymbols(struct vcc *tl, symwalk_f *func, enum symkind kind);
-void VCC_GlobalSymbol(struct symbol *, vcc_type_t, const char *str, ...);
/* vcc_token.c */
void vcc_Coord(const struct vcc *tl, struct vsb *vsb,
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 3a6620d..3edda25 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -386,6 +386,12 @@ vcc_expr_tostring(struct vcc *tl, struct expr **e, vcc_type_t fmt)
vcc_ErrWhere2(tl, (*e)->t1, tl->t);
return;
}
+ if (p == NULL) {
+ VSB_printf(tl->sb,
+ "Cannot convert %s to STRING.\n", (*e)->fmt->name);
+ vcc_ErrWhere2(tl, (*e)->t1, tl->t);
+ return;
+ }
AN(p);
if (*p != '\0') {
*e = vcc_expr_edit(fmt, p, *e, NULL);
diff --git a/lib/libvcc/vcc_storage.c b/lib/libvcc/vcc_storage.c
index 9d17b5e..6187db4 100644
--- a/lib/libvcc/vcc_storage.c
+++ b/lib/libvcc/vcc_storage.c
@@ -60,28 +60,12 @@
#include <string.h>
#include "vcc_compile.h"
+#include "libvcc.h" // VCC_Stevedore() proto
/*--------------------------------------------------------------------
*
*/
-static struct var *
-vcc_Stv_mkvar(struct vcc *tl, vcc_type_t fmt)
-{
- struct var *v;
-
- v = TlAlloc(tl, sizeof *v);
- AN(v);
-
- v->r_methods = 0;
-#define VCL_MET_MAC(l,u,t,b) v->r_methods |= VCL_MET_##u;
-#include "tbl/vcl_returns.h"
-#undef VCL_MET_MAC
- v->fmt = fmt;
-
- return (v);
-}
-
static struct stvars {
const char *name;
vcc_type_t fmt;
@@ -92,49 +76,31 @@ static struct stvars {
{ NULL, BOOL }
};
-void __match_proto__(sym_wildcard_t)
-vcc_Stv_Wildcard(struct vcc *tl, struct symbol *parent,
- const char *b, const char *e)
+void
+VCC_Stevedore(struct vcc *vcc, const char *stv_name)
{
- const char *q;
- struct var *v = NULL;
struct symbol *sym;
struct stvars *sv;
- char stv[1024];
char buf[1024];
- for (q = b; q < e && *q != '.'; q++)
- continue;
- bprintf(stv, "%.*s", (int)(q - b), b);
-
- if (q == e) {
- v = vcc_Stv_mkvar(tl, BOOL);
- bprintf(buf, "VRT_Stv(\"%s\")", stv);
- v->rname = TlDup(tl, buf);
- } else {
- assert(*q == '.');
- q++;
- for(sv = stvars; sv->name != NULL; sv++) {
- if (strncmp(q, sv->name, e - q))
- continue;
- if (sv->name[e - q] != '\0')
- continue;
- v = vcc_Stv_mkvar(tl, sv->fmt);
- bprintf(buf, "VRT_Stv_%s(\"%s\")", sv->name, stv);
- v->rname = TlDup(tl, buf);
- break;
- }
- }
-
- if (v == NULL)
- return;
-
- sym = VCC_Symbol(tl, parent, b, e, SYM_VAR, 1);
+ CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
+ bprintf(buf, "storage.%s", stv_name);
+ sym = VCC_Symbol(vcc, NULL, buf, NULL, SYM_VAR, 1);
AN(sym);
- sym->fmt = v->fmt;
+ sym->fmt = STEVEDORE;
sym->eval = vcc_Eval_Var;
- sym->r_methods = v->r_methods;
- sym->rname = v->rname;
- sym->w_methods = v->w_methods;
- sym->lname = v->lname;
+ bprintf(buf, "VRT_stevedore(\"%s\")", stv_name);
+ sym->rname = TlDup(vcc, buf);
+ sym->r_methods = ~0;
+
+ for(sv = stvars; sv->name != NULL; sv++) {
+ bprintf(buf, "storage.%s.%s", stv_name, sv->name);
+ sym = VCC_Symbol(vcc, NULL, buf, NULL, SYM_VAR, 1);
+ AN(sym);
+ sym->fmt = sv->fmt;
+ sym->eval = vcc_Eval_Var;
+ bprintf(buf, "VRT_Stv_%s(\"%s\")", sv->name, stv_name);
+ sym->rname = TlDup(vcc, buf);
+ sym->r_methods = ~0;
+ }
}
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 701555a..c1aa72f 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -206,16 +206,6 @@ vcc_global(struct vcc *tl, struct symbol *sym,
#undef VCL_MET_MAC
}
-void
-VCC_GlobalSymbol(struct symbol *sym, vcc_type_t fmt, const char *str, ...)
-{
- va_list ap;
-
- va_start(ap, str);
- vcc_global(NULL, sym, fmt, str, ap);
- va_end(ap);
-}
-
struct symbol *
VCC_HandleSymbol(struct vcc *tl, const struct token *tk, vcc_type_t fmt,
const char *str, ...)
diff --git a/lib/libvcc/vcc_types.c b/lib/libvcc/vcc_types.c
index 65b7553..e98904c 100644
--- a/lib/libvcc/vcc_types.c
+++ b/lib/libvcc/vcc_types.c
@@ -124,6 +124,7 @@ const struct type REAL[1] = {{
const struct type STEVEDORE[1] = {{
.magic = 0xfae932d9,
.name = "STEVEDORE",
+ .tostring = "VRT_STEVEDORE_string(\v1)",
}};
const struct type STRING[1] = {{
More information about the varnish-commit
mailing list