[master] e9eb047b4 vbp_update_backend: do not assume a director

Nils Goroll nils.goroll at uplex.de
Thu Jun 28 14:24:08 UTC 2018


commit e9eb047b4be4dd92a6bbe425ceaef4461bb12117
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Jun 28 15:31:28 2018 +0200

    vbp_update_backend: do not assume a director
    
    To get out of a catch-22, see second next commit

diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index d8337216b..b5a665a9d 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -153,42 +153,50 @@ vbp_has_poked(struct vbp_target *vt)
 static void
 vbp_update_backend(struct vbp_target *vt)
 {
-	unsigned i;
+	unsigned i = 0;
 	char bits[10];
 	const char *logmsg;
 
 	CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
 
 	Lck_Lock(&vbp_mtx);
-	if (vt->backend != NULL) {
-		i = 0;
+	if (vt->backend == NULL) {
+		Lck_Unlock(&vbp_mtx);
+		return;
+	}
+
 #define BITMAP(n, c, t, b) \
-		bits[i++] = (vt->n & 1) ? c : '-';
+	bits[i++] = (vt->n & 1) ? c : '-';
 #include "tbl/backend_poll.h"
-		bits[i] = '\0';
-		assert(i < sizeof bits);
-
-		if (vt->good >= vt->threshold) {
-			if (vt->backend->director->sick) {
-				logmsg = "Back healthy";
-				VRT_SetHealth(vt->backend->director, 1);
-			} else {
-				logmsg = "Still healthy";
-			}
+	bits[i] = '\0';
+	assert(i < sizeof bits);
+
+	if (vt->backend->director == NULL) {
+		Lck_Unlock(&vbp_mtx);
+		return;
+	}
+
+	if (vt->good >= vt->threshold) {
+		if (vt->backend->director->sick) {
+			logmsg = "Back healthy";
+			VRT_SetHealth(vt->backend->director, 1);
 		} else {
-			if (vt->backend->director->sick) {
-				logmsg = "Still sick";
-			} else {
-				logmsg = "Went sick";
-				VRT_SetHealth(vt->backend->director, 0);
-			}
+			logmsg = "Still healthy";
+		}
+	} else {
+		if (vt->backend->director->sick) {
+			logmsg = "Still sick";
+		} else {
+			logmsg = "Went sick";
+			VRT_SetHealth(vt->backend->director, 0);
 		}
-		VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s",
-		    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);
 	}
+	VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s",
+	    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);
+
 	Lck_Unlock(&vbp_mtx);
 }
 


More information about the varnish-commit mailing list