Commit ed411722 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Lasse Karstensen

Don't create backends on cooling VCLs, return NULL

parent 6f3fdd21
......@@ -130,5 +130,5 @@ struct vbc *VBT_Get(struct tcp_pool *, double tmo, const struct backend *,
void VBT_Wait(struct worker *, struct vbc *);
/* cache_vcl.c */
void VCL_AddBackend(struct vcl *, struct backend *);
int VCL_AddBackend(struct vcl *, struct backend *);
void VCL_DelBackend(struct backend *);
......@@ -65,10 +65,12 @@ struct director *
VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
{
struct backend *b;
struct director *d;
struct vsb *vsb;
struct vcl *vcl;
struct tcp_pool *tp = NULL;
const struct vrt_backend_probe *vbp;
int retval;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC);
......@@ -123,9 +125,15 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
if (vbp != NULL)
VBP_Insert(b, vbp, tp);
VCL_AddBackend(ctx->vcl, b);
retval = VCL_AddBackend(ctx->vcl, b);
if (retval == 0)
return (b->director);
return (b->director);
d = b->director;
VRT_delete_backend(ctx, &d);
AZ(d);
return (NULL);
}
/*--------------------------------------------------------------------
......
......@@ -193,12 +193,16 @@ VCL_Rel(struct vcl **vcc)
/*--------------------------------------------------------------------*/
void
int
VCL_AddBackend(struct vcl *vcl, struct backend *be)
{
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
if (vcl->temp == vcl_temp_cooling)
return (1);
Lck_Lock(&vcl_mtx);
VTAILQ_INSERT_TAIL(&vcl->backend_list, be, vcl_list);
Lck_Unlock(&vcl_mtx);
......@@ -208,6 +212,8 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be)
VBE_Event(be, VCL_EVENT_WARM);
} else if (vcl->temp != vcl_temp_init)
WRONG("Dynamic Backends can only be added to warm VCLs");
return (0);
}
void
......
......@@ -110,7 +110,9 @@ Finally, Varnish will take care of event propagation for *all* native backends,
but dynamic backends can only be created when the VCL is warm. If your backends
are created by an independent thread (basically outside of VCL scope) you must
subscribe to VCL events and watch for VCL state (see
:ref:`ref-vmod-event-functions`). You are also encouraged to comply with the
:ref:`ref-vmod-event-functions`). Varnish will panic if you try to create a
backend on a cold VCL, and ``VRT_new_backend`` will return ``NULL`` if the VCL
is cooling. You are also encouraged to comply with the
:ref:`ref_vcl_temperature` in general.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment