[master] 016531b Shuffling the backend code around a bit in preparation for multi-protocol backends.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Sep 23 12:36:57 CEST 2014
commit 016531bbd66dcbb49630e11b0c1e7b7e143de531
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Sep 23 10:36:28 2014 +0000
Shuffling the backend code around a bit in preparation for multi-protocol
backends.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index f12eb0c..a3b0cd7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -695,6 +695,7 @@ void VBE_UseHealth(const struct director *vdi);
void VBE_DiscardHealth(const struct director *vdi);
+int VDI_GetHdr(struct worker *wrk, struct busyobj *bo);
struct vbc *VDI_GetFd(struct busyobj *);
int VDI_Healthy(const struct director *);
void VDI_CloseFd(struct vbc **vbp, const struct acct_bereq *);
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 9854b41..3dc8c6d 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -42,6 +42,7 @@
#include "cache_backend.h"
#include "vrt.h"
#include "vtcp.h"
+#include "vtim.h"
static struct mempool *vbcpool;
@@ -356,6 +357,35 @@ VBE_DiscardHealth(const struct director *vdi)
}
/*--------------------------------------------------------------------
+ */
+
+int
+VDI_GetHdr(struct worker *wrk, struct busyobj *bo)
+{
+ int i;
+
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+
+ if (bo->director == NULL) {
+ VSLb(bo->vsl, SLT_FetchError, "No backend");
+ return (-1);
+ }
+
+ i = V1F_fetch_hdr(wrk, bo);
+ /*
+ * If we recycle a backend connection, there is a finite chance
+ * that the backend closed it before we get a request to it.
+ * Do a single retry in that case.
+ */
+ if (i == 1) {
+ VSC_C_main->backend_retry++;
+ i = VDI_GetHdr(wrk, bo);
+ }
+ return (i);
+}
+
+/*--------------------------------------------------------------------
*
*/
@@ -378,7 +408,7 @@ vdi_simple_getfd(const struct director *d, struct busyobj *bo)
return (vc);
}
-static unsigned
+static unsigned __match_proto__(vdi_healthy_f)
vdi_simple_healthy(const struct director *d, double *changed)
{
struct vdi_simple *vs;
@@ -391,6 +421,17 @@ vdi_simple_healthy(const struct director *d, double *changed)
return (VBE_Healthy(be, changed));
}
+static int __match_proto__(vdi_gethdrs_f)
+vdi_simple_gethdrs(const struct director *d, struct worker *wrk,
+ struct busyobj *bo)
+{
+
+ CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+ return (-1);
+}
+
/*--------------------------------------------------------------------*/
void
@@ -428,6 +469,7 @@ VRT_init_dir(struct cli *cli, struct director **bp, int idx, const void *priv)
REPLACE(vs->dir.vcl_name, t->vcl_name);
vs->dir.getfd = vdi_simple_getfd;
vs->dir.healthy = vdi_simple_healthy;
+ vs->dir.gethdrs = vdi_simple_gethdrs;
vs->vrt = t;
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index c9ce112..fe4bb15 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -76,7 +76,9 @@ struct vrt_backend_probe;
*/
typedef struct vbc *vdi_getfd_f(const struct director *, struct busyobj *);
-typedef unsigned vdi_healthy(const struct director *, double *changed);
+typedef unsigned vdi_healthy_f(const struct director *, double *changed);
+typedef int vdi_gethdrs_f(const struct director *, struct worker *,
+ struct busyobj *);
struct director {
unsigned magic;
@@ -84,7 +86,8 @@ struct director {
const char *name;
char *vcl_name;
vdi_getfd_f *getfd;
- vdi_healthy *healthy;
+ vdi_healthy_f *healthy;
+ vdi_gethdrs_f *gethdrs;
void *priv;
};
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index c28d1cb..38e72f0 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -265,17 +265,8 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
assert(bo->state <= BOS_REQ_DONE);
- i = V1F_fetch_hdr(wrk, bo);
- /*
- * If we recycle a backend connection, there is a finite chance
- * that the backend closed it before we get a request to it.
- * Do a single retry in that case.
- */
- if (i == 1) {
- VSLb_ts_busyobj(bo, "Beresp", W_TIM_real(wrk));
- VSC_C_main->backend_retry++;
- i = V1F_fetch_hdr(wrk, bo);
- }
+ i = VDI_GetHdr(wrk, bo);
+
now = W_TIM_real(wrk);
VSLb_ts_busyobj(bo, "Beresp", now);
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index a4c4ec5..7e38a34 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -86,15 +86,10 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+ CHECK_OBJ_NOTNULL(bo->director, DIRECTOR_MAGIC);
CHECK_OBJ_ORNULL(bo->req, REQ_MAGIC);
htc = bo->htc;
- if (bo->director == NULL) {
- VSLb(bo->vsl, SLT_FetchError, "No backend");
- return (-1);
- }
- AN(bo->director);
-
hp = bo->bereq;
bo->vbc = VDI_GetFd(bo);
diff --git a/lib/libvmod_directors/vdir.c b/lib/libvmod_directors/vdir.c
index aae7a14..75ea080 100644
--- a/lib/libvmod_directors/vdir.c
+++ b/lib/libvmod_directors/vdir.c
@@ -51,7 +51,7 @@ vdir_expand(struct vdir *vd, unsigned n)
}
void
-vdir_new(struct vdir **vdp, const char *vcl_name, vdi_healthy *healthy,
+vdir_new(struct vdir **vdp, const char *vcl_name, vdi_healthy_f *healthy,
vdi_getfd_f *getfd, void *priv)
{
struct vdir *vd;
diff --git a/lib/libvmod_directors/vdir.h b/lib/libvmod_directors/vdir.h
index d237b2d..583d6e1 100644
--- a/lib/libvmod_directors/vdir.h
+++ b/lib/libvmod_directors/vdir.h
@@ -41,7 +41,7 @@ struct vdir {
struct vbitmap *vbm;
};
-void vdir_new(struct vdir **vdp, const char *vcl_name, vdi_healthy *healthy,
+void vdir_new(struct vdir **vdp, const char *vcl_name, vdi_healthy_f *healthy,
vdi_getfd_f *getfd, void *priv);
void vdir_delete(struct vdir **vdp);
void vdir_lock(struct vdir *vd);
More information about the varnish-commit
mailing list