[master] c7611af Move the last bits of file descriptor awareness out of the "abstract" director layer.

Poul-Henning Kamp phk at FreeBSD.org
Thu Sep 25 08:42:34 CEST 2014


commit c7611af55556de29f6bff5beda78b83473d9f264
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Sep 25 06:41:57 2014 +0000

    Move the last bits of file descriptor awareness out of the "abstract"
    director layer.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index b8a2a79..f40c5d1 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -355,6 +355,60 @@ VBE_DiscardHealth(const struct director *vdi)
 	VBP_Remove(vs->backend, vs->vrt->probe);
 }
 
+/* Close a connection ------------------------------------------------*/
+
+void
+VBE_CloseFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
+{
+	struct backend *bp;
+	struct vbc *vc;
+
+	AN(vbp);
+	vc = *vbp;
+	*vbp = NULL;
+	CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
+	CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
+	assert(vc->fd >= 0);
+
+	bp = vc->backend;
+
+	VSLb(vc->vsl, SLT_BackendClose, "%d %s", vc->fd, bp->display_name);
+
+	vc->vsl = NULL;
+	VTCP_close(&vc->fd);
+	VBE_DropRefConn(bp, acct_bereq);
+	vc->backend = NULL;
+	VBE_ReleaseConn(vc);
+}
+
+/* Recycle a connection ----------------------------------------------*/
+
+static void
+vbe_RecycleFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
+{
+	struct backend *bp;
+	struct vbc *vc;
+
+	AN(vbp);
+	vc = *vbp;
+	*vbp = NULL;
+	CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
+	CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
+	assert(vc->fd >= 0);
+
+	bp = vc->backend;
+
+	VSLb(vc->vsl, SLT_BackendReuse, "%d %s", vc->fd, bp->display_name);
+
+	vc->vsl = NULL;
+
+	Lck_Lock(&bp->mtx);
+	VSC_C_main->backend_recycle++;
+	VTAILQ_INSERT_HEAD(&bp->connlist, vc, list);
+	VBE_DropRefLocked(bp, acct_bereq);
+}
+
+
 /*--------------------------------------------------------------------
  *
  */
@@ -453,9 +507,9 @@ vdi_simple_finish(const struct director *d, struct worker *wrk,
 
 	if (bo->vbc != NULL) {
 		if (bo->doclose != SC_NULL)
-			VDI_CloseFd(&bo->vbc, &bo->acct);
+			VBE_CloseFd(&bo->vbc, &bo->acct);
 		else
-			VDI_RecycleFd(&bo->vbc, &bo->acct);
+			vbe_RecycleFd(&bo->vbc, &bo->acct);
 	}
 }
 
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index c51d62f..5c18107 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -142,6 +142,7 @@ struct vbc {
 void VBE_ReleaseConn(struct vbc *vc);
 void VBE_UseHealth(const struct director *vdi);
 void VBE_DiscardHealth(const struct director *vdi);
+void VBE_CloseFd(struct vbc **vbp, const struct acct_bereq *);
 
 /* cache_backend_cfg.c */
 void VBE_DropRefConn(struct backend *, const struct acct_bereq *);
@@ -167,8 +168,6 @@ void VDI_Finish(const struct director *d, struct worker *wrk,
 struct vbc *VDI_GetFd(const struct director *d, struct worker *wrk,
     struct busyobj *);
 int VDI_Healthy(const struct director *);
-void VDI_CloseFd(struct vbc **vbp, const struct acct_bereq *);
-void VDI_RecycleFd(struct vbc **vbp, const struct acct_bereq *);
 void VDI_AddHostHeader(struct http *to, const struct vbc *vbc);
 void VBE_Poll(void);
 void VDI_Init(void);
diff --git a/bin/varnishd/cache/cache_dir.c b/bin/varnishd/cache/cache_dir.c
index 0dd65b5..9f7ae43 100644
--- a/bin/varnishd/cache/cache_dir.c
+++ b/bin/varnishd/cache/cache_dir.c
@@ -26,7 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * Abstract backend API
+ * Abstract director API
+ *
+ * The abstract director API does not know how we talk to the backend or
+ * if there even is one in the usual meaning of the word.
  *
  */
 
@@ -35,60 +38,6 @@
 #include "cache.h"
 
 #include "cache_backend.h"
-#include "vtcp.h"
-
-/* Close a connection ------------------------------------------------*/
-
-void
-VDI_CloseFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
-{
-	struct backend *bp;
-	struct vbc *vc;
-
-	AN(vbp);
-	vc = *vbp;
-	*vbp = NULL;
-	CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
-	CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
-	assert(vc->fd >= 0);
-
-	bp = vc->backend;
-
-	VSLb(vc->vsl, SLT_BackendClose, "%d %s", vc->fd, bp->display_name);
-
-	vc->vsl = NULL;
-	VTCP_close(&vc->fd);
-	VBE_DropRefConn(bp, acct_bereq);
-	vc->backend = NULL;
-	VBE_ReleaseConn(vc);
-}
-
-/* Recycle a connection ----------------------------------------------*/
-
-void
-VDI_RecycleFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
-{
-	struct backend *bp;
-	struct vbc *vc;
-
-	AN(vbp);
-	vc = *vbp;
-	*vbp = NULL;
-	CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
-	CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
-	assert(vc->fd >= 0);
-
-	bp = vc->backend;
-
-	VSLb(vc->vsl, SLT_BackendReuse, "%d %s", vc->fd, bp->display_name);
-
-	vc->vsl = NULL;
-
-	Lck_Lock(&bp->mtx);
-	VSC_C_main->backend_recycle++;
-	VTAILQ_INSERT_HEAD(&bp->connlist, vc, list);
-	VBE_DropRefLocked(bp, acct_bereq);
-}
 
 /* Resolve director --------------------------------------------------*/
 
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index 7884d5e..de12e88 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -143,7 +143,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
 		VSLb(bo->vsl, SLT_FetchError, "backend write error: %d (%s)",
 		    errno, strerror(errno));
 		VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk));
-		VDI_CloseFd(&bo->vbc, &bo->acct);
+		VBE_CloseFd(&bo->vbc, &bo->acct);
 		/* XXX: other cleanup ? */
 		return (retry);
 	}
@@ -169,7 +169,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
 			VSLb(bo->vsl, SLT_FetchError,
 			    "http %sread error: overflow",
 			    first ? "first " : "");
-			VDI_CloseFd(&bo->vbc, &bo->acct);
+			VBE_CloseFd(&bo->vbc, &bo->acct);
 			/* XXX: other cleanup ? */
 			return (-1);
 		}
@@ -177,7 +177,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
 			bo->acct.beresp_hdrbytes += Tlen(htc->rxbuf);
 			VSLb(bo->vsl, SLT_FetchError, "http %sread error: EOF",
 			    first ? "first " : "");
-			VDI_CloseFd(&bo->vbc, &bo->acct);
+			VBE_CloseFd(&bo->vbc, &bo->acct);
 			/* XXX: other cleanup ? */
 			return (retry);
 		}
@@ -194,7 +194,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
 
 	if (HTTP1_DissectResponse(hp, htc)) {
 		VSLb(bo->vsl, SLT_FetchError, "http format error");
-		VDI_CloseFd(&bo->vbc, &bo->acct);
+		VBE_CloseFd(&bo->vbc, &bo->acct);
 		/* XXX: other cleanup ? */
 		return (-1);
 	}
diff --git a/bin/varnishd/cache/cache_pipe.c b/bin/varnishd/cache/cache_pipe.c
index 71cf3e6..9d43be0 100644
--- a/bin/varnishd/cache/cache_pipe.c
+++ b/bin/varnishd/cache/cache_pipe.c
@@ -141,7 +141,7 @@ PipeRequest(struct req *req, struct busyobj *bo)
 	if (i) {
 		pipecharge(req, &acct_pipe, vc->backend->vsc);
 		SES_Close(req->sp, SC_TX_PIPE);
-		VDI_CloseFd(&vc, NULL);
+		VBE_CloseFd(&vc, NULL);
 		return;
 	}
 
@@ -183,7 +183,7 @@ PipeRequest(struct req *req, struct busyobj *bo)
 	VSLb_ts_req(req, "PipeSess", W_TIM_real(wrk));
 	pipecharge(req, &acct_pipe, vc->backend->vsc);
 	SES_Close(req->sp, SC_TX_PIPE);
-	VDI_CloseFd(&vc, NULL);
+	VBE_CloseFd(&vc, NULL);
 	bo->vbc = NULL;
 }
 



More information about the varnish-commit mailing list