[master] d6b6602f7 Use VDI_EVENT_SICK when the admin health changes

Nils Goroll nils.goroll at uplex.de
Mon Sep 30 14:06:05 UTC 2024


commit d6b6602f70c684f023de6d0c01ec9759b0dfd8cd
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Sep 23 19:19:16 2024 +0200

    Use VDI_EVENT_SICK when the admin health changes
    
    Using the new event, we can now selectively notify interested backend types
    (so far: VBE only) when the admin health changes.
    
    This fixes the layer violation introduced with
    e46f97278f1036f4e648dd64d3f34ada8d29f64a, where a director private pointer was
    used with a VBE specific function.
    
    Fixes #4183

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 99d10ed70..29084bd2a 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -139,16 +139,8 @@ VBE_Connect_Error(struct VSC_vbe *vsc, int err)
 
 /*--------------------------------------------------------------------*/
 
-int
-VBE_is_ah_auto(const struct backend *bp)
-{
-
-	CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
-	return (bp->director->vdir->admin_health == VDI_AH_AUTO);
-}
-
-void
-VBE_connwait_signal_all(const struct backend *bp)
+static void
+vbe_connwait_signal_all(const struct backend *bp)
 {
 	struct connwait *cw;
 
@@ -565,7 +557,7 @@ vbe_dir_event(const struct director *d, enum vcl_event_e ev)
 		const struct vdi_ahealth *ah = d->vdir->admin_health;
 
 		if (ah == VDI_AH_SICK || (ah == VDI_AH_AUTO && bp->sick))
-			VBE_connwait_signal_all(bp);
+			vbe_connwait_signal_all(bp);
 	}
 }
 
diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index 502e10310..501ddb64a 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -190,10 +190,8 @@ VBP_Update_Backend(struct vbp_target *vt)
 	i = (vt->good < vt->threshold);
 	chg = (i != vt->backend->sick);
 	vt->backend->sick = i;
-	if (i && chg && (vt->backend->director != NULL &&
-	    VBE_is_ah_auto(vt->backend))) {
-		VBE_connwait_signal_all(vt->backend);
-	}
+	if (i && chg && vt->backend->director != NULL)
+		VDI_Event(vt->backend->director, VDI_EVENT_SICK);
 
 	AN(vt->backend->vcl_name);
 	VSL(SLT_Backend_health, NO_VXID,
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 042ad9f34..ea1a4efb9 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -477,7 +477,6 @@ static int v_matchproto_(vcl_be_func)
 do_set_health(struct cli *cli, struct director *d, void *priv)
 {
 	struct set_health *sh;
-	struct vrt_ctx *ctx;
 
 	(void)cli;
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
@@ -488,12 +487,7 @@ do_set_health(struct cli *cli, struct director *d, void *priv)
 	if (d->vdir->admin_health != sh->ah) {
 		d->vdir->health_changed = VTIM_real();
 		d->vdir->admin_health = sh->ah;
-		ctx = VCL_Get_CliCtx(0);
-		if (sh->ah == VDI_AH_SICK || (sh->ah == VDI_AH_AUTO &&
-		    d->vdir->methods->healthy != NULL &&
-		    !d->vdir->methods->healthy(ctx, d, NULL))) {
-			VBE_connwait_signal_all(d->priv);
-		    }
+		VDI_Event(d, VDI_EVENT_SICK);
 	}
 	return (0);
 }
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index e0b88b4aa..e84f90e0f 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -161,11 +161,7 @@ void VCA_Init(void);
 void VCA_Shutdown(void);
 
 /* cache_backend.c */
-struct backend;
-
 void VBE_InitCfg(void);
-void VBE_connwait_signal_all(const struct backend *bp);
-int VBE_is_ah_auto(const struct backend *bp);
 
 /* cache_ban.c */
 
diff --git a/include/vrt.h b/include/vrt.h
index 13c93be12..9d7d90c14 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -496,7 +496,9 @@ struct vmod_data {
 };
 
 /***********************************************************************
- * VCL events sent to VMODs and directors
+ * Events sent to VMODs and directors:
+ * - VCL: VCL temperature events
+ * - VDI: director events
  */
 
 enum vcl_event_e {
@@ -504,7 +506,7 @@ enum vcl_event_e {
 	VCL_EVENT_WARM,
 	VCL_EVENT_COLD,
 	VCL_EVENT_DISCARD,
-	// Only for directors
+
 	VDI_EVENT_SICK,
 };
 


More information about the varnish-commit mailing list