[master] cfb9223 Teach VCC how to put backend-VSC's into a VSM-cluster.

Poul-Henning Kamp phk at FreeBSD.org
Fri Jan 5 10:36:09 UTC 2018


commit cfb922305af6126c3437a3b5ff8d74c983560ae7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Jan 5 10:19:02 2018 +0000

    Teach VCC how to put backend-VSC's into a VSM-cluster.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 601beaf..9da3fca 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -423,8 +423,16 @@ vbe_panic(const struct director *d, struct vsb *vsb)
  * Create a new static or dynamic director::backend instance.
  */
 
-struct director *
-VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
+size_t v_matchproto_()
+VRT_backend_vsm_need(VRT_CTX)
+{
+	(void)ctx;
+	return (VSC_vbe_size);
+}
+
+struct director * v_matchproto_()
+VRT_new_backend_clustered(VRT_CTX, struct vsm_cluster *vc,
+    const struct vrt_backend *vrt)
 {
 	struct backend *be;
 	struct director *d;
@@ -433,6 +441,7 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
 	int retval;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	(void)vc;
 	CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC);
 	assert(vrt->ipv4_suckaddr != NULL || vrt->ipv6_suckaddr != NULL);
 
@@ -495,6 +504,12 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
 	return (NULL);
 }
 
+struct director * v_matchproto_()
+VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
+{
+	return (VRT_new_backend_clustered(ctx, NULL, vrt));
+}
+
 /*--------------------------------------------------------------------
  * Delete a dynamic director::backend instance.  Undeleted dynamic and
  * static instances are GC'ed when the VCL is discarded (in cache_vcl.c)
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 9adc590..e8e212c 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -623,6 +623,16 @@ VRT_purge(VRT_CTX, double ttl, double grace, double keep)
 }
 
 /*--------------------------------------------------------------------
+ */
+
+struct vsm_cluster *
+VRT_VSM_Cluster(size_t sz)
+{
+	AN(sz);
+	return ((void*)VRT_VSM_Cluster);
+}
+
+/*--------------------------------------------------------------------
  * Simple stuff
  */
 
diff --git a/include/vrt.h b/include/vrt.h
index 9a01feb..ff70504 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -387,9 +387,14 @@ void VRT_synth_page(VRT_CTX, const char *, ...);
 
 /* Backend related */
 struct director *VRT_new_backend(VRT_CTX, const struct vrt_backend *);
+struct director *VRT_new_backend_clustered(VRT_CTX,
+    struct vsm_cluster *, const struct vrt_backend *);
+size_t VRT_backend_vsm_need(VRT_CTX);
 void VRT_delete_backend(VRT_CTX, struct director **);
 int VRT_backend_healthy(VRT_CTX, struct director *);
 
+/* VSM related */
+struct vsm_cluster *VRT_VSM_Cluster(size_t);
 
 /* cache_director.c */
 int VRT_Healthy(VRT_CTX, VCL_BACKEND);
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 54458d8..4b81bf2 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -449,7 +449,8 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
 
 	ifp = New_IniFin(tl);
 	VSB_printf(ifp->ini,
-	    "\t%s =\n\t    VRT_new_backend(ctx, &vgc_dir_priv_%s);",
+	    "\t%s =\n\t    VRT_new_backend_clustered(ctx, vc,\n"
+	    "\t\t&vgc_dir_priv_%s);",
 	    vgcname, vgcname);
 }
 
@@ -463,6 +464,7 @@ vcc_ParseBackend(struct vcc *tl)
 	struct token *t_first, *t_be;
 	struct symbol *sym;
 
+	tl->ndirector++;
 	t_first = tl->t;
 	vcc_NextToken(tl);		/* ID: backend */
 
@@ -492,3 +494,16 @@ vcc_ParseBackend(struct vcc *tl)
 		tl->t_default_director = t_be;
 	}
 }
+
+void
+vcc_Backend_Init(struct vcc *tl)
+{
+	struct inifin *ifp;
+
+	ifp = New_IniFin(tl);
+	VSB_printf(ifp->ini, "\tstruct vsm_cluster *vc;\n");
+	VSB_printf(ifp->ini, "\n");
+	VSB_printf(ifp->ini,
+	    "\tvc = VRT_VSM_Cluster(ndirector * VRT_backend_vsm_need(ctx));\n");
+	VSB_printf(ifp->ini, "\tif (vc == 0)\n\t\treturn(1);");
+}
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 28975b0..a079aee 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -298,7 +298,9 @@ EmitInitFini(const struct vcc *tl)
 	 * LOAD
 	 */
 	Fc(tl, 0, "\nstatic int\nVGC_Load(VRT_CTX)\n{\n\n");
-	Fc(tl, 0, "\tvgc_inistep = 0;\n\n");
+	Fc(tl, 0, "\tvgc_inistep = 0;\n");
+	Fc(tl, 0, "\tsize_t ndirector = %dUL;\n", tl->ndirector);
+	Fc(tl, 0, "\n");
 	VTAILQ_FOREACH(p, &tl->inifin, list) {
 		AZ(VSB_finish(p->ini));
 		assert(p->n > 0);
@@ -560,6 +562,8 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
 
 	vcc_Expr_Init(tl);
 
+	vcc_Backend_Init(tl);
+
 	for (v = vcc_vars; v->name != NULL; v++) {
 		if (v->fmt == HEADER) {
 			sym = VCC_Symbol(tl, NULL, v->name, NULL,
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 47d8525..d0c040c 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -217,6 +217,7 @@ struct vcc {
 
 	int			nprobe;
 
+	int			ndirector;
 	const char		*default_director;
 	struct token		*t_default_director;
 	const char		*default_probe;
@@ -252,6 +253,7 @@ int vcc_ParseAction(struct vcc *tl);
 /* vcc_backend.c */
 struct fld_spec;
 
+void vcc_Backend_Init(struct vcc *tl);
 void vcc_ParseProbe(struct vcc *tl);
 void vcc_ParseBackend(struct vcc *tl);
 struct fld_spec * vcc_FldSpec(struct vcc *tl, const char *first, ...);
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index c0c6d80..e368cf9 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -143,6 +143,9 @@ class vscset(object):
 		fo.write("};\n")
 		fo.write("\n")
 
+		fo.write("#define VSC_" + self.name + 
+		    "_size PRNDUP(sizeof(" + self.struct + "))\n\n")
+
 		fo.write(self.struct + " *VSC_" + self.name + "_New")
 		fo.write("(struct vsm_cluster *,\n")
 		fo.write("    struct vsc_seg **, const char *fmt, ...);\n")


More information about the varnish-commit mailing list