[master] cc4455d01 Move VPI stuff out of VRT

Poul-Henning Kamp phk at FreeBSD.org
Mon Apr 29 21:31:12 UTC 2019


commit cc4455d01960671f5aa5dec3a8d72370e5084cf9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Apr 29 21:30:13 2019 +0000

    Move VPI stuff out of VRT

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 6b2e4753b..86ec2d460 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -44,6 +44,7 @@ varnishd_SOURCES = \
 	cache/cache_tcp_pool.c \
 	cache/cache_vary.c \
 	cache/cache_vcl.c \
+	cache/cache_vpi.c \
 	cache/cache_vrt.c \
 	cache/cache_vrt_filter.c \
 	cache/cache_vrt_priv.c \
diff --git a/bin/varnishd/cache/cache_vpi.c b/bin/varnishd/cache/cache_vpi.c
new file mode 100644
index 000000000..ec35ad2c7
--- /dev/null
+++ b/bin/varnishd/cache/cache_vpi.c
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2019 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.
+ *
+ */
+
+#include "config.h"
+
+#include "cache_varnishd.h"
+
+#include "vcl.h"
+
+#include "vcc_interface.h"
+
+#include "cache_vcl.h"
+
+/*--------------------------------------------------------------------
+ * Private & exclusive interfaces between VCC and varnishd
+ */
+
+void
+VPI_count(VRT_CTX, unsigned u)
+{
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->vcl->conf, VCL_CONF_MAGIC);
+	assert(u < ctx->vcl->conf->nref);
+	if (ctx->vsl != NULL)
+		VSLb(ctx->vsl, SLT_VCL_trace, "%s %u %u.%u.%u",
+		    ctx->vcl->loaded_name, u, ctx->vcl->conf->ref[u].source,
+		    ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
+	else
+		VSL(SLT_VCL_trace, 0, "%s %u %u.%u.%u",
+		    ctx->vcl->loaded_name, u, ctx->vcl->conf->ref[u].source,
+		    ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
+}
+
+VCL_VCL
+VPI_vcl_get(VRT_CTX, const char *name)
+{
+	VCL_VCL vcl;
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	vcl = vcl_find(name);
+	AN(vcl);
+	Lck_Lock(&vcl_mtx);
+	vcl->nrefs++;
+	Lck_Unlock(&vcl_mtx);
+	return (vcl);
+}
+
+void
+VPI_vcl_rel(VRT_CTX, VCL_VCL vcl)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	AN(vcl);
+	Lck_Lock(&vcl_mtx);
+	vcl->nrefs--;
+	Lck_Unlock(&vcl_mtx);
+}
+
+void
+VPI_vcl_select(VRT_CTX, VCL_VCL vcl)
+{
+	struct req *req = ctx->req;
+
+	CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+
+	if (IS_TOPREQ(req) && req->vcl0 != NULL)
+		return;		// Illega, req-FSM will fail this later.
+
+	VCL_TaskLeave(req->vcl, req->privs);
+	if (IS_TOPREQ(req)) {
+		req->vcl0 = req->vcl;
+		req->vcl = NULL;
+	} else {
+		VCL_Rel(&req->vcl);
+	}
+	vcl_get(&req->vcl, vcl);
+	VSLb(ctx->req->vsl, SLT_VCL_use, "%s via %s",
+	    req->vcl->loaded_name, vcl->loaded_name);
+	VCL_TaskEnter(req->vcl, req->privs);
+}
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 12f7843cf..30fd2a26a 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -38,8 +38,6 @@
 #include "vcl.h"
 #include "vtim.h"
 
-#include "vcc_interface.h"
-
 #include "cache_director.h"
 #include "cache_vcl.h"
 
@@ -324,75 +322,6 @@ VCL_DefaultProbe(const struct vcl *vcl)
 	return (vcl->conf->default_probe);
 }
 
-/*--------------------------------------------------------------------
- * VRT apis relating to VCL's as VCLS.
- */
-
-void
-VRT_count(VRT_CTX, unsigned u)
-{
-
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
-	CHECK_OBJ_NOTNULL(ctx->vcl->conf, VCL_CONF_MAGIC);
-	assert(u < ctx->vcl->conf->nref);
-	if (ctx->vsl != NULL)
-		VSLb(ctx->vsl, SLT_VCL_trace, "%s %u %u.%u.%u",
-		    ctx->vcl->loaded_name, u, ctx->vcl->conf->ref[u].source,
-		    ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
-	else
-		VSL(SLT_VCL_trace, 0, "%s %u %u.%u.%u",
-		    ctx->vcl->loaded_name, u, ctx->vcl->conf->ref[u].source,
-		    ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
-}
-
-VCL_VCL
-VPI_vcl_get(VRT_CTX, const char *name)
-{
-	VCL_VCL vcl;
-
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	vcl = vcl_find(name);
-	AN(vcl);
-	Lck_Lock(&vcl_mtx);
-	vcl->nrefs++;
-	Lck_Unlock(&vcl_mtx);
-	return (vcl);
-}
-
-void
-VPI_vcl_rel(VRT_CTX, VCL_VCL vcl)
-{
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	AN(vcl);
-	Lck_Lock(&vcl_mtx);
-	vcl->nrefs--;
-	Lck_Unlock(&vcl_mtx);
-}
-
-void
-VPI_vcl_select(VRT_CTX, VCL_VCL vcl)
-{
-	struct req *req = ctx->req;
-
-	CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
-
-	if (IS_TOPREQ(req) && req->vcl0 != NULL)
-		return;		// Illega, req-FSM will fail this later.
-
-	VCL_TaskLeave(req->vcl, req->privs);
-	if (IS_TOPREQ(req)) {
-		req->vcl0 = req->vcl;
-		req->vcl = NULL;
-	} else {
-		VCL_Rel(&req->vcl);
-	}
-	vcl_get(&req->vcl, vcl);
-	VSLb(ctx->req->vsl, SLT_VCL_use, "%s via %s",
-	    req->vcl->loaded_name, vcl->loaded_name);
-	VCL_TaskEnter(req->vcl, req->privs);
-}
-
 struct vclref *
 VRT_ref_vcl(VRT_CTX, const char *desc)
 {
diff --git a/include/vcc_interface.h b/include/vcc_interface.h
index f86157555..cf1845a8d 100644
--- a/include/vcc_interface.h
+++ b/include/vcc_interface.h
@@ -36,3 +36,17 @@
 VCL_VCL VPI_vcl_get(VRT_CTX, const char *);
 void VPI_vcl_rel(VRT_CTX, VCL_VCL);
 void VPI_vcl_select(VRT_CTX, VCL_VCL);
+
+/***********************************************************************
+ * VPI_count() refers to this structure for coordinates into the VCL source.
+ */
+
+struct vpi_ref {
+	unsigned	source;
+	unsigned	offset;
+	unsigned	line;
+	unsigned	pos;
+	const char	*token;
+};
+
+void VPI_count(VRT_CTX, unsigned);
diff --git a/include/vrt.h b/include/vrt.h
index cdf7bd12f..f83218efa 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -376,19 +376,6 @@ struct vrt_backend_probe {
 	VRT_BACKEND_PROBE_FIELDS(const)
 };
 
-/***********************************************************************
- * VRT_count() refers to this structure for coordinates into the VCL source.
- */
-
-struct vrt_ref {
-	unsigned	source;
-	unsigned	offset;
-	unsigned	line;
-	unsigned	pos;
-	const char	*token;
-};
-
-void VRT_count(VRT_CTX, unsigned);
 
 /***********************************************************************
  * Implementation details of ACLs
diff --git a/lib/libvcc/Makefile.am b/lib/libvcc/Makefile.am
index 2b141b542..be4d4c66d 100644
--- a/lib/libvcc/Makefile.am
+++ b/lib/libvcc/Makefile.am
@@ -42,8 +42,10 @@ dist_pkgdata_SCRIPTS = \
 ## keep in sync with include/Makefile.am
 vcc_obj.c: \
 	    $(top_srcdir)/lib/libvcc/generate.py \
+	    $(top_srcdir)/include/vcc_interface.h \
 	    $(top_srcdir)/include/vdef.h \
-	    $(top_srcdir)/include/vrt.h
+	    $(top_srcdir)/include/vrt.h \
+	    $(top_srcdir)/include/vrt_obj.h
 	mkdir -p $(top_builddir)/include/tbl
 	@PYTHON@ $(top_srcdir)/lib/libvcc/generate.py \
 	    $(top_srcdir) $(top_builddir)
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index d6b02a0e9..8da81c378 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -651,8 +651,8 @@ struct VCL_conf {
 	unsigned		syntax;
 	VCL_BACKEND		*default_director;
 	VCL_PROBE		default_probe;
-	int			nref;
-	const struct vrt_ref	*ref;
+	unsigned		nref;
+	const struct vpi_ref	*ref;
 
 	int			nsrc;
 	const char		**srcname;
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 6f2e38adc..6b0ac88a6 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -243,7 +243,7 @@ EmitCoordinates(const struct vcc *tl, struct vsb *vsb)
 
 	VSB_printf(vsb, "\n#define VGC_NREFS %u\n\n", tl->cnt + 1);
 
-	VSB_printf(vsb, "static const struct vrt_ref VGC_ref[VGC_NREFS] = {\n");
+	VSB_printf(vsb, "static const struct vpi_ref VGC_ref[VGC_NREFS] = {\n");
 	lin = 1;
 	pos = 0;
 	sp = 0;
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index f47991748..1e0bbd355 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -46,7 +46,7 @@ static void vcc_Compound(struct vcc *tl);
 } while (0)
 
 #define C(tl, sep)	do {					\
-	Fb(tl, 1, "VRT_count(ctx, %u)%s\n", ++tl->cnt, sep);	\
+	Fb(tl, 1, "VPI_count(ctx, %u)%s\n", ++tl->cnt, sep);	\
 	tl->t->cnt = tl->cnt;					\
 } while (0)
 


More information about the varnish-commit mailing list