[4.1] 6b4cbe2 Expose VCL probes to VMODs
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Sep 4 15:54:55 CEST 2015
commit 6b4cbe2645331fb5466b6a5a8695a0913d2b1b1a
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Aug 18 11:40:08 2015 +0200
Expose VCL probes to VMODs
diff --git a/doc/sphinx/reference/directors.rst b/doc/sphinx/reference/directors.rst
index cbd8a42..8a16c87 100644
--- a/doc/sphinx/reference/directors.rst
+++ b/doc/sphinx/reference/directors.rst
@@ -150,4 +150,5 @@ too is no longer needed. It is then Varnish that will take care of health
probing and disabling the feature on cold VCL (see
:ref:`ref-vmod-event-functions`).
-.. TODO document VCL_PROBE if patchwork #310 is merged
+Instead of initializing your own probe definition, you can get a ``VCL_PROBE``
+directly built from VCL (see :ref:`ref-vmod-vcl-c-types`).
diff --git a/doc/sphinx/reference/vmod.rst b/doc/sphinx/reference/vmod.rst
index 57db2a8..0446e83 100644
--- a/doc/sphinx/reference/vmod.rst
+++ b/doc/sphinx/reference/vmod.rst
@@ -193,7 +193,10 @@ PRIV_TOP
PRIV_VCL
See :ref:`ref-vmod-private-pointers` below.
-.. TODO document PROBE if patchwork #310 is merged
+PROBE
+ C-type: ``const struct vrt_backend_probe *``
+
+ A named standalone backend probe definition.
REAL
C-type: ``double``
diff --git a/include/vrt.h b/include/vrt.h
index 98168a3..4b429dd 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -67,20 +67,21 @@ struct ws;
* (alphabetic order)
*/
-typedef const struct director * VCL_BACKEND;
-typedef const struct vmod_priv * VCL_BLOB;
-typedef unsigned VCL_BOOL;
-typedef double VCL_BYTES;
-typedef double VCL_DURATION;
-typedef const char * VCL_ENUM;
-typedef const struct gethdr_s * VCL_HEADER;
-typedef struct http * VCL_HTTP;
-typedef long VCL_INT;
-typedef const struct suckaddr * VCL_IP;
-typedef double VCL_REAL;
-typedef const char * VCL_STRING;
-typedef double VCL_TIME;
-typedef void VCL_VOID;
+typedef const struct director * VCL_BACKEND;
+typedef const struct vmod_priv * VCL_BLOB;
+typedef unsigned VCL_BOOL;
+typedef double VCL_BYTES;
+typedef double VCL_DURATION;
+typedef const char * VCL_ENUM;
+typedef const struct gethdr_s * VCL_HEADER;
+typedef struct http * VCL_HTTP;
+typedef long VCL_INT;
+typedef const struct suckaddr * VCL_IP;
+typedef const struct vrt_backend_probe * VCL_PROBE;
+typedef double VCL_REAL;
+typedef const char * VCL_STRING;
+typedef double VCL_TIME;
+typedef void VCL_VOID;
/***********************************************************************
* This is the composite argument we pass to compiled VCL and VRT
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index c0501a3..14aedf3 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -249,7 +249,7 @@ void
vcc_ParseProbe(struct vcc *tl)
{
struct token *t_probe;
- int i;
+ struct symbol *sym;
char *p;
vcc_NextToken(tl); /* ID: probe */
@@ -258,11 +258,18 @@ vcc_ParseProbe(struct vcc *tl)
ERRCHK(tl);
t_probe = tl->t;
vcc_NextToken(tl);
- i = vcc_AddDef(tl, t_probe, SYM_PROBE);
- if (i > 1) {
+
+ sym = VCC_GetSymbolTok(tl, t_probe, SYM_PROBE);
+ AN(sym);
+ if (sym->ndef > 0) {
VSB_printf(tl->sb, "Probe %.*s redefined\n", PF(t_probe));
vcc_ErrWhere(tl, t_probe);
+ return;
}
+ sym->fmt = PROBE;
+ sym->eval = vcc_Eval_Probe;
+ sym->ndef++;
+ ERRCHK(tl);
vcc_ParseProbeSpec(tl, t_probe, &p);
if (vcc_IdIs(t_probe, "default")) {
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 86f731d..893369e 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -280,6 +280,7 @@ sym_expr_t vcc_Eval_SymFunc;
void vcc_Eval_Func(struct vcc *tl, const char *cfunc, const char *extra,
const char *name, const char *args);
sym_expr_t vcc_Eval_Backend;
+sym_expr_t vcc_Eval_Probe;
/* vcc_obj.c */
extern const struct var vcc_vars[];
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index b9c6531..294d12a 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -516,6 +516,23 @@ vcc_Eval_Backend(struct vcc *tl, struct expr **e, const struct symbol *sym)
/*--------------------------------------------------------------------
*/
+
+void
+vcc_Eval_Probe(struct vcc *tl, struct expr **e, const struct symbol *sym)
+{
+
+ assert(sym->kind == SYM_PROBE);
+
+ vcc_ExpectCid(tl);
+ vcc_AddRef(tl, tl->t, SYM_PROBE);
+ *e = vcc_mk_expr(PROBE, "&vgc_probe_%.*s", PF(tl->t));
+ (*e)->constant = EXPR_VAR; /* XXX ? */
+ vcc_NextToken(tl);
+}
+
+/*--------------------------------------------------------------------
+ */
+
void
vcc_Eval_Var(struct vcc *tl, struct expr **e, const struct symbol *sym)
{
@@ -812,6 +829,8 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
sym = NULL;
if (fmt == BACKEND)
sym = VCC_FindSymbol(tl, tl->t, SYM_BACKEND);
+ if (fmt == PROBE)
+ sym = VCC_FindSymbol(tl, tl->t, SYM_PROBE);
if (sym == NULL)
sym = VCC_FindSymbol(tl, tl->t, SYM_VAR);
if (sym == NULL)
@@ -831,6 +850,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
case SYM_VAR:
case SYM_FUNC:
case SYM_BACKEND:
+ case SYM_PROBE:
AN(sym->eval);
AZ(*e);
sym->eval(tl, e, sym);
diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py
index 01de3a7..5a6c0fc 100755
--- a/lib/libvcc/vmodtool.py
+++ b/lib/libvcc/vmodtool.py
@@ -60,6 +60,7 @@ ctypes = {
'PRIV_VCL': "struct vmod_priv *",
'PRIV_TASK': "struct vmod_priv *",
'PRIV_TOP': "struct vmod_priv *",
+ 'PROBE': "VCL_PROBE",
'REAL': "VCL_REAL",
'STRING': "VCL_STRING",
'STRING_LIST': "const char *, ...",
More information about the varnish-commit
mailing list