Skip to content

Commit

Permalink
Use VRT_Notify() when the admin health changes
Browse files Browse the repository at this point in the history
Using the new facility, we can now selectively notify interested backend types
(so far: VBE only) when the admin health changes.

This fixes the layer violation introduced with
e46f972, where a director private pointer was
used with a VBE specific function.

Fixes #4183
  • Loading branch information
nigoroll committed Sep 17, 2024
1 parent a6157a8 commit a217715
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 26 deletions.
14 changes: 3 additions & 11 deletions bin/varnishd/cache/cache_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -688,7 +680,7 @@ vbe_notify(VCL_BACKEND d)

// sick == 0 for _noprobe
if (ah == VDI_AH_SICK || (ah == VDI_AH_AUTO && bp->sick))
VBE_connwait_signal_all(bp);
vbe_connwait_signal_all(bp);
}

/*--------------------------------------------------------------------
Expand Down
6 changes: 2 additions & 4 deletions bin/varnishd/cache/cache_backend_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,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)
VRT_Notify(vt->backend->director);

AN(vt->backend->vcl_name);
VSL(SLT_Backend_health, NO_VXID,
Expand Down
8 changes: 1 addition & 7 deletions bin/varnishd/cache/cache_director.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,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);
Expand All @@ -504,12 +503,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);
}
VRT_Notify(d);
}
return (0);
}
Expand Down
4 changes: 0 additions & 4 deletions bin/varnishd/cache/cache_varnishd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit a217715

Please sign in to comment.