[master] fd9664e Compress the admin health code a bit

Poul-Henning Kamp phk at FreeBSD.org
Mon Apr 23 22:06:22 UTC 2018


commit fd9664eafd666e289275b807f7eb49dd563d73bd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Apr 23 20:47:44 2018 +0000

    Compress the admin health code a bit

diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 3b6e4b7..bfc931a 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -47,10 +47,11 @@
 
 struct vdi_ahealth {
 	const char		*name;
+	int			health;
 };
 
-#define VBE_AHEALTH(l,u)						\
-	static const struct vdi_ahealth vdi_ah_##l[1] = {{#l}};		\
+#define VBE_AHEALTH(l,u,h)						\
+	static const struct vdi_ahealth vdi_ah_##l[1] = {{#l,h}};	\
 	const struct vdi_ahealth * const VDI_AH_##u = vdi_ah_##l;
 VBE_AHEALTH_LIST
 #undef VBE_AHEALTH
@@ -58,7 +59,7 @@ VBE_AHEALTH_LIST
 static const struct vdi_ahealth *
 vdi_str2ahealth(const char *t)
 {
-#define VBE_AHEALTH(l,u) if (!strcasecmp(t, #l)) return (VDI_AH_##u);
+#define VBE_AHEALTH(l,u,h) if (!strcasecmp(t, #l)) return (VDI_AH_##u);
 VBE_AHEALTH_LIST
 #undef VBE_AHEALTH
 	if (!strcasecmp(t, "auto")) return (VDI_AH_PROBE);
@@ -265,23 +266,15 @@ unsigned
 VDI_Healthy(const struct director *d, double *changed)
 {
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+	AN(d->admin_health);
 
 	if (changed != NULL)
 		*changed = d->health_changed;
 
-	if (d->admin_health == VDI_AH_PROBE)
+	if (d->admin_health->health < 0)
 		return (d->health);
 
-	if (d->admin_health == VDI_AH_SICK)
-		return (0);
-
-	if (d->admin_health == VDI_AH_DELETED)
-		return (0);
-
-	if (d->admin_health == VDI_AH_HEALTHY)
-		return (1);
-
-	WRONG("Wrong admin health");
+	return (d->admin_health->health);
 }
 
 /*---------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index 7db5a4b..9e98da7 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -97,13 +97,13 @@ void VCL_DelDirector(struct director *);
 
 /* cache_director.c */
 
-#define VBE_AHEALTH_LIST			\
-	VBE_AHEALTH(healthy,	HEALTHY)	\
-	VBE_AHEALTH(sick,	SICK)		\
-	VBE_AHEALTH(probe,	PROBE)		\
-	VBE_AHEALTH(deleted,	DELETED)
+#define VBE_AHEALTH_LIST					\
+	VBE_AHEALTH(healthy,	HEALTHY,	1)		\
+	VBE_AHEALTH(sick,	SICK,		0)		\
+	VBE_AHEALTH(probe,	PROBE,		-1)		\
+	VBE_AHEALTH(deleted,	DELETED,	0)
 
-#define VBE_AHEALTH(l,u) extern const struct vdi_ahealth * const VDI_AH_##u;
+#define VBE_AHEALTH(l,u,h) extern const struct vdi_ahealth * const VDI_AH_##u;
 VBE_AHEALTH_LIST
 #undef VBE_AHEALTH
 


More information about the varnish-commit mailing list