[master] 54b7af9 Always close directors through the VDI api.

Poul-Henning Kamp phk at FreeBSD.org
Mon Oct 6 10:03:43 CEST 2014


commit 54b7af96905eb7cd902f00181156e03052901d6b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Oct 6 08:00:21 2014 +0000

    Always close directors through the VDI api.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index bfce9cc..4e4625c 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -341,8 +341,8 @@ VBE_DiscardHealth(const struct director *vdi)
 
 /* Close a connection ------------------------------------------------*/
 
-void
-VBE_CloseFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
+static void
+vbe_CloseFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
 {
 	struct backend *bp;
 	struct vbc *vc;
@@ -356,8 +356,6 @@ VBE_CloseFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
 
 	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);
@@ -382,8 +380,6 @@ vbe_RecycleFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
 
 	bp = vc->backend;
 
-	VSLb(vc->vsl, SLT_BackendReuse, "%d %s", vc->fd, bp->display_name);
-
 	vc->vsl = NULL;
 
 	Lck_Lock(&bp->mtx);
@@ -458,17 +454,20 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
 	if (i == 1) {
 		AZ(bo->vbc);
 		VSC_C_main->backend_retry++;
-		bo->vbc = VDI_GetFd(d, wrk, bo);
+		bo->doclose = SC_NULL;
+		bo->vbc = vbe_dir_getfd(d, bo);
 		if (bo->vbc == NULL) {
 			VSLb(bo->vsl, SLT_FetchError, "no backend connection");
 			return (-1);
 		}
 		i = V1F_fetch_hdr(wrk, bo);
 	}
-	if (i != 0)
+	if (i != 0) {
+		bo->doclose = SC_NULL;
 		AZ(bo->vbc);
-	else
+	} else {
 		AN(bo->vbc);
+	}
 	return (i);
 }
 
@@ -494,11 +493,20 @@ vbe_dir_finish(const struct director *d, struct worker *wrk,
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
 	if (bo->vbc != NULL) {
-		if (bo->doclose != SC_NULL)
-			VBE_CloseFd(&bo->vbc, &bo->acct);
-		else
+		if (bo->doclose != SC_NULL) {
+			VSLb(bo->vsl, SLT_BackendClose,
+			    "%d %s", bo->vbc->fd,
+			    bo->vbc->backend->display_name);
+			vbe_CloseFd(&bo->vbc, &bo->acct);
+		} else {
+			VSLb(bo->vsl, SLT_BackendReuse,
+			    "%d %s", bo->vbc->fd,
+			    bo->vbc->backend->display_name);
 			vbe_RecycleFd(&bo->vbc, &bo->acct);
+		}
+
 	}
+	AZ(bo->vbc);
 }
 
 static struct suckaddr * __match_proto__(vdi_suckaddr_f)
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index ec24380..72a4cdf 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -105,7 +105,6 @@ 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 *);
diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c
index 6793739..974c5b4 100644
--- a/bin/varnishd/http1/cache_http1_fetch.c
+++ b/bin/varnishd/http1/cache_http1_fetch.c
@@ -144,7 +144,8 @@ 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));
-		VBE_CloseFd(&bo->vbc, &bo->acct);
+		bo->doclose = SC_TX_ERROR;
+		VDI_Finish(bo->director_resp, bo->wrk, bo);
 		/* XXX: other cleanup ? */
 		return (retry);
 	}
@@ -171,7 +172,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
 			VSLb(bo->vsl, SLT_FetchError,
 			    "http %sread error: overflow",
 			    first ? "first " : "");
-			VBE_CloseFd(&bo->vbc, &bo->acct);
+			bo->doclose = SC_RX_OVERFLOW;
+			VDI_Finish(bo->director_resp, bo->wrk, bo);
 			/* XXX: other cleanup ? */
 			return (-1);
 		}
@@ -180,7 +182,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
 			    htc->rxbuf_e - htc->rxbuf_b;
 			VSLb(bo->vsl, SLT_FetchError, "http %sread error: EOF",
 			    first ? "first " : "");
-			VBE_CloseFd(&bo->vbc, &bo->acct);
+			bo->doclose = SC_RX_TIMEOUT;
+			VDI_Finish(bo->director_resp, bo->wrk, bo);
 			/* XXX: other cleanup ? */
 			return (retry);
 		}
@@ -197,7 +200,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
 
 	if (HTTP1_DissectResponse(hp, htc)) {
 		VSLb(bo->vsl, SLT_FetchError, "http format error");
-		VBE_CloseFd(&bo->vbc, &bo->acct);
+		bo->doclose = SC_RX_JUNK;
+		VDI_Finish(bo->director_resp, bo->wrk, bo);
 		/* XXX: other cleanup ? */
 		return (-1);
 	}



More information about the varnish-commit mailing list