r5090 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Wed Aug 11 14:27:45 CEST 2010


Author: phk
Date: 2010-08-11 14:27:45 +0200 (Wed, 11 Aug 2010)
New Revision: 5090

Added:
   trunk/varnish-cache/bin/varnishd/cache_dir.c
Modified:
   trunk/varnish-cache/bin/varnishd/Makefile.am
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/cache_dir_dns.c
   trunk/varnish-cache/bin/varnishd/cache_dir_random.c
   trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_pipe.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
Log:
Move the top-of-director APIs from cache_backend.c to cache_dir.c and
give them the VTLA "VDI"



Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am	2010-08-11 12:27:45 UTC (rev 5090)
@@ -20,6 +20,7 @@
 	cache_ban.c \
 	cache_center.c \
 	cache_cli.c \
+	cache_dir.c \
 	cache_dir_random.c \
 	cache_dir_dns.c \
 	cache_dir_round_robin.c \

Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2010-08-11 12:27:45 UTC (rev 5090)
@@ -473,12 +473,12 @@
 
 /* cache_backend.c */
 
-struct vbc *VBE_GetFd(const struct director *, struct sess *sp);
-int VBE_Healthy(double now, const struct director *, uintptr_t target);
-int VBE_Healthy_sp(const struct sess *sp, const struct director *);
-void VBE_CloseFd(struct sess *sp);
-void VBE_RecycleFd(struct sess *sp);
-void VBE_AddHostHeader(const struct sess *sp);
+struct vbc *VDI_GetFd(const struct director *, struct sess *sp);
+int VDI_Healthy(double now, const struct director *, uintptr_t target);
+int VDI_Healthy_sp(const struct sess *sp, const struct director *);
+void VDI_CloseFd(struct sess *sp);
+void VDI_RecycleFd(struct sess *sp);
+void VDI_AddHostHeader(const struct sess *sp);
 void VBE_Poll(void);
 
 /* cache_backend_cfg.c */

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -53,21 +53,7 @@
  */
 static VTAILQ_HEAD(,vbc) vbcs = VTAILQ_HEAD_INITIALIZER(vbcs);
 
-/*--------------------------------------------------------------------
- * Create default Host: header for backend request
- */
-void
-VBE_AddHostHeader(const struct sess *sp)
-{
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->wrk->bereq, HTTP_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->vbc, VBC_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->vbc->backend, BACKEND_MAGIC);
-	http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->bereq,
-	    "Host: %s", sp->vbc->backend->hosthdr);
-}
-
 /* Private interface from backend_cfg.c */
 void
 VBE_ReleaseConn(struct vbc *vc)
@@ -342,7 +328,7 @@
 		}
 		VSC_main->backend_toolate++;
 		sp->vbc = vc;
-		VBE_CloseFd(sp);
+		VDI_CloseFd(sp);
 	}
 
 	if (!vbe_Healthy(sp->t_req, (uintptr_t)sp->objhead, bp)) {
@@ -371,90 +357,6 @@
 	return (vc);
 }
 
-/* Close a connection ------------------------------------------------*/
-
-void
-VBE_CloseFd(struct sess *sp)
-{
-	struct backend *bp;
-
-	CHECK_OBJ_NOTNULL(sp->vbc, VBC_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->vbc->backend, BACKEND_MAGIC);
-	assert(sp->vbc->fd >= 0);
-
-	bp = sp->vbc->backend;
-
-	WSL(sp->wrk, SLT_BackendClose, sp->vbc->fd, "%s", bp->vcl_name);
-	TCP_close(&sp->vbc->fd);
-	VBE_DropRefConn(bp);
-	sp->vbc->backend = NULL;
-	VBE_ReleaseConn(sp->vbc);
-	sp->vbc = NULL;
-}
-
-/* Recycle a connection ----------------------------------------------*/
-
-void
-VBE_RecycleFd(struct sess *sp)
-{
-	struct backend *bp;
-
-	CHECK_OBJ_NOTNULL(sp->vbc, VBC_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->vbc->backend, BACKEND_MAGIC);
-	assert(sp->vbc->fd >= 0);
-
-	bp = sp->vbc->backend;
-
-	WSL(sp->wrk, SLT_BackendReuse, sp->vbc->fd, "%s", bp->vcl_name);
-	/*
-	 * Flush the shmlog, so that another session reusing this backend
-	 * will log chronologically later than our use of it.
-	 */
-	WSL_Flush(sp->wrk, 0);
-	Lck_Lock(&bp->mtx);
-	VSC_main->backend_recycle++;
-	VTAILQ_INSERT_HEAD(&bp->connlist, sp->vbc, list);
-	sp->vbc = NULL;
-	VBE_DropRefLocked(bp);
-}
-
-/* Get a connection --------------------------------------------------*/
-
-struct vbc *
-VBE_GetFd(const struct director *d, struct sess *sp)
-{
-
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	if (d == NULL)
-		d = sp->director;
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	return (d->getfd(d, sp));
-}
-
-/* Check health ------------------------------------------------------
- *
- * The target is really an objhead pointer, but since it can not be
- * dereferenced during health-checks, we pass it as uintptr_t, which
- * hopefully will make people investigate, before mucking about with it.
- */
-
-int
-VBE_Healthy_sp(const struct sess *sp, const struct director *d)
-{
-
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	return (d->healthy(sp->t_req, d, (uintptr_t)sp->objhead));
-}
-
-int
-VBE_Healthy(double now, const struct director *d, uintptr_t target)
-{
-
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	return (d->healthy(now, d, target));
-}
-
 /*--------------------------------------------------------------------
  * The "simple" director really isn't, since thats where all the actual
  * connections happen.  Nontheless, pretend it is simple by sequestering

Added: trunk/varnish-cache/bin/varnishd/cache_dir.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir.c	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/cache_dir.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -0,0 +1,138 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2010 Redpill Linpro 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.
+ *
+ * Handle backend connections and backend request structures.
+ *
+ */
+
+#include "config.h"
+
+#include "svnid.h"
+SVNID("$Id: cache_backend.c 5089 2010-08-11 12:12:47Z phk $")
+
+#include "cache.h"
+#include "cache_backend.h"
+
+/*--------------------------------------------------------------------
+ * Create default Host: header for backend request
+ */
+void
+VDI_AddHostHeader(const struct sess *sp)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->wrk->bereq, HTTP_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->vbc, VBC_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->vbc->backend, BACKEND_MAGIC);
+	http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->bereq,
+	    "Host: %s", sp->vbc->backend->hosthdr);
+}
+
+/* Close a connection ------------------------------------------------*/
+
+void
+VDI_CloseFd(struct sess *sp)
+{
+	struct backend *bp;
+
+	CHECK_OBJ_NOTNULL(sp->vbc, VBC_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->vbc->backend, BACKEND_MAGIC);
+	assert(sp->vbc->fd >= 0);
+
+	bp = sp->vbc->backend;
+
+	WSL(sp->wrk, SLT_BackendClose, sp->vbc->fd, "%s", bp->vcl_name);
+	TCP_close(&sp->vbc->fd);
+	VBE_DropRefConn(bp);
+	sp->vbc->backend = NULL;
+	VBE_ReleaseConn(sp->vbc);
+	sp->vbc = NULL;
+}
+
+/* Recycle a connection ----------------------------------------------*/
+
+void
+VDI_RecycleFd(struct sess *sp)
+{
+	struct backend *bp;
+
+	CHECK_OBJ_NOTNULL(sp->vbc, VBC_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->vbc->backend, BACKEND_MAGIC);
+	assert(sp->vbc->fd >= 0);
+
+	bp = sp->vbc->backend;
+
+	WSL(sp->wrk, SLT_BackendReuse, sp->vbc->fd, "%s", bp->vcl_name);
+	/*
+	 * Flush the shmlog, so that another session reusing this backend
+	 * will log chronologically later than our use of it.
+	 */
+	WSL_Flush(sp->wrk, 0);
+	Lck_Lock(&bp->mtx);
+	VSC_main->backend_recycle++;
+	VTAILQ_INSERT_HEAD(&bp->connlist, sp->vbc, list);
+	sp->vbc = NULL;
+	VBE_DropRefLocked(bp);
+}
+
+/* Get a connection --------------------------------------------------*/
+
+struct vbc *
+VDI_GetFd(const struct director *d, struct sess *sp)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	if (d == NULL)
+		d = sp->director;
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+	return (d->getfd(d, sp));
+}
+
+/* Check health ------------------------------------------------------
+ *
+ * The target is really an objhead pointer, but since it can not be
+ * dereferenced during health-checks, we pass it as uintptr_t, which
+ * hopefully will make people investigate, before mucking about with it.
+ */
+
+int
+VDI_Healthy_sp(const struct sess *sp, const struct director *d)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+	return (d->healthy(sp->t_req, d, (uintptr_t)sp->objhead));
+}
+
+int
+VDI_Healthy(double now, const struct director *d, uintptr_t target)
+{
+
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+	return (d->healthy(now, d, target));
+}

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_dns.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_dns.c	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_dns.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -164,7 +164,7 @@
 			current = i + initial - nhosts;
 		else
 			current = i + initial;
-		if (VBE_Healthy_sp(sp, group->hosts[current])) {
+		if (VDI_Healthy_sp(sp, group->hosts[current])) {
 			group->next_host = current+1;
 			return group->hosts[current];
 		}
@@ -395,10 +395,10 @@
 	CAST_OBJ_NOTNULL(vs, director->priv, VDI_DNS_MAGIC);
 
 	dir = vdi_dns_find_backend(sp, vs);
-	if (!dir || !VBE_Healthy_sp(sp, dir))
+	if (!dir || !VDI_Healthy_sp(sp, dir))
 		return (NULL);
 	
-	vbe = VBE_GetFd(dir, sp);
+	vbe = VDI_GetFd(dir, sp);
 	return (vbe);
 }
 

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -138,9 +138,9 @@
 			if (r >= s1)
 				continue;
 			d2 = vs->hosts[i].backend;
-			if (!VBE_Healthy_sp(sp, d2))
+			if (!VDI_Healthy_sp(sp, d2))
 				break;
-			vbe = VBE_GetFd(d2, sp);
+			vbe = VDI_GetFd(d2, sp);
 			if (vbe != NULL)
 				return (vbe);
 			break;
@@ -153,7 +153,7 @@
 		for (i = 0; i < vs->nhosts; i++) {
 			d2 = vs->hosts[i].backend;
 			/* XXX: cache result of healty to avoid double work */
-			if (VBE_Healthy_sp(sp, d2))
+			if (VDI_Healthy_sp(sp, d2))
 				s1 += vs->hosts[i].weight;
 		}
 
@@ -172,12 +172,12 @@
 		s1 = 0.0;
 		for (i = 0; i < vs->nhosts; i++)  {
 			d2 = vs->hosts[i].backend;
-			if (!VBE_Healthy_sp(sp, d2))
+			if (!VDI_Healthy_sp(sp, d2))
 				continue;
 			s1 += vs->hosts[i].weight;
 			if (r >= s1)
 				continue;
-			vbe = VBE_GetFd(d2, sp);
+			vbe = VDI_GetFd(d2, sp);
 			if (vbe != NULL)
 				return (vbe);
 			break;
@@ -197,7 +197,7 @@
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_RANDOM_MAGIC);
 
 	for (i = 0; i < vs->nhosts; i++) {
-		if (VBE_Healthy(now, vs->hosts[i].backend, target))
+		if (VDI_Healthy(now, vs->hosts[i].backend, target))
 			return 1;
 	}
 	return 0;

Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -74,9 +74,9 @@
 	for (i = 0; i < vs->nhosts; i++) {
 		backend = vs->hosts[vs->next_host].backend;
 		vs->next_host = (vs->next_host + 1) % vs->nhosts;
-		if (!VBE_Healthy_sp(sp, backend))
+		if (!VDI_Healthy_sp(sp, backend))
 			continue;
-		vbe = VBE_GetFd(backend, sp);
+		vbe = VDI_GetFd(backend, sp);
 		if (vbe != NULL)
 			return (vbe);
 	}
@@ -96,7 +96,7 @@
 
 	for (i = 0; i < vs->nhosts; i++) {
 		backend = vs->hosts[i].backend;
-		if (VBE_Healthy(now, backend, target))
+		if (VDI_Healthy(now, backend, target))
 			return 1;
 	}
 	return 0;

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -351,7 +351,7 @@
 	w = sp->wrk;
 	hp = sp->wrk->bereq;
 
-	sp->vbc = VBE_GetFd(NULL, sp);
+	sp->vbc = VDI_GetFd(NULL, sp);
 	if (sp->vbc == NULL) {
 		WSP(sp, SLT_FetchError, "no backend connection");
 		return (__LINE__);
@@ -364,7 +364,7 @@
 	 * XXX: This possibly ought to go into the default VCL
 	 */
 	if (!http_GetHdr(hp, H_Host, &b))
-		VBE_AddHostHeader(sp);
+		VDI_AddHostHeader(sp);
 
 	(void)TCP_blocking(vc->fd);	/* XXX: we should timeout instead */
 	WRW_Reserve(w, &vc->fd);
@@ -374,7 +374,7 @@
 	i = FetchReqBody(sp);
 	if (WRW_FlushRelease(w) || i > 0) {
 		WSP(sp, SLT_FetchError, "backend write error: %d", errno);
-		VBE_CloseFd(sp);
+		VDI_CloseFd(sp);
 		/* XXX: other cleanup ? */
 		return (__LINE__);
 	}
@@ -397,7 +397,7 @@
 		if (i < 0) {
 			WSP(sp, SLT_FetchError,
 			    "http read error: %d", errno);
-			VBE_CloseFd(sp);
+			VDI_CloseFd(sp);
 			/* XXX: other cleanup ? */
 			return (__LINE__);
 		}
@@ -412,7 +412,7 @@
 
 	if (http_DissectResponse(sp->wrk, sp->wrk->htc, hp)) {
 		WSP(sp, SLT_FetchError, "http format error");
-		VBE_CloseFd(sp);
+		VDI_CloseFd(sp);
 		/* XXX: other cleanup ? */
 		return (__LINE__);
 	}
@@ -466,7 +466,7 @@
 		sp->wrk->stats.fetch_bad++;
 		/* XXX: AUGH! */
 		WSL(sp->wrk, SLT_Debug, vc->fd, "Invalid Transfer-Encoding");
-		VBE_CloseFd(sp);
+		VDI_CloseFd(sp);
 		return (__LINE__);
 	} else if (http_HdrIs(hp, H_Connection, "keep-alive")) {
 		/*
@@ -515,7 +515,7 @@
 			VTAILQ_REMOVE(&sp->obj->store, st, list);
 			STV_free(st);
 		}
-		VBE_CloseFd(sp);
+		VDI_CloseFd(sp);
 		sp->obj->len = 0;
 		return (__LINE__);
 	}
@@ -540,9 +540,9 @@
 		cls = 1;
 
 	if (cls)
-		VBE_CloseFd(sp);
+		VDI_CloseFd(sp);
 	else
-		VBE_RecycleFd(sp);
+		VDI_RecycleFd(sp);
 
 	return (0);
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -402,7 +402,7 @@
 	if (oc == NULL			/* We found no live object */
 	    && grace_oc != NULL		/* There is a grace candidate */
 	    && (busy_oc != NULL		/* Somebody else is already busy */
-	    || !VBE_Healthy(sp->t_req, sp->director, (uintptr_t)oh))) {
+	    || !VDI_Healthy(sp->t_req, sp->director, (uintptr_t)oh))) {
 					 /* Or it is impossible to fetch: */
 		o = grace_oc->obj;
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);

Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -74,7 +74,7 @@
 	CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
 	w = sp->wrk;
 
-	sp->vbc = VBE_GetFd(NULL, sp);
+	sp->vbc = VDI_GetFd(NULL, sp);
 	if (sp->vbc == NULL)
 		return;
 	vc = sp->vbc;
@@ -91,7 +91,7 @@
 
 	if (i) {
 		vca_close_session(sp, "pipe");
-		VBE_CloseFd(sp);
+		VDI_CloseFd(sp);
 		return;
 	}
 
@@ -131,5 +131,5 @@
 		}
 	}
 	vca_close_session(sp, "pipe");
-	VBE_CloseFd(sp);
+	VDI_CloseFd(sp);
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2010-08-11 12:12:47 UTC (rev 5089)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2010-08-11 12:27:45 UTC (rev 5090)
@@ -819,7 +819,7 @@
 {
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
-	return (VBE_Healthy_sp(sp, sp->director));
+	return (VDI_Healthy_sp(sp, sp->director));
 }
 
 /*--------------------------------------------------------------------*/




More information about the varnish-commit mailing list