[master] 17f2e93 Remove the VCC generated round-robin and fallback directors, these now live in VMOD.directors (and can be stacked :-)

Poul-Henning Kamp phk at varnish-cache.org
Mon Mar 11 13:21:53 CET 2013


commit 17f2e93821167ca590f2b39d0cfbb57871198c8e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Mar 11 12:21:18 2013 +0000

    Remove the VCC generated round-robin and fallback directors,
    these now live in VMOD.directors (and can be stacked :-)

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 0165696..378ce55 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -21,7 +21,6 @@ varnishd_SOURCES = \
 	cache/cache_dir.c \
 	cache/cache_dir_dns.c \
 	cache/cache_dir_random.c \
-	cache/cache_dir_round_robin.c \
 	cache/cache_esi_deliver.c \
 	cache/cache_esi_fetch.c \
 	cache/cache_esi_parse.c \
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index fb88308..b1e8d89 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -187,6 +187,4 @@ dir_init_f VRT_init_dir_simple;
 dir_init_f VRT_init_dir_dns;
 dir_init_f VRT_init_dir_hash;
 dir_init_f VRT_init_dir_random;
-dir_init_f VRT_init_dir_round_robin;
-dir_init_f VRT_init_dir_fallback;
 dir_init_f VRT_init_dir_client;
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index 3f15ada..2cda875 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -257,10 +257,6 @@ VRT_init_dir(struct cli *cli, struct director **dir, const char *name,
 		VRT_init_dir_random(cli, dir, idx, priv);
 	else if (!strcmp(name, "dns"))
 		VRT_init_dir_dns(cli, dir, idx, priv);
-	else if (!strcmp(name, "round-robin"))
-		VRT_init_dir_round_robin(cli, dir, idx, priv);
-	else if (!strcmp(name, "fallback"))
-		VRT_init_dir_fallback(cli, dir, idx, priv);
 	else if (!strcmp(name, "client"))
 		VRT_init_dir_client(cli, dir, idx, priv);
 	else
diff --git a/bin/varnishd/cache/cache_dir_round_robin.c b/bin/varnishd/cache/cache_dir_round_robin.c
deleted file mode 100644
index b3a57f2..0000000
--- a/bin/varnishd/cache/cache_dir_round_robin.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*-
- * Copyright (c) 2008-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Petter Knudsen <petter at linpro.no>
- *
- * 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 <stdlib.h>
-
-#include "cache.h"
-
-#include "cache_backend.h"
-#include "vrt.h"
-
-/*--------------------------------------------------------------------*/
-
-struct vdi_round_robin_host {
-	struct director			*backend;
-};
-
-enum mode_e { m_round_robin, m_fallback };
-
-struct vdi_round_robin {
-	unsigned			magic;
-#define VDI_ROUND_ROBIN_MAGIC		0x2114a178
-	struct director			dir;
-	enum mode_e			mode;
-	struct vdi_round_robin_host	*hosts;
-	unsigned			nhosts;
-	unsigned			next_host;
-};
-
-static struct vbc *
-vdi_round_robin_getfd(const struct director *d, struct req *req)
-{
-	int i;
-	struct vdi_round_robin *vs;
-	struct director *backend;
-	struct vbc *vbe;
-
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	CAST_OBJ_NOTNULL(vs, d->priv, VDI_ROUND_ROBIN_MAGIC);
-
-	/*
-	 * In fallback mode we ignore the next_host and always grab the
-	 * first healthy backend we can find.
-	 */
-	for (i = 0; i < vs->nhosts; i++) {
-		if (vs->mode == m_round_robin) {
-			backend = vs->hosts[vs->next_host].backend;
-			vs->next_host = (vs->next_host + 1) % vs->nhosts;
-		} else /* m_fallback */ {
-			backend = vs->hosts[i].backend;
-		}
-		if (!VDI_Healthy(backend, req))
-			continue;
-		vbe = VDI_GetFd(backend, req);
-		if (vbe != NULL)
-			return (vbe);
-	}
-
-	return (NULL);
-}
-
-static unsigned
-vdi_round_robin_healthy(const struct director *d, const struct req *req)
-{
-	struct vdi_round_robin *vs;
-	struct director *backend;
-	int i;
-
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	CAST_OBJ_NOTNULL(vs, d->priv, VDI_ROUND_ROBIN_MAGIC);
-
-	for (i = 0; i < vs->nhosts; i++) {
-		backend = vs->hosts[i].backend;
-		if (VDI_Healthy(backend, req))
-			return (1);
-	}
-	return (0);
-}
-
-static void
-vdi_round_robin_fini(const struct director *d)
-{
-	struct vdi_round_robin *vs;
-
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	CAST_OBJ_NOTNULL(vs, d->priv, VDI_ROUND_ROBIN_MAGIC);
-
-	free(vs->hosts);
-	free(vs->dir.vcl_name);
-	vs->dir.magic = 0;
-	vs->next_host = 0;
-	FREE_OBJ(vs);
-}
-
-static void
-vrt_init_dir(struct cli *cli, struct director **bp, int idx,
-    const void *priv, enum mode_e mode)
-{
-	const struct vrt_dir_round_robin *t;
-	struct vdi_round_robin *vs;
-	const struct vrt_dir_round_robin_entry *te;
-	struct vdi_round_robin_host *vh;
-	int i;
-
-	ASSERT_CLI();
-	(void)cli;
-	t = priv;
-
-	ALLOC_OBJ(vs, VDI_ROUND_ROBIN_MAGIC);
-	XXXAN(vs);
-	vs->hosts = calloc(sizeof *vh, t->nmember);
-	XXXAN(vs->hosts);
-
-	vs->dir.magic = DIRECTOR_MAGIC;
-	vs->dir.priv = vs;
-	vs->dir.name = "round_robin";
-	REPLACE(vs->dir.vcl_name, t->name);
-	vs->dir.getfd = vdi_round_robin_getfd;
-	vs->dir.fini = vdi_round_robin_fini;
-	vs->dir.healthy = vdi_round_robin_healthy;
-
-	vs->mode = mode;
-	vh = vs->hosts;
-	te = t->members;
-	for (i = 0; i < t->nmember; i++, vh++, te++) {
-		vh->backend = bp[te->host];
-		AN(vh->backend);
-	}
-	vs->nhosts = t->nmember;
-	vs->next_host = 0;
-
-	bp[idx] = &vs->dir;
-}
-
-void
-VRT_init_dir_round_robin(struct cli *cli, struct director **bp, int idx,
-    const void *priv)
-{
-	vrt_init_dir(cli, bp, idx, priv, m_round_robin);
-}
-
-void
-VRT_init_dir_fallback(struct cli *cli, struct director **bp, int idx,
-    const void *priv)
-{
-	vrt_init_dir(cli, bp, idx, priv, m_fallback);
-}
diff --git a/include/vrt.h b/include/vrt.h
index a2550aa..228781d 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -122,20 +122,6 @@ struct vrt_dir_random {
 };
 
 /*
- * A director with round robin selection
- */
-
-struct vrt_dir_round_robin_entry {
-	int					host;
-};
-
-struct vrt_dir_round_robin {
-	const char				*name;
-	unsigned				nmember;
-	const struct vrt_dir_round_robin_entry	*members;
-};
-
-/*
  * A director with dns-based selection
  */
 
diff --git a/lib/libvcl/Makefile.am b/lib/libvcl/Makefile.am
index be3efe0..88c8f75 100644
--- a/lib/libvcl/Makefile.am
+++ b/lib/libvcl/Makefile.am
@@ -18,7 +18,6 @@ libvcl_la_SOURCES = \
 	vcc_backend_util.c \
 	vcc_compile.c \
 	vcc_dir_random.c \
-	vcc_dir_round_robin.c \
 	vcc_dir_dns.c \
 	vcc_expr.c \
 	vcc_parse.c \
diff --git a/lib/libvcl/vcc_backend.c b/lib/libvcl/vcc_backend.c
index a480edd..47e3280 100644
--- a/lib/libvcl/vcc_backend.c
+++ b/lib/libvcl/vcc_backend.c
@@ -696,6 +696,7 @@ vcc_ParseSimpleDirector(struct vcc *tl)
  * Parse directors and backends
  */
 
+
 static const struct dirlist {
 	const char	*name;
 	parsedirector_f	*func;
@@ -703,8 +704,8 @@ static const struct dirlist {
 	{ "hash",		vcc_ParseRandomDirector },
 	{ "random",		vcc_ParseRandomDirector },
 	{ "client",		vcc_ParseRandomDirector },
-	{ "round-robin",	vcc_ParseRoundRobinDirector },
-	{ "fallback",		vcc_ParseRoundRobinDirector },
+	{ "round-robin",	NULL },
+	{ "fallback",		NULL },
 	{ "dns",		vcc_ParseDnsDirector },
 	{ NULL,		NULL }
 };
@@ -753,6 +754,13 @@ vcc_ParseDirector(struct vcc *tl)
 			vcc_ErrWhere(tl, tl->t_policy);
 			return;
 		}
+		if (dl->func == NULL) {
+			VSB_printf(tl->sb,
+			    "\n%.*s director are now in VMOD.directors\n",
+				PF(tl->t_policy));
+			vcc_ErrWhere(tl, tl->t_policy);
+			return;
+		}
 		Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n",
 		    PF(tl->t_dir));
 		SkipToken(tl, '{');
diff --git a/lib/libvcl/vcc_compile.h b/lib/libvcl/vcc_compile.h
index 162fef6..1e51f5f 100644
--- a/lib/libvcl/vcc_compile.h
+++ b/lib/libvcl/vcc_compile.h
@@ -269,9 +269,6 @@ void EncString(struct vsb *sb, const char *b, const char *e, int mode);
 /* vcc_dir_random.c */
 parsedirector_f vcc_ParseRandomDirector;
 
-/* vcc_dir_round_robin.c */
-parsedirector_f vcc_ParseRoundRobinDirector;
-
 /* vcc_expr.c */
 void vcc_Duration(struct vcc *tl, double *);
 unsigned vcc_UintVal(struct vcc *tl);
diff --git a/lib/libvcl/vcc_dir_round_robin.c b/lib/libvcl/vcc_dir_round_robin.c
deleted file mode 100644
index 835d969..0000000
--- a/lib/libvcl/vcc_dir_round_robin.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * Copyright (c) 2008-2009 Varnish Software AS
- * All rights reserved.
- *
- * Author: Petter Knudsen <petter at linpro.no>
- *
- * 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 "vcc_compile.h"
-
-/*--------------------------------------------------------------------
- * Parse directors
- */
-
-void
-vcc_ParseRoundRobinDirector(struct vcc *tl)
-{
-	struct token *t_field, *t_be;
-	int nelem;
-	struct fld_spec *fs;
-	const char *first;
-	char *p;
-
-	fs = vcc_FldSpec(tl, "!backend", NULL);
-
-	Fc(tl, 0, "\nstatic const struct vrt_dir_round_robin_entry "
-	    "vdrre_%.*s[] = {\n", PF(tl->t_dir));
-
-	for (nelem = 0; tl->t->tok != '}'; nelem++) {	/* List of members */
-		first = "";
-		t_be = tl->t;
-		vcc_ResetFldSpec(fs);
-
-		SkipToken(tl, '{');
-		Fc(tl, 0, "\t{");
-
-		while (tl->t->tok != '}') {	/* Member fields */
-			vcc_IsField(tl, &t_field, fs);
-			ERRCHK(tl);
-			if (vcc_IdIs(t_field, "backend")) {
-				vcc_ParseBackendHost(tl, nelem, &p);
-				ERRCHK(tl);
-				AN(p);
-				Fc(tl, 0, "%s .host = VGC_backend_%s",
-				    first, p);
-			} else {
-				ErrInternal(tl);
-			}
-			first = ", ";
-		}
-		vcc_FieldsOk(tl, fs);
-		if (tl->err) {
-			VSB_printf(tl->sb,
-			    "\nIn member host specification starting at:\n");
-			vcc_ErrWhere(tl, t_be);
-			return;
-		}
-		Fc(tl, 0, " },\n");
-		vcc_NextToken(tl);
-	}
-	Fc(tl, 0, "};\n");
-	Fc(tl, 0,
-	    "\nstatic const struct vrt_dir_round_robin vgc_dir_priv_%.*s = {\n",
-	    PF(tl->t_dir));
-	Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(tl->t_dir));
-	Fc(tl, 0, "\t.nmember = %d,\n", nelem);
-	Fc(tl, 0, "\t.members = vdrre_%.*s,\n", PF(tl->t_dir));
-	Fc(tl, 0, "};\n");
-}



More information about the varnish-commit mailing list