r2431 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Feb 5 12:19:22 CET 2008


Author: phk
Date: 2008-02-05 12:19:22 +0100 (Tue, 05 Feb 2008)
New Revision: 2431

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_cli.c
   trunk/varnish-cache/bin/varnishd/cache_vcl.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
Log:
Add the missing bits to actually allow discards of VCL code.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2008-02-05 10:50:33 UTC (rev 2430)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2008-02-05 11:19:22 UTC (rev 2431)
@@ -595,6 +595,7 @@
 void VCL_Refresh(struct VCL_conf **vcc);
 void VCL_Rel(struct VCL_conf **vcc);
 void VCL_Get(struct VCL_conf **vcc);
+void VCL_Idle(void);
 
 #define VCL_RET_MAC(l,u,b,n)
 #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *);

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2008-02-05 10:50:33 UTC (rev 2430)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2008-02-05 11:19:22 UTC (rev 2431)
@@ -51,7 +51,6 @@
 
 struct backendlist backendlist = VTAILQ_HEAD_INITIALIZER(backendlist);
 
-
 /*--------------------------------------------------------------------
  * Attempt to connect to a given addrinfo entry.
  *
@@ -222,8 +221,10 @@
 	CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
 
 	i = --b->refcount;
-	if (i == 0)
+	if (i == 0) {
+		ASSERT_CLI();	/* XXX: ?? */
 		VTAILQ_REMOVE(&backendlist, b, list);
+	}
 	UNLOCK(&b->mtx);
 	if (i)
 		return;

Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_cli.c	2008-02-05 10:50:33 UTC (rev 2430)
+++ trunk/varnish-cache/bin/varnishd/cache_cli.c	2008-02-05 11:19:22 UTC (rev 2431)
@@ -106,8 +106,10 @@
 		pfd[0].fd = heritage.fds[2];
 		pfd[0].events = POLLIN;
 		i = poll(pfd, 1, 5000);
-		if (i == 0)
+		if (i == 0) {
+			VCL_Idle();
 			continue;
+		}
 		if ((nbuf + 2) >= lbuf) {
 			lbuf += lbuf;
 			buf = realloc(buf, lbuf);

Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vcl.c	2008-02-05 10:50:33 UTC (rev 2430)
+++ trunk/varnish-cache/bin/varnishd/cache_vcl.c	2008-02-05 11:19:22 UTC (rev 2431)
@@ -47,10 +47,9 @@
 
 struct vcls {
 	VTAILQ_ENTRY(vcls)	list;
-	const char		*name;
+	char			*name;
 	void			*dlh;
 	struct VCL_conf		*conf;
-	int			discard;
 };
 
 /*
@@ -61,10 +60,9 @@
     VTAILQ_HEAD_INITIALIZER(vcl_head);
 
 
+static MTX			vcl_mtx;
 static struct vcls		*vcl_active; /* protected by vcl_mtx */
 
-static MTX			vcl_mtx;
-
 /*--------------------------------------------------------------------*/
 
 void
@@ -85,6 +83,7 @@
 	AN(vcl_active);
 	*vcc = vcl_active->conf;
 	AN(*vcc);
+	AZ((*vcc)->discard);
 	(*vcc)->busy++;
 	UNLOCK(&vcl_mtx);
 }
@@ -92,7 +91,6 @@
 void
 VCL_Rel(struct VCL_conf **vcc)
 {
-	struct vcls *vcl;
 	struct VCL_conf *vc;
 
 	vc = *vcc;
@@ -101,19 +99,11 @@
 	LOCK(&vcl_mtx);
 	assert(vc->busy > 0);
 	vc->busy--;
-	vcl = vc->priv;	/* XXX miniobj */
-	if (vc->busy == 0 && vcl_active != vcl) {
-		/* XXX: purge backends */
-	}
-	if (vc->busy == 0 && vcl->discard) {
-		VTAILQ_REMOVE(&vcl_head, vcl, list);
-	} else {
-		vcl = NULL;
-	}
+	/*
+	 * We do not garbage collect discarded VCL's here, that happens
+	 * in VCL_Idle() which is called from the CLI thread.
+	 */
 	UNLOCK(&vcl_mtx);
-	if (vcl != NULL) {
-		/* XXX: dispose of vcl */
-	}
 }
 
 /*--------------------------------------------------------------------*/
@@ -123,9 +113,13 @@
 {
 	struct vcls *vcl;
 
-	VTAILQ_FOREACH(vcl, &vcl_head, list)
+	ASSERT_CLI();
+	VTAILQ_FOREACH(vcl, &vcl_head, list) {
+		if (vcl->conf->discard)
+			continue;
 		if (!strcmp(vcl->name, name))
 			return (vcl);
+	}
 	return (NULL);
 }
 
@@ -134,6 +128,7 @@
 {
 	struct vcls *vcl;
 
+	ASSERT_CLI();
 	vcl = vcl_find(name);
 	if (vcl != NULL) {
 		cli_out(cli, "Config '%s' already loaded", name);
@@ -177,15 +172,48 @@
 	return (0);
 }
 
+/*--------------------------------------------------------------------
+ * This function is polled from the CLI thread to dispose of any non-busy
+ * VCLs * which have been discarded.
+ */
+
+static void
+VCL_Nuke(struct vcls *vcl)
+{
+
+	ASSERT_CLI();
+	assert(vcl != vcl_active);
+	assert(vcl->conf->discard);
+	assert(vcl->conf->busy == 0);
+	VTAILQ_REMOVE(&vcl_head, vcl, list);
+	vcl->conf->fini_func();
+	free(vcl->name);
+	free(vcl);
+}
+
 /*--------------------------------------------------------------------*/
 
 void
+VCL_Idle(void)
+{
+	struct vcls *vcl, *vcl2;
+
+	ASSERT_CLI();
+	VTAILQ_FOREACH_SAFE(vcl, &vcl_head, list, vcl2) 
+		if (vcl->conf->discard && vcl->conf->busy == 0) 
+			VCL_Nuke(vcl);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
 cli_func_config_list(struct cli *cli, const char * const *av, void *priv)
 {
 	struct vcls *vcl;
 
 	(void)av;
 	(void)priv;
+	ASSERT_CLI();
 	VTAILQ_FOREACH(vcl, &vcl_head, list) {
 		cli_out(cli, "%s %6u %s\n",
 		    vcl == vcl_active ? "* " : "  ",
@@ -200,6 +228,7 @@
 
 	(void)av;
 	(void)priv;
+	ASSERT_CLI();
 	if (VCL_Load(av[3], av[2], cli))
 		cli_result(cli, CLIS_PARAM);
 	return;
@@ -210,6 +239,7 @@
 {
 	struct vcls *vcl;
 
+	ASSERT_CLI();
 	(void)av;
 	(void)priv;
 	vcl = vcl_find(av[2]);
@@ -218,11 +248,6 @@
 		cli_out(cli, "VCL '%s' unknown", av[2]);
 		return;
 	}
-	if (vcl->discard) {
-		cli_result(cli, CLIS_PARAM);
-		cli_out(cli, "VCL %s already discarded", av[2]);
-		return;
-	}
 	LOCK(&vcl_mtx);
 	if (vcl == vcl_active) {
 		UNLOCK(&vcl_mtx);
@@ -230,15 +255,10 @@
 		cli_out(cli, "VCL %s is the active VCL", av[2]);
 		return;
 	}
-	vcl->discard = 1;
+	vcl->conf->discard = 1;
+	UNLOCK(&vcl_mtx);
 	if (vcl->conf->busy == 0)
-		VTAILQ_REMOVE(&vcl_head, vcl, list);
-	else
-		vcl = NULL;
-	UNLOCK(&vcl_mtx);
-	if (vcl != NULL) {
-		/* XXX dispose of vcl */
-	}
+		VCL_Nuke(vcl);
 }
 
 void
@@ -254,11 +274,6 @@
 		cli_result(cli, CLIS_PARAM);
 		return;
 	}
-	if (vcl->discard) {
-		cli_out(cli, "VCL '%s' has been discarded", av[2]);
-		cli_result(cli, CLIS_PARAM);
-		return;
-	}
 	LOCK(&vcl_mtx);
 	vcl_active = vcl;
 	UNLOCK(&vcl_mtx);

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-02-05 10:50:33 UTC (rev 2430)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2008-02-05 11:19:22 UTC (rev 2431)
@@ -630,5 +630,6 @@
 VRT_fini_backend(struct backend *b)
 {
 
+	ASSERT_CLI();
 	VBE_DropRef(b);	
 }




More information about the varnish-commit mailing list