Hi,

Continuing on the dynamic backends track, here is a patch to allow
manipulation of probes. It is not usable yet, but will hopefully be
soon.

Best Regards,
Dridi
From 04f3e8149a499e25a60df4ff39d38df32f5ad4e9 Mon Sep 17 00:00:00 2001
From: Dridi Boukelmoune <[email protected]>
Date: Tue, 16 Jun 2015 14:35:15 +0200
Subject: [PATCH] Allow probes references in VCL and VMODs

Make sure probes can be managed outside of the cli thread, even though
it can't be tested yet.
---
 bin/varnishd/cache/cache_backend_poll.c |  3 ---
 include/vrt.h                           | 29 +++++++++++++++--------------
 lib/libvcc/vcc_backend.c                | 13 ++++++++++---
 lib/libvcc/vcc_compile.h                |  1 +
 lib/libvcc/vcc_expr.c                   | 20 ++++++++++++++++++++
 lib/libvcc/vmodtool.py                  |  1 +
 6 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c
index c658417..9f3f081 100644
--- a/bin/varnishd/cache/cache_backend_poll.c
+++ b/bin/varnishd/cache/cache_backend_poll.c
@@ -496,7 +496,6 @@ VBP_Control(const struct backend *be, int enable)
 {
 	struct vbp_target *vt;
 
-	ASSERT_CLI();
 	CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
 	vt = be->probe;
 	CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
@@ -527,7 +526,6 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p,
 {
 	struct vbp_target *vt;
 
-	ASSERT_CLI();
 	CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
 	CHECK_OBJ_NOTNULL(p, VRT_BACKEND_PROBE_MAGIC);
 
@@ -556,7 +554,6 @@ VBP_Remove(struct backend *be)
 {
 	struct vbp_target *vt;
 
-	ASSERT_CLI();
 	CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
 	vt = be->probe;
 	CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
diff --git a/include/vrt.h b/include/vrt.h
index cbed87b..7e94387 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -66,20 +66,21 @@ struct vmod;
  * (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 59fb851..c59e73e 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -236,7 +236,7 @@ void
 vcc_ParseProbe(struct vcc *tl)
 {
 	struct token *t_probe;
-	int i;
+	struct symbol *sym;
 
 	vcc_NextToken(tl);		/* ID: probe */
 
@@ -244,11 +244,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);
 
 	Fh(tl, 0, "\n#define vgc_probe_%.*s\tvgc_probe__%d\n",
 	    PF(t_probe), tl->nprobe);
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index a222b9b..091588e 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -279,6 +279,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 df5aa43..4e053dc 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -515,6 +515,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)
 {
@@ -811,6 +828,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)
@@ -830,6 +849,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 a5eb8bb..98143b4 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 *, ...",
-- 
2.1.0

_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to