[master] cc8f349 Chop a part of cache_director.h into vrt.h, taking the rest of the file off-limits for VMODs.

Poul-Henning Kamp phk at FreeBSD.org
Tue May 1 13:06:16 UTC 2018


commit cc8f349f809d4a91761bec73d2e4a92792690349
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 1 13:04:34 2018 +0000

    Chop a part of cache_director.h into vrt.h, taking the rest
    of the file off-limits for VMODs.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index e1ed9a8..88a28cd 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -40,7 +40,6 @@
 #include "vtcp.h"
 #include "vtim.h"
 
-#include "cache_director.h"
 #include "cache_backend.h"
 #include "cache_tcp_pool.h"
 #include "cache_transport.h"
@@ -88,7 +87,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo,
 	CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
 	AN(bp->vsc);
 
-	if (!bp->director->health) {
+	if (bp->director->sick) {
 		VSLb(bo->vsl, SLT_FetchError,
 		     "backend %s: unhealthy", VRT_BACKEND_string(bp->director));
 		// XXX: per backend stats ?
@@ -422,14 +421,14 @@ vbe_list(const struct director *d, struct vsb *vsb, int vflag, int pflag)
 	if (bp->probe != NULL)
 		VBP_Status(vsb, bp, vflag | pflag);
 	else
-		VSB_printf(vsb, "%-10s", d->health ? "healthy" : "sick");
+		VSB_printf(vsb, "%-10s", d->sick ? "sick" : "healthy");
 }
 
 /*--------------------------------------------------------------------
  */
 
-static const struct director_methods vbe_methods[1] = {{
-	.magic =		DIRECTOR_METHODS_MAGIC,
+static const struct vdi_methods vbe_methods[1] = {{
+	.magic =		VDI_METHODS_MAGIC,
 	.type =			"backend",
 	.http1pipe =		vbe_dir_http1pipe,
 	.gethdrs =		vbe_dir_gethdrs,
diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index dbf0520..37b6016 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -49,7 +49,6 @@
 #include "vtcp.h"
 #include "vtim.h"
 
-#include "cache_director.h"
 #include "cache_backend.h"
 #include "cache_tcp_pool.h"
 
@@ -168,22 +167,22 @@ vbp_update_backend(struct vbp_target *vt)
 		assert(i < sizeof bits);
 
 		if (vt->good >= vt->threshold) {
-			if (vt->backend->director->health) {
-				logmsg = "Still healthy";
-			} else {
+			if (vt->backend->director->sick) {
 				logmsg = "Back healthy";
 				VRT_SetHealth(vt->backend->director, 1);
+			} else {
+				logmsg = "Still healthy";
 			}
 		} else {
-			if (vt->backend->director->health) {
+			if (vt->backend->director->sick) {
+				logmsg = "Still sick";
+			} else {
 				logmsg = "Went sick";
 				VRT_SetHealth(vt->backend->director, 0);
-			} else {
-				logmsg = "Still sick";
 			}
 		}
 		VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s",
-		    vt->backend->director->cli_name, logmsg, bits,
+		    vt->backend->director->vcl_name, logmsg, bits,
 		    vt->good, vt->threshold, vt->window,
 		    vt->last, vt->avg, vt->resp_buf);
 		VBE_SetHappy(vt->backend, vt->happy);
@@ -485,7 +484,7 @@ VBP_Status(struct vsb *vsb, const struct backend *be, int details)
 
 	if (!details) {
 		bprintf(buf, "%d/%d %s", vt->good, vt->window,
-		    vt->backend->director->health ? "good" : "bad");
+		    vt->backend->director->sick ? "bad" : "good");
 		VSB_printf(vsb, "%-10s", buf);
 		return;
 	}
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index cedb41b..feff1b7 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -65,13 +65,13 @@ VBE_AHEALTH_LIST
 	return (NULL);
 }
 
-const char *
+static const char *
 VDI_Ahealth(const struct director *d)
 {
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	AN(d->admin_health);
-	return (d->admin_health->name);
+	AN(d->vdir->admin_health);
+	return (d->vdir->admin_health->name);
 }
 
 /* Resolve director --------------------------------------------------*/
@@ -88,10 +88,10 @@ VDI_Resolve(VRT_CTX)
 	CHECK_OBJ_ORNULL(bo->director_req, DIRECTOR_MAGIC);
 
 	for (d = bo->director_req; d != NULL &&
-	    d->methods->resolve != NULL; d = d2) {
+	    d->vdir->methods->resolve != NULL; d = d2) {
 		CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 		AN(d->vdir);
-		d2 = d->methods->resolve(ctx, d);
+		d2 = d->vdir->methods->resolve(ctx, d);
 		if (d2 == NULL)
 			VSLb(bo->vsl, SLT_FetchError,
 			    "Director %s returned no backend", d->vcl_name);
@@ -120,9 +120,9 @@ VDI_GetHdr(struct busyobj *bo)
 	d = VDI_Resolve(ctx);
 	if (d != NULL) {
 		bo->director_resp = d;
-		AN(d->methods->gethdrs);
+		AN(d->vdir->methods->gethdrs);
 		bo->director_state = DIR_S_HDRS;
-		i = d->methods->gethdrs(ctx, d);
+		i = d->vdir->methods->gethdrs(ctx, d);
 	}
 	if (i)
 		bo->director_state = DIR_S_NULL;
@@ -143,13 +143,13 @@ VDI_GetBody(struct busyobj *bo)
 
 	d = bo->director_resp;
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	AZ(d->methods->resolve);
+	AZ(d->vdir->methods->resolve);
 
 	assert(bo->director_state == DIR_S_HDRS);
 	bo->director_state = DIR_S_BODY;
-	if (d->methods->getbody == NULL)
+	if (d->vdir->methods->getbody == NULL)
 		return (0);
-	return (d->methods->getbody(ctx, d));
+	return (d->vdir->methods->getbody(ctx, d));
 }
 
 /* Get IP number (if any ) -------------------------------------------*/
@@ -168,10 +168,10 @@ VDI_GetIP(struct busyobj *bo)
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	assert(bo->director_state == DIR_S_HDRS ||
 	   bo->director_state == DIR_S_BODY);
-	AZ(d->methods->resolve);
-	if (d->methods->getip == NULL)
+	AZ(d->vdir->methods->resolve);
+	if (d->vdir->methods->getip == NULL)
 		return (NULL);
-	return (d->methods->getip(ctx, d));
+	return (d->vdir->methods->getip(ctx, d));
 }
 
 /* Finish fetch ------------------------------------------------------*/
@@ -189,11 +189,11 @@ VDI_Finish(struct busyobj *bo)
 	d = bo->director_resp;
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 
-	AZ(d->methods->resolve);
-	AN(d->methods->finish);
+	AZ(d->vdir->methods->resolve);
+	AN(d->vdir->methods->finish);
 
 	assert(bo->director_state != DIR_S_NULL);
-	d->methods->finish(ctx, d);
+	d->vdir->methods->finish(ctx, d);
 	bo->director_state = DIR_S_NULL;
 }
 
@@ -212,12 +212,12 @@ VDI_Http1Pipe(struct req *req, struct busyobj *bo)
 	VCL_Bo2Ctx(ctx, bo);
 
 	d = VDI_Resolve(ctx);
-	if (d == NULL || d->methods->http1pipe == NULL) {
+	if (d == NULL || d->vdir->methods->http1pipe == NULL) {
 		VSLb(bo->vsl, SLT_VCL_Error, "Backend does not support pipe");
 		return (SC_TX_ERROR);
 	}
 	bo->director_resp = d;
-	return (d->methods->http1pipe(ctx, d));
+	return (d->vdir->methods->http1pipe(ctx, d));
 }
 
 /* Check health --------------------------------------------------------
@@ -238,19 +238,19 @@ VRT_Healthy(VRT_CTX, VCL_BACKEND d, VCL_TIME *changed)
 		return (0);
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 
-	if (d->admin_health->health >= 0) {
+	if (d->vdir->admin_health->health >= 0) {
 		if (changed != NULL)
-			*changed = d->health_changed;
-		return (d->admin_health->health);
+			*changed = d->vdir->health_changed;
+		return (d->vdir->admin_health->health);
 	}
 
-	if (d->methods->healthy == NULL) {
+	if (d->vdir->methods->healthy == NULL) {
 		if (changed != NULL)
-			*changed = d->health_changed;
-		return (d->health);
+			*changed = d->vdir->health_changed;
+		return (!d->sick);
 	}
 
-	return (d->methods->healthy(ctx, d, changed));
+	return (d->vdir->methods->healthy(ctx, d, changed));
 }
 
 /* Send Event ----------------------------------------------------------
@@ -261,8 +261,8 @@ VDI_Event(const struct director *d, enum vcl_event_e ev)
 {
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
-	if (d->methods->event != NULL)
-		d->methods->event(d, ev);
+	if (d->vdir->methods->event != NULL)
+		d->vdir->methods->event(d, ev);
 }
 
 /* Dump panic info -----------------------------------------------------
@@ -275,14 +275,14 @@ VDI_Panic(const struct director *d, struct vsb *vsb, const char *nm)
 		return;
 	VSB_printf(vsb, "%s = %p {\n", nm, d);
 	VSB_indent(vsb, 2);
-	VSB_printf(vsb, "cli_name = %s,\n", d->cli_name);
-	VSB_printf(vsb, "health = %s,\n", d->health ?  "healthy" : "sick");
+	VSB_printf(vsb, "cli_name = %s,\n", d->vdir->cli_name);
+	VSB_printf(vsb, "health = %s,\n", d->sick ?  "sick" : "healthy");
 	VSB_printf(vsb, "admin_health = %s, changed = %f,\n",
-	    VDI_Ahealth(d), d->health_changed);
-	VSB_printf(vsb, "type = %s {\n", d->methods->type);
+	    VDI_Ahealth(d), d->vdir->health_changed);
+	VSB_printf(vsb, "type = %s {\n", d->vdir->methods->type);
 	VSB_indent(vsb, 2);
-	if (d->methods->panic != NULL)
-		d->methods->panic(d, vsb);
+	if (d->vdir->methods->panic != NULL)
+		d->vdir->methods->panic(d, vsb);
 	VSB_indent(vsb, -2);
 	VSB_printf(vsb, "},\n");
 	VSB_indent(vsb, -2);
@@ -308,20 +308,20 @@ do_list(struct cli *cli, struct director *d, void *priv)
 	CAST_OBJ_NOTNULL(la, priv, LIST_ARGS_MAGIC);
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 
-	if (d->admin_health == VDI_AH_DELETED)
+	if (d->vdir->admin_health == VDI_AH_DELETED)
 		return (0);
 
-	VCLI_Out(cli, "\n%-30s %-7s ", d->cli_name, VDI_Ahealth(d));
+	VCLI_Out(cli, "\n%-30s %-7s ", d->vdir->cli_name, VDI_Ahealth(d));
 
-	if (d->methods->list != NULL)
-		d->methods->list(d, cli->sb, 0, 0);
+	if (d->vdir->methods->list != NULL)
+		d->vdir->methods->list(d, cli->sb, 0, 0);
 	else
-		VCLI_Out(cli, "%-10s", d->health ? "healthy" : "sick");
+		VCLI_Out(cli, "%-10s", d->sick ? "sick" : "halthy");
 
-	VTIM_format(d->health_changed, time_str);
+	VTIM_format(d->vdir->health_changed, time_str);
 	VCLI_Out(cli, " %s", time_str);
-	if ((la->p || la->v) && d->methods->list != NULL)
-		d->methods->list(d, cli->sb, la->p, la->v);
+	if ((la->p || la->v) && d->vdir->methods->list != NULL)
+		d->vdir->methods->list(d, cli->sb, la->p, la->v);
 	return (0);
 }
 
@@ -373,12 +373,13 @@ do_set_health(struct cli *cli, struct director *d, void *priv)
 	(void)cli;
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(sh, priv, SET_HEALTH_MAGIC);
-	if (d->admin_health == VDI_AH_DELETED)
+	if (d->vdir->admin_health == VDI_AH_DELETED)
 		return (0);
-	if (d->admin_health != sh->ah) {
-		d->health_changed = VTIM_real();
-		d->admin_health = sh->ah;
-		d->health = sh->ah->health ? 1 : 0;
+	if (d->vdir->admin_health != sh->ah) {
+		d->vdir->health_changed = VTIM_real();
+		d->vdir->admin_health = sh->ah;
+		d->sick &= ~0x02;
+		d->sick |= sh->ah->health ? 0 : 0x02;
 	}
 	return (0);
 }
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index 9697533..124ff2e 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2015 Varnish Software AS
+ * Copyright (c) 2006-2018 Varnish Software AS
  * All rights reserved.
  *
  * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
@@ -26,76 +26,26 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * Director APIs
- *
- * A director ("VDI") is an abstract entity which can either satisfy a
- * backend fetch request or select another director for the job.
- *
- * In theory a director does not have to talk HTTP over TCP, it can satisfy
- * the backend request using any means it wants, although this is presently
- * not implemented.
+ * This is the private implementation of directors.
+ * You are not supposed to need anything here.
  *
  */
 
-struct vcldir;
-
-typedef VCL_BOOL vdi_healthy_f(VRT_CTX, VCL_BACKEND, VCL_TIME *);
-typedef VCL_BACKEND vdi_resolve_f(VRT_CTX, VCL_BACKEND);
-typedef int vdi_gethdrs_f(VRT_CTX, VCL_BACKEND);
-typedef int vdi_getbody_f(VRT_CTX, VCL_BACKEND);
-typedef VCL_IP vdi_getip_f(VRT_CTX, VCL_BACKEND);
-typedef void vdi_finish_f(VRT_CTX, VCL_BACKEND);
-typedef enum sess_close vdi_http1pipe_f(VRT_CTX, VCL_BACKEND);
-typedef void vdi_event_f(VCL_BACKEND, enum vcl_event_e);
-typedef void vdi_destroy_f(VCL_BACKEND);
-typedef void vdi_panic_f(VCL_BACKEND, struct vsb *);
-typedef void vdi_list_f(VCL_BACKEND, struct vsb *, int, int);
+struct vdi_methods;
 
-struct director_methods {
+struct vcldir {
 	unsigned			magic;
-#define DIRECTOR_METHODS_MAGIC		0x4ec0c4bb
-	const char			*type;
-	vdi_http1pipe_f			*http1pipe;
-	vdi_healthy_f			*healthy;
-	vdi_resolve_f			*resolve;
-	vdi_gethdrs_f			*gethdrs;
-	vdi_getbody_f			*getbody;
-	vdi_getip_f			*getip;
-	vdi_finish_f			*finish;
-	vdi_event_f			*event;
-	vdi_destroy_f			*destroy;
-	vdi_panic_f			*panic;
-	vdi_list_f			*list;
-};
-
-struct director {
-	unsigned			magic;
-#define DIRECTOR_MAGIC			0x3336351d
-	const struct director_methods	*methods;
-	char				*vcl_name;
-
-	void				*priv;
-
-	/* Internal Housekeeping fields */
-
-	struct vcldir			*vdir;
-
-	char				*cli_name;
-
+#define VCLDIR_MAGIC			0xbf726c7d
+	struct director			*dir;
+	struct vcl			*vcl;
+	const struct vdi_methods	*methods;
+	VTAILQ_ENTRY(vcldir)		list;
 	unsigned			health;
 	const struct vdi_ahealth	*admin_health;
 	double				health_changed;
+	char				*cli_name;
 };
 
-
-/* cache_vcl.c */
-VCL_BACKEND VRT_AddDirector(VRT_CTX, const struct director_methods *,
-    void *, const char *, ...) v_printflike_(4, 5);
-
-void VRT_SetHealth(VCL_BACKEND d, int health);
-void VRT_DisableDirector(VCL_BACKEND);
-void VRT_DelDirector(VCL_BACKEND *);
-
 /* cache_director.c */
 
 #define VBE_AHEALTH_LIST					\
@@ -107,5 +57,3 @@ void VRT_DelDirector(VCL_BACKEND *);
 #define VBE_AHEALTH(l,u,h) extern const struct vdi_ahealth * const VDI_AH_##u;
 VBE_AHEALTH_LIST
 #undef VBE_AHEALTH
-
-const char *VDI_Ahealth(const struct director *d);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 4427cae..a402fce 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -30,7 +30,6 @@
 #include "config.h"
 
 #include "cache_varnishd.h"
-#include "cache_director.h"
 #include "cache_filter.h"
 #include "cache_objhead.h"
 #include "hash/hash_slinger.h"
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 00a0249..b36e85d 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -39,7 +39,6 @@
 #include "config.h"
 
 #include "cache_varnishd.h"
-#include "cache_director.h"
 #include "cache_filter.h"
 #include "cache_objhead.h"
 #include "cache_transport.h"
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index ed57193..0a63c04 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -263,7 +263,7 @@ vcl_iterdir(struct cli *cli, const char *pat, const struct vcl *vcl,
 	struct vcldir *vdir;
 
 	VTAILQ_FOREACH(vdir, &vcl->director_list, list) {
-		if (fnmatch(pat, vdir->dir->cli_name, 0))
+		if (fnmatch(pat, vdir->cli_name, 0))
 			continue;
 		found++;
 		i = func(cli, vdir->dir, priv);
@@ -344,9 +344,9 @@ vcl_KillBackends(struct vcl *vcl)
 		if (vdir == NULL)
 			break;
 		VTAILQ_REMOVE(&vcl->director_list, vdir, list);
-		REPLACE(vdir->dir->cli_name, NULL);
-		AN(vdir->dir->methods->destroy);
-		vdir->dir->methods->destroy(vdir->dir);
+		REPLACE(vdir->cli_name, NULL);
+		AN(vdir->methods->destroy);
+		vdir->methods->destroy(vdir->dir);
 		FREE_OBJ(vdir);
 	}
 }
diff --git a/bin/varnishd/cache/cache_vcl.h b/bin/varnishd/cache/cache_vcl.h
index e5a5453..f344c37 100644
--- a/bin/varnishd/cache/cache_vcl.h
+++ b/bin/varnishd/cache/cache_vcl.h
@@ -35,13 +35,6 @@ struct vfp_filter;
 
 VTAILQ_HEAD(vfp_filter_head, vfp_filter);
 
-struct vcldir {
-	unsigned		magic;
-#define VCLDIR_MAGIC		0xbf726c7d
-	struct director		*dir;
-	struct vcl		*vcl;
-	VTAILQ_ENTRY(vcldir)	list;
-};
 
 struct vcl {
 	unsigned		magic;
diff --git a/bin/varnishd/cache/cache_vcl_vrt.c b/bin/varnishd/cache/cache_vcl_vrt.c
index b97aae1..fc07bfd 100644
--- a/bin/varnishd/cache/cache_vcl_vrt.c
+++ b/bin/varnishd/cache/cache_vcl_vrt.c
@@ -127,7 +127,7 @@ VCL_Rel(struct vcl **vcc)
 /*--------------------------------------------------------------------*/
 
 VCL_BACKEND
-VRT_AddDirector(VRT_CTX, const struct director_methods *m, void *priv,
+VRT_AddDirector(VRT_CTX, const struct vdi_methods *m, void *priv,
     const char *fmt, ...)
 {
 	struct vsb *vsb;
@@ -138,7 +138,7 @@ VRT_AddDirector(VRT_CTX, const struct director_methods *m, void *priv,
 	int i;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	CHECK_OBJ_NOTNULL(m, DIRECTOR_METHODS_MAGIC);
+	CHECK_OBJ_NOTNULL(m, VDI_METHODS_MAGIC);
 	AN(fmt);
 	vcl = ctx->vcl;
 	CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
@@ -150,9 +150,14 @@ VRT_AddDirector(VRT_CTX, const struct director_methods *m, void *priv,
 
 	ALLOC_OBJ(d, DIRECTOR_MAGIC);
 	AN(d);
-	d->methods = m;
+	ALLOC_OBJ(vdir, VCLDIR_MAGIC);
+	AN(vdir);
+	vdir->dir = d;
+	d->vdir = vdir;
+
+	vdir->methods = m;
 	d->priv = priv;
-	d->admin_health = VDI_AH_PROBE;
+	vdir->admin_health = VDI_AH_PROBE;
 	vsb = VSB_new_auto();
 	AN(vsb);
 	VSB_printf(vsb, "%s.", VCL_Name(vcl));
@@ -161,18 +166,14 @@ VRT_AddDirector(VRT_CTX, const struct director_methods *m, void *priv,
 	VSB_vprintf(vsb, fmt, ap);
 	va_end(ap);
 	AZ(VSB_finish(vsb));
-	REPLACE((d->cli_name), VSB_data(vsb));
+	REPLACE((vdir->cli_name), VSB_data(vsb));
 	VSB_destroy(&vsb);
-	d->vcl_name = d->cli_name + i;
+	d->vcl_name = vdir->cli_name + i;
 
-	ALLOC_OBJ(vdir, VCLDIR_MAGIC);
-	AN(vdir);
-	vdir->dir = d;
 	vdir->vcl = vcl;
-	d->vdir = vdir;
-	d->health = 1;
-	d->admin_health = VDI_AH_PROBE;
-	d->health_changed = VTIM_real();
+	d->sick = 0;
+	vdir->admin_health = VDI_AH_PROBE;
+	vdir->health_changed = VTIM_real();
 
 	Lck_Lock(&vcl_mtx);
 	VTAILQ_INSERT_TAIL(&vcl->director_list, vdir, list);
@@ -208,9 +209,9 @@ VRT_DelDirector(VCL_BACKEND *bp)
 	if (VCL_WARM(vcl))
 		VDI_Event(d, VCL_EVENT_COLD);
 	AZ(errno=pthread_rwlock_unlock(&vcl->temp_rwl));
-	if(d->methods->destroy != NULL)
-		d->methods->destroy(d);
-	free(d->cli_name);
+	if(vdir->methods->destroy != NULL)
+		vdir->methods->destroy(d);
+	free(vdir->cli_name);
 	FREE_OBJ(vdir->dir);
 	FREE_OBJ(vdir);
 }
@@ -224,8 +225,11 @@ VRT_SetHealth(VCL_BACKEND d, int health)
 	vdir = d->vdir;
 	CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC);
 
-	vdir->dir->health = health;
-	vdir->dir->health_changed = VTIM_real();
+	if (health)
+		vdir->dir->sick &= ~0x01;
+	else
+		vdir->dir->sick |= 0x01;
+	vdir->health_changed = VTIM_real();
 }
 
 void
@@ -237,9 +241,9 @@ VRT_DisableDirector(VCL_BACKEND d)
 	vdir = d->vdir;
 	CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC);
 
-	vdir->dir->admin_health = VDI_AH_DELETED;
-	vdir->dir->health = 0;
-	vdir->dir->health_changed = VTIM_real();
+	vdir->admin_health = VDI_AH_DELETED;
+	vdir->dir->sick |= 0x04;
+	vdir->health_changed = VTIM_real();
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 6001d32..015c412 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -33,7 +33,6 @@
 
 #include "cache_varnishd.h"
 
-#include "cache_director.h"
 #include "cache_objhead.h"
 #include "vav.h"
 #include "vcl.h"
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index d62e9cd..3205573 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -37,7 +37,6 @@
 
 #include "vcl.h"
 
-#include "cache_director.h"
 #include "vrt_obj.h"
 
 static char vrt_hostname[255] = "";
diff --git a/include/vrt.h b/include/vrt.h
index 37a0937..d23ee9e 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -411,14 +411,58 @@ VCL_BACKEND VRT_new_backend_clustered(VRT_CTX,
     struct vsmw_cluster *, const struct vrt_backend *);
 size_t VRT_backend_vsm_need(VRT_CTX);
 void VRT_delete_backend(VRT_CTX, VCL_BACKEND *);
-int VRT_backend_healthy(VRT_CTX, VCL_BACKEND);
 
 /* VSM related */
 struct vsmw_cluster *VRT_VSM_Cluster_New(VRT_CTX, size_t);
 void VRT_VSM_Cluster_Destroy(VRT_CTX, struct vsmw_cluster **);
 
-/* cache_director.c */
+/* VDI - Director API */
+typedef VCL_BOOL vdi_healthy_f(VRT_CTX, VCL_BACKEND, VCL_TIME *);
+typedef VCL_BACKEND vdi_resolve_f(VRT_CTX, VCL_BACKEND);
+typedef int vdi_gethdrs_f(VRT_CTX, VCL_BACKEND);
+typedef int vdi_getbody_f(VRT_CTX, VCL_BACKEND);
+typedef VCL_IP vdi_getip_f(VRT_CTX, VCL_BACKEND);
+typedef void vdi_finish_f(VRT_CTX, VCL_BACKEND);
+typedef enum sess_close vdi_http1pipe_f(VRT_CTX, VCL_BACKEND);
+typedef void vdi_event_f(VCL_BACKEND, enum vcl_event_e);
+typedef void vdi_destroy_f(VCL_BACKEND);
+typedef void vdi_panic_f(VCL_BACKEND, struct vsb *);
+typedef void vdi_list_f(VCL_BACKEND, struct vsb *, int, int);
+
+struct vdi_methods {
+	unsigned			magic;
+#define VDI_METHODS_MAGIC		0x4ec0c4bb
+	const char			*type;
+	vdi_http1pipe_f			*http1pipe;
+	vdi_healthy_f			*healthy;
+	vdi_resolve_f			*resolve;
+	vdi_gethdrs_f			*gethdrs;
+	vdi_getbody_f			*getbody;
+	vdi_getip_f			*getip;
+	vdi_finish_f			*finish;
+	vdi_event_f			*event;
+	vdi_destroy_f			*destroy;
+	vdi_panic_f			*panic;
+	vdi_list_f			*list;
+};
+
+struct vcldir;
+
+struct director {
+	unsigned			magic;
+#define DIRECTOR_MAGIC			0x3336351d
+	unsigned			sick;
+	void				*priv;
+	char				*vcl_name;
+	struct vcldir			*vdir;
+};
+
 VCL_BOOL VRT_Healthy(VRT_CTX, VCL_BACKEND, VCL_TIME *);
+VCL_BACKEND VRT_AddDirector(VRT_CTX, const struct vdi_methods *,
+    void *, const char *, ...) v_printflike_(4, 5);
+void VRT_SetHealth(VCL_BACKEND d, int health);
+void VRT_DisableDirector(VCL_BACKEND);
+void VRT_DelDirector(VCL_BACKEND *);
 
 /* Suckaddr related */
 int VRT_VSA_GetPtr(const struct suckaddr *sua, const unsigned char ** dst);
diff --git a/lib/libvmod_directors/fall_back.c b/lib/libvmod_directors/fall_back.c
index 07d8c97..e4a5a12 100644
--- a/lib/libvmod_directors/fall_back.c
+++ b/lib/libvmod_directors/fall_back.c
@@ -32,7 +32,6 @@
 #include <string.h>
 
 #include "cache/cache.h"
-#include "cache/cache_director.h"
 
 #include "vcc_if.h"
 
@@ -85,8 +84,8 @@ vmod_fallback_resolve(VRT_CTX, VCL_BACKEND dir)
 	return (be);
 }
 
-static const struct director_methods vmod_fallback_methods[1] = {{
-	.magic =		DIRECTOR_METHODS_MAGIC,
+static const struct vdi_methods vmod_fallback_methods[1] = {{
+	.magic =		VDI_METHODS_MAGIC,
 	.type =			"fallback",
 	.healthy =		vmod_fallback_healthy,
 	.resolve =		vmod_fallback_resolve,
diff --git a/lib/libvmod_directors/hash.c b/lib/libvmod_directors/hash.c
index 1e4d9de..9a362cb 100644
--- a/lib/libvmod_directors/hash.c
+++ b/lib/libvmod_directors/hash.c
@@ -32,7 +32,6 @@
 #include <string.h>
 
 #include "cache/cache.h"
-#include "cache/cache_director.h"
 
 #include "vend.h"
 #include "vsha256.h"
@@ -47,8 +46,8 @@ struct vmod_directors_hash {
 	struct vdir				*vd;
 };
 
-static const struct director_methods vmod_hash_methods[1] = {{
-	.magic =		DIRECTOR_METHODS_MAGIC,
+static const struct vdi_methods vmod_hash_methods[1] = {{
+	.magic =		VDI_METHODS_MAGIC,
 	.type =			"hash",
 }};
 
diff --git a/lib/libvmod_directors/random.c b/lib/libvmod_directors/random.c
index c89fb8e..3968e5c 100644
--- a/lib/libvmod_directors/random.c
+++ b/lib/libvmod_directors/random.c
@@ -31,7 +31,6 @@
 #include <stdlib.h>
 
 #include "cache/cache.h"
-#include "cache/cache_director.h"
 
 #include "vbm.h"
 #include "vrnd.h"
@@ -73,8 +72,8 @@ vmod_random_resolve(VRT_CTX, VCL_BACKEND dir)
 	return (be);
 }
 
-static const struct director_methods vmod_random_methods[1] = {{
-	.magic =		DIRECTOR_METHODS_MAGIC,
+static const struct vdi_methods vmod_random_methods[1] = {{
+	.magic =		VDI_METHODS_MAGIC,
 	.type =			"random",
 	.healthy =		vmod_random_healthy,
 	.resolve =		vmod_random_resolve,
diff --git a/lib/libvmod_directors/round_robin.c b/lib/libvmod_directors/round_robin.c
index c69fbf1..636d88a 100644
--- a/lib/libvmod_directors/round_robin.c
+++ b/lib/libvmod_directors/round_robin.c
@@ -32,7 +32,6 @@
 #include <string.h>
 
 #include "cache/cache.h"
-#include "cache/cache_director.h"
 
 #include "vcc_if.h"
 
@@ -82,8 +81,8 @@ vmod_rr_resolve(VRT_CTX, VCL_BACKEND dir)
 	return (be);
 }
 
-static const struct director_methods vmod_rr_methods[1] = {{
-	.magic =		DIRECTOR_METHODS_MAGIC,
+static const struct vdi_methods vmod_rr_methods[1] = {{
+	.magic =		VDI_METHODS_MAGIC,
 	.type =			"round-robin",
 	.healthy =		vmod_rr_healthy,
 	.resolve =		vmod_rr_resolve,
diff --git a/lib/libvmod_directors/shard_cfg.c b/lib/libvmod_directors/shard_cfg.c
index 152d8df..942932e 100644
--- a/lib/libvmod_directors/shard_cfg.c
+++ b/lib/libvmod_directors/shard_cfg.c
@@ -35,7 +35,6 @@
 #include <string.h>
 
 #include "cache/cache.h"
-#include "cache/cache_director.h"
 
 #include "shard_dir.h"
 #include "shard_cfg.h"
diff --git a/lib/libvmod_directors/shard_dir.c b/lib/libvmod_directors/shard_dir.c
index 9677546..e0a876c 100644
--- a/lib/libvmod_directors/shard_dir.c
+++ b/lib/libvmod_directors/shard_dir.c
@@ -37,7 +37,6 @@
 #include <time.h>
 
 #include "cache/cache.h"
-#include "cache/cache_director.h"
 
 #include "vbm.h"
 #include "vrnd.h"
diff --git a/lib/libvmod_directors/vdir.c b/lib/libvmod_directors/vdir.c
index 714a655..cf38246 100644
--- a/lib/libvmod_directors/vdir.c
+++ b/lib/libvmod_directors/vdir.c
@@ -51,12 +51,12 @@ vdir_expand(struct vdir *vd, unsigned n)
 
 void
 vdir_new(VRT_CTX, struct vdir **vdp, const char *vcl_name,
-    const struct director_methods *m, void *priv)
+    const struct vdi_methods *m, void *priv)
 {
 	struct vdir *vd;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	CHECK_OBJ_NOTNULL(m, DIRECTOR_METHODS_MAGIC);
+	CHECK_OBJ_NOTNULL(m, VDI_METHODS_MAGIC);
 	AN(vcl_name);
 	AN(vdp);
 	AZ(*vdp);
diff --git a/lib/libvmod_directors/vdir.h b/lib/libvmod_directors/vdir.h
index 5531931..15d7999 100644
--- a/lib/libvmod_directors/vdir.h
+++ b/lib/libvmod_directors/vdir.h
@@ -42,7 +42,7 @@ struct vdir {
 };
 
 void vdir_new(VRT_CTX, struct vdir **vdp, const char *vcl_name,
-    const struct director_methods *, void *priv);
+    const struct vdi_methods *, void *priv);
 void vdir_delete(struct vdir **vdp);
 void vdir_rdlock(struct vdir *vd);
 void vdir_wrlock(struct vdir *vd);
diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index 0eabffa..d54128a 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -191,8 +191,8 @@ shard__assert(void)
 	assert(t2a == t2b);
 }
 
-static const struct director_methods vmod_shard_methods[1] = {{
-	.magic =	DIRECTOR_METHODS_MAGIC,
+static const struct vdi_methods vmod_shard_methods[1] = {{
+	.magic =	VDI_METHODS_MAGIC,
 	.type =		"shard",
 	.resolve =	vmod_shard_resolve,
 	.healthy =	vmod_shard_healthy,


More information about the varnish-commit mailing list