[master] 73bd54c Add support code for living with multiple VCL versions at the same time.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Feb 19 09:47:06 UTC 2018
commit 73bd54ccaae36f288c0a54b82e171b3d14affce4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Feb 19 09:26:18 2018 +0000
Add support code for living with multiple VCL versions at the same time.
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 7bde5b8..12280e1 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -518,6 +518,12 @@ VCL_Open(const char *fn, struct vsb *msg)
(void)dlclose(dlh);
return (NULL);
}
+ if (cnf->syntax < heritage.min_vcl || cnf->syntax > heritage.max_vcl) {
+ VSB_printf(msg, "Compiled VCL version (%.1f) not supported.\n",
+ .1 * cnf->syntax);
+ (void)dlclose(dlh);
+ return (NULL);
+ }
ALLOC_OBJ(vcl, VCL_MAGIC);
AN(vcl);
AZ(errno=pthread_rwlock_init(&vcl->temp_rwl, NULL));
diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h
index e59261e..64131d6 100644
--- a/bin/varnishd/common/heritage.h
+++ b/bin/varnishd/common/heritage.h
@@ -81,6 +81,9 @@ struct heritage {
long mgt_pid;
struct vsmw *proc_vsmw;
+
+ unsigned min_vcl;
+ unsigned max_vcl;
};
extern struct heritage heritage;
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index f23bc75..8e968ed 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -46,6 +46,7 @@
#include "common/heritage.h"
#include "hash/hash_slinger.h"
+#include "libvcc.h"
#include "vav.h"
#include "vcli_serve.h"
#include "vend.h"
@@ -274,6 +275,9 @@ mgt_initialize(struct cli *cli)
mgt_cli_init_cls(); // CLI commands can be registered
MCF_InitParams(cli);
+
+ VCC_VCL_Range(&heritage.min_vcl, &heritage.max_vcl);
+
cli_check(cli);
}
diff --git a/doc/sphinx/reference/vcl_var.rst b/doc/sphinx/reference/vcl_var.rst
index 8aa8983..f94841a 100644
--- a/doc/sphinx/reference/vcl_var.rst
+++ b/doc/sphinx/reference/vcl_var.rst
@@ -29,7 +29,7 @@ When setting a variable, the right hand side of the equal sign
must have the variables type, you cannot assign a STRING to
a variable of type NUMBER, even if the string is `"42"`.
(Explicit conversion functions can be found in
-:ref:`vmod_std(3)` .
+:ref:`vmod_std(3)`).
local, server, remote and client
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/include/libvcc.h b/include/libvcc.h
index 78bf5fa..31b2a7f 100644
--- a/include/libvcc.h
+++ b/include/libvcc.h
@@ -40,6 +40,7 @@ void VCC_Unsafe_Path(struct vcc *, unsigned);
void VCC_VCL_path(struct vcc *, const char *);
void VCC_VMOD_path(struct vcc *, const char *);
void VCC_Predef(struct vcc *, const char *type, const char *name);
+void VCC_VCL_Range(unsigned *, unsigned *);
struct vsb *VCC_Compile(struct vcc *, struct vsb **,
const char *vclsrc, const char *vclsrcfile);
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index ea8fdf8..758b7e7 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -670,6 +670,19 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
}
/*--------------------------------------------------------------------
+ * Report the range of VCL language we support
+ */
+void
+VCC_VCL_Range(unsigned *lo, unsigned *hi)
+{
+
+ AN(lo);
+ *lo = VCL_LOW;
+ AN(hi);
+ *hi = VCL_HIGH;
+}
+
+/*--------------------------------------------------------------------
* Compile the VCL code in the argument. Error messages, if any are
* formatted into the vsb.
*/
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index dd9a33a..bdbb3a6 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -41,9 +41,18 @@
#include "vcc_token_defs.h"
-#ifndef NULL
-#define NULL ((void*)0)
-#endif
+/*---------------------------------------------------------------------
+ * VCL version stuff
+ */
+
+#define VCL_LOW 40 // Lowest VCC supports
+#define VCL_HIGH 41 // Highest VCC supports
+
+// Specific VCL versions
+#define VCL_40 40
+#define VCL_41 41
+
+/*---------------------------------------------------------------------*/
struct vsb;
struct token;
@@ -126,11 +135,15 @@ struct symbol {
VTAILQ_ENTRY(symbol) list;
VTAILQ_HEAD(,symbol) children;
+ char *name;
+ unsigned nlen;
+
+ unsigned lorev;
+ unsigned hirev;
+
struct symbol *parent;
const char *vmod;
- char *name;
- unsigned nlen;
sym_wildcard_t *wildcard;
vcc_kind_t kind;
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index 16ba0b7..bccd27e 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -367,7 +367,7 @@ vcc_Parse(struct vcc *tl)
}
tok = tl->t;
vcc_ParseVcl(tl);
- if (tok->src->syntax < 40 || tok->src->syntax > 41) {
+ if (tok->src->syntax < VCL_LOW || tok->src->syntax > VCL_HIGH) {
VSB_printf(tl->sb, "VCL version %.1f not supported.\n",
.1 * tok->src->syntax);
vcc_ErrWhere2(tl, tok, tl->t);
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index b5df60c..a039006 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -93,6 +93,8 @@ vcc_new_symbol(struct vcc *tl, const char *b, const char *e)
VTAILQ_INIT(&sym->children);
sym->kind = SYM_NONE;
sym->type = VOID;
+ sym->lorev = VCL_LOW;
+ sym->hirev = VCL_HIGH;
return (sym);
}
@@ -140,7 +142,8 @@ VCC_Symbol(struct vcc *tl, struct symbol *parent,
break;
if ((kind == SYM_NONE && kind == sym->kind))
continue;
- if (tl->syntax < 41 && (kind != SYM_NONE && kind != sym->kind))
+ if (tl->syntax < VCL_41 &&
+ (kind != SYM_NONE && kind != sym->kind))
continue;
break;
}
@@ -192,7 +195,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_kind_t kind, const char *e, const char *x)
struct symbol *sym;
AN(e);
- if (tl->syntax >= 41 && e == SYMTAB_CREATE && kind != SYM_SUB &&
+ if (tl->syntax >= VCL_41 && e == SYMTAB_CREATE && kind != SYM_SUB &&
(tl->t->b[0] == 'v'|| tl->t->b[0] == 'V') &&
(tl->t->b[1] == 'c'|| tl->t->b[1] == 'C') &&
(tl->t->b[2] == 'l'|| tl->t->b[2] == 'L')) {
@@ -213,6 +216,20 @@ VCC_SymbolGet(struct vcc *tl, vcc_kind_t kind, const char *e, const char *x)
vcc_ErrWhere(tl, tl->t);
return (NULL);
}
+ if (sym->lorev > tl->syntax || sym->hirev < tl->syntax) {
+ VSB_printf(tl->sb, "Symbol ");
+ vcc_ErrToken(tl, tl->t);
+ if (sym->lorev > tl->syntax)
+ VSB_printf(tl->sb, " needs vcl %.1f or higher.",
+ .1 * sym->lorev);
+ else
+ VSB_printf(tl->sb,
+ " is discontinued after vcl %.1f.",
+ .1 * sym->hirev);
+ VSB_cat(tl->sb, "\nAt: ");
+ vcc_ErrWhere(tl, tl->t);
+ return(NULL);
+ }
if (kind != SYM_NONE && kind != sym->kind) {
VSB_printf(tl->sb, "Symbol ");
vcc_ErrToken(tl, tl->t);
More information about the varnish-commit
mailing list