[master] adca4ad Rename dir->getfd() to dir->gethttp1fd() and don't assume that the director has it.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jan 7 11:52:38 CET 2015


commit adca4ad282c71c9bd7c4ca7dfe3594f79065fce9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jan 7 10:51:22 2015 +0000

    Rename dir->getfd() to dir->gethttp1fd() and don't assume that
    the director has it.
    
    Make VDI_GetBody() and VDI_Finish() operate on the implied bo->director_resp.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 226f420..64139fb 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -516,7 +516,7 @@ VRT_init_vbe(VRT_CTX, struct director **bp, int idx,
 	vs->dir.priv = vs;
 	vs->dir.name = "simple";
 	REPLACE(vs->dir.vcl_name, t->vcl_name);
-	vs->dir.getfd = vbe_dir_getfd;
+	vs->dir.gethttp1fd = vbe_dir_getfd;
 	vs->dir.healthy = vbe_dir_healthy;
 	vs->dir.gethdrs = vbe_dir_gethdrs;
 	vs->dir.getbody = vbe_dir_getbody;
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 13a25c9..199fe3f 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -43,24 +43,24 @@
 /* Resolve director --------------------------------------------------*/
 
 static const struct director *
-vdi_resolve(struct worker *wrk, struct busyobj *bo, const struct director *d)
+vdi_resolve(struct worker *wrk, struct busyobj *bo)
 {
+	const struct director *d;
+	const struct director *d2;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
-	if (d == NULL) {
-		VSLb(bo->vsl, SLT_FetchError, "No backend");
-		return (NULL);
-	}
-
-	while (d != NULL && d->resolve != NULL) {
+	for (d = bo->director_req; d != NULL && d->resolve != NULL; d = d2) {
 		CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-		d = d->resolve(d, wrk, bo);
+		d2 = d->resolve(d, wrk, bo);
+		if (d2 == NULL)
+			VSLb(bo->vsl, SLT_FetchError,
+			    "Director %s returned no backend", d->vcl_name);
 	}
 	CHECK_OBJ_ORNULL(d, DIRECTOR_MAGIC);
 	if (d == NULL)
-		VSLb(bo->vsl, SLT_FetchError, "Backend selection failed");
+		VSLb(bo->vsl, SLT_FetchError, "No backend");
 	bo->director_resp = d;
 	return (d);
 }
@@ -76,7 +76,7 @@ VDI_GetHdr(struct worker *wrk, struct busyobj *bo)
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
-	d = vdi_resolve(wrk, bo, bo->director_req);
+	d = vdi_resolve(wrk, bo);
 	if (d != NULL) {
 		AN(d->gethdrs);
 		bo->director_state = DIR_S_HDRS;
@@ -90,13 +90,15 @@ VDI_GetHdr(struct worker *wrk, struct busyobj *bo)
 /* Setup body fetch --------------------------------------------------*/
 
 int
-VDI_GetBody(const struct director *d, struct worker *wrk, struct busyobj *bo)
+VDI_GetBody(struct worker *wrk, struct busyobj *bo)
 {
+	const struct director *d;
 
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
+	d = bo->director_resp;
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	AZ(d->resolve);
 	AN(d->getbody);
 
@@ -108,13 +110,16 @@ VDI_GetBody(const struct director *d, struct worker *wrk, struct busyobj *bo)
 /* Finish fetch ------------------------------------------------------*/
 
 void
-VDI_Finish(const struct director *d, struct worker *wrk, struct busyobj *bo)
+VDI_Finish(struct worker *wrk, struct busyobj *bo)
 {
+	const struct director *d;
 
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
+	d = bo->director_resp;
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+
 	AZ(d->resolve);
 	AN(d->finish);
 
@@ -126,22 +131,22 @@ VDI_Finish(const struct director *d, struct worker *wrk, struct busyobj *bo)
 /* Get a connection --------------------------------------------------*/
 
 int
-VDI_GetFd(const struct director *d, struct worker *wrk, struct busyobj *bo)
+VDI_GetHttp1Fd(struct worker *wrk, struct busyobj *bo)
 {
+	const struct director *d;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
-	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 
-	d = vdi_resolve(wrk, bo, d);
-	if (d == NULL)
+	d = vdi_resolve(wrk, bo);
+	if (d == NULL || d->gethttp1fd == NULL)
 		return (-1);
-
-	AN(d->getfd);
-	return (d->getfd(d, bo));
+	return (d->gethttp1fd(d, bo));
 }
 
-/* Check health ------------------------------------------------------
+/* Check health --------------------------------------------------------
+ *
+ * If director has no healthy method, we just assume it is healthy.
  */
 
 int
@@ -149,6 +154,7 @@ VDI_Healthy(const struct director *d, const struct busyobj *bo)
 {
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	AN(d->healthy);
+	if (d->healthy == NULL)
+		return (1);
 	return (d->healthy(d, bo, NULL));
 }
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index 7941213..3980356 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -42,7 +42,7 @@
  * backends to use.
  */
 
-typedef int vdi_getfd_f(const struct director *, struct busyobj *);
+typedef int vdi_gethttp1fd_f(const struct director *, struct busyobj *);
 typedef unsigned vdi_healthy_f(const struct director *, const struct busyobj *,
     double *changed);
 typedef const struct director *vdi_resolve_f(const struct director *,
@@ -59,7 +59,7 @@ struct director {
 #define DIRECTOR_MAGIC		0x3336351d
 	const char		*name;
 	char			*vcl_name;
-	vdi_getfd_f		*getfd;
+	vdi_gethttp1fd_f	*gethttp1fd;
 	vdi_healthy_f		*healthy;
 	vdi_resolve_f		*resolve;
 	vdi_gethdrs_f		*gethdrs;
@@ -70,11 +70,9 @@ struct director {
 
 /* cache_director.c */
 int VDI_GetHdr(struct worker *wrk, struct busyobj *bo);
-int VDI_GetBody(const struct director *d, struct worker *wrk,
-    struct busyobj *bo);
-void VDI_Finish(const struct director *d, struct worker *wrk,
-    struct busyobj *bo);
-int VDI_GetFd(const struct director *d, struct worker *wrk, struct busyobj *);
+int VDI_GetBody(struct worker *wrk, struct busyobj *bo);
+void VDI_Finish(struct worker *wrk, struct busyobj *bo);
+int VDI_GetHttp1Fd(struct worker *wrk, struct busyobj *);
 int VDI_Healthy(const struct director *, const struct busyobj *);
 void VDI_AddHostHeader(struct http *to, const struct vbc *vbc);
 void VBE_Init(void);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index d53ce82..e0c6941 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -374,7 +374,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 
 	if (bo->htc->body_status == BS_ERROR) {
 		bo->doclose = SC_RX_BODY;
-		VDI_Finish(bo->director_resp, bo->wrk, bo);
+		VDI_Finish(bo->wrk, bo);
 		VSLb(bo->vsl, SLT_Error, "Body cannot be fetched");
 		assert(bo->director_state == DIR_S_NULL);
 		return (F_STP_ERROR);
@@ -419,14 +419,14 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 
 	if (wrk->handling == VCL_RET_ABANDON) {
 		bo->doclose = SC_RESP_CLOSE;
-		VDI_Finish(bo->director_resp, bo->wrk, bo);
+		VDI_Finish(bo->wrk, bo);
 		return (F_STP_FAIL);
 	}
 
 	if (wrk->handling == VCL_RET_RETRY) {
 		bo->doclose = SC_RESP_CLOSE;
 		if (bo->director_state != DIR_S_NULL)
-			VDI_Finish(bo->director_resp, bo->wrk, bo);
+			VDI_Finish(bo->wrk, bo);
 
 		if (bo->retries++ < cache_param->max_retries)
 			return (F_STP_RETRY);
@@ -596,14 +596,14 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	if (VFP_Open(bo->vfc)) {
 		(void)VFP_Error(bo->vfc, "Fetch pipeline failed to open");
 		bo->doclose = SC_RX_BODY;
-		VDI_Finish(bo->director_resp, bo->wrk, bo);
+		VDI_Finish(bo->wrk, bo);
 		return (F_STP_ERROR);
 	}
 
 	if (vbf_beresp2obj(bo)) {
 		(void)VFP_Error(bo->vfc, "Could not get storage");
 		bo->doclose = SC_RX_BODY;
-		VDI_Finish(bo->director_resp, bo->wrk, bo);
+		VDI_Finish(bo->wrk, bo);
 		return (F_STP_ERROR);
 	}
 
@@ -625,7 +625,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 		ObjSetFlag(bo->wrk, bo->fetch_objcore, OF_IMSCAND, 1);
 
 	if (bo->htc->body_status != BS_NONE)
-		AZ(VDI_GetBody(bo->director_resp, bo->wrk, bo));
+		AZ(VDI_GetBody(bo->wrk, bo));
 
 	assert(bo->refcount >= 1);
 
@@ -649,12 +649,12 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 		assert(bo->state < BOS_STREAM);
 		ObjFreeObj(bo->wrk, bo->fetch_objcore);
 		// XXX: doclose = ?
-		VDI_Finish(bo->director_resp, bo->wrk, bo);
+		VDI_Finish(bo->wrk, bo);
 		return (F_STP_ERROR);
 	}
 
 	if (bo->vfc->failed) {
-		VDI_Finish(bo->director_resp, bo->wrk, bo);
+		VDI_Finish(bo->wrk, bo);
 		return (F_STP_FAIL);
 	}
 
@@ -667,7 +667,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 
 	/* Recycle the backend connection before setting BOS_FINISHED to
 	   give predictable backend reuse behavior for varnishtest */
-	VDI_Finish(bo->director_resp, bo->wrk, bo);
+	VDI_Finish(bo->wrk, bo);
 
 	VBO_setstate(bo, BOS_FINISHED);
 	VSLb_ts_busyobj(bo, "BerespBody", W_TIM_real(wrk));
@@ -729,7 +729,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	if (bo->ims_oc->flags & OC_F_FAILED)
 		(void)VFP_Error(bo->vfc, "Template object failed");
 	if (bo->vfc->failed) {
-		VDI_Finish(bo->director_resp, bo->wrk, bo);
+		VDI_Finish(bo->wrk, bo);
 		return (F_STP_FAIL);
 	}
 
@@ -741,7 +741,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 
 	/* Recycle the backend connection before setting BOS_FINISHED to
 	   give predictable backend reuse behavior for varnishtest */
-	VDI_Finish(bo->director_resp, bo->wrk, bo);
+	VDI_Finish(bo->wrk, bo);
 
 	VBO_setstate(bo, BOS_FINISHED);
 	VSLb_ts_busyobj(bo, "BerespBody", W_TIM_real(wrk));
@@ -796,7 +796,7 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 
 		bo->doclose = SC_RESP_CLOSE;
 		if (bo->director_state != DIR_S_NULL)
-			VDI_Finish(bo->director_resp, bo->wrk, bo);
+			VDI_Finish(bo->wrk, bo);
 
 		if (bo->retries++ < cache_param->max_retries)
 			return (F_STP_RETRY);
diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c
index 84b45a0..a988139 100644
--- a/bin/varnishd/http1/cache_http1_pipe.c
+++ b/bin/varnishd/http1/cache_http1_pipe.c
@@ -112,7 +112,7 @@ V1P_Process(struct req *req, struct busyobj *bo)
 	acct_pipe.req = req->acct.req_hdrbytes;
 	req->acct.req_hdrbytes = 0;
 
-	fd = VDI_GetFd(bo->director_req, wrk, bo);
+	fd = VDI_GetHttp1Fd(wrk, bo);
 	if (fd < 0) {
 		pipecharge(req, &acct_pipe, NULL);
 		SES_Close(req->sp, SC_OVERLOAD);
@@ -172,7 +172,7 @@ V1P_Process(struct req *req, struct busyobj *bo)
 	pipecharge(req, &acct_pipe, bo->htc->vbc->backend->vsc);
 	SES_Close(req->sp, SC_TX_PIPE);
 	bo->doclose = SC_TX_PIPE;
-	VDI_Finish(bo->director_resp, bo->wrk, bo);
+	VDI_Finish(bo->wrk, bo);
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list