[master] 1fe06ba Make it cache_vcl's responsibility to send events to backends and to discard them with the VCL.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Jun 22 15:02:12 CEST 2015
commit 1fe06ba636637bbb46617d339d83d3b5c0a4a2cd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jun 22 13:01:43 2015 +0000
Make it cache_vcl's responsibility to send events to backends and to
discard them with the VCL.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index ab3cd4d..da22bf4 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1079,7 +1079,7 @@ void VCL_Ref(struct vcl *);
void VCL_Refresh(struct vcl **);
void VCL_Rel(struct vcl **);
void VCL_AddBackend(struct vcl *, struct backend *);
-void VCL_DelBackend(struct vcl *, const struct backend *);
+void VCL_DelBackend(struct vcl *, struct backend *);
const char *VCL_Return_Name(unsigned);
#define VCL_MET_MAC(l,u,b) \
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index 697b77a..b6b96e4 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -113,6 +113,10 @@ void VBE_fill_director(struct backend *be, const struct vrt_backend *vrt);
/* cache_backend_cfg.c */
unsigned VBE_Healthy(const struct backend *b, double *changed);
+#ifdef VCL_MET_MAX
+void VBE_Event(struct backend *, enum vcl_event_e);
+#endif
+void VBE_Delete(struct backend *be);
/* cache_backend_poll.c */
void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p,
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index 3e07591..15332a1 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -38,19 +38,20 @@
#include "cache.h"
+#include "vcl.h"
+#include "vrt.h"
+
#include "cache_director.h"
#include "cache_backend.h"
#include "vcli.h"
#include "vcli_priv.h"
#include "vsa.h"
-#include "vcl.h"
-#include "vrt.h"
#include "vtim.h"
static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends);
static struct lock backends_mtx;
/*--------------------------------------------------------------------
- * Create a new director::backend instance.
+ * Create/Delete a new director::backend instance.
*/
struct director *
@@ -111,19 +112,31 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
}
void
-VRT_event_vbe(VRT_CTX, enum vcl_event_e ev, const struct director *d,
- const struct vrt_backend *vrt)
+VRT_delete_backend(VRT_CTX, struct director **dp)
{
+ struct director *d;
struct backend *be;
- ASSERT_CLI();
- (void)ev;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ AN(dp);
+ d = *dp;
+ *dp = NULL;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
- CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC);
- assert(d->priv2 == vrt);
-
CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
+ VCL_DelBackend(ctx->vcl, be);
+}
+
+/*---------------------------------------------------------------------
+ * These are for cross-calls with cache_vcl.c only.
+ */
+
+void
+VBE_Event(struct backend *be, enum vcl_event_e ev)
+{
+
+ ASSERT_CLI();
+ CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
+
if (ev == VCL_EVENT_WARM) {
be->vsc = VSM_Alloc(sizeof *be->vsc,
VSC_CLASS, VSC_type_vbe, be->display_name);
@@ -143,25 +156,14 @@ VRT_event_vbe(VRT_CTX, enum vcl_event_e ev, const struct director *d,
}
void
-VRT_delete_backend(VRT_CTX, struct director **dp)
+VBE_Delete(struct backend *be)
{
- struct director *d;
- struct backend *be;
-
- ASSERT_CLI();
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- AN(dp);
- d = *dp;
- *dp = NULL;
- CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
- CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
-
- VCL_DelBackend(ctx->vcl, be);
+ CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
if (be->probe != NULL)
VBP_Remove(be);
- free(d->vcl_name);
+ free(be->director->vcl_name);
Lck_Lock(&backends_mtx);
VTAILQ_REMOVE(&backends, be, list);
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 865daac..02404fd 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -39,15 +39,16 @@
#include "cache.h"
-#include "cache_director.h"
-#include "cache_backend.h"
#include "vcl.h"
#include "vrt.h"
+
+#include "cache_director.h"
+#include "cache_backend.h"
#include "vcli.h"
#include "vcli_priv.h"
static const char * const vcl_temp_cold = "cold";
-static const char * const vcl_temp_warm = "warn";
+static const char * const vcl_temp_warm = "warm";
static const char * const vcl_temp_cooling = "cooling";
struct vcl {
@@ -197,13 +198,42 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be)
}
void
-VCL_DelBackend(struct vcl *vcl, const struct backend *be)
+VCL_DelBackend(struct vcl *vcl, struct backend *be)
{
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
Lck_Lock(&vcl_mtx);
VTAILQ_REMOVE(&vcl->backend_list, be, vcl_list);
Lck_Unlock(&vcl_mtx);
+ VBE_Delete(be);
+}
+
+static void
+vcl_BackendEvent(const struct vcl *vcl, enum vcl_event_e e)
+{
+ struct backend *be;
+
+ CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+ AZ(vcl->busy);
+
+ VTAILQ_FOREACH(be, &vcl->backend_list, vcl_list)
+ VBE_Event(be, e);
+}
+
+static void
+vcl_KillBackends(struct vcl *vcl)
+{
+ struct backend *be;
+
+ CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+ AZ(vcl->busy);
+ while (1) {
+ be = VTAILQ_FIRST(&vcl->backend_list);
+ if (be == NULL)
+ break;
+ VTAILQ_REMOVE(&vcl->backend_list, be, vcl_list);
+ VBE_Delete(be);
+ }
}
/*--------------------------------------------------------------------*/
@@ -346,6 +376,7 @@ vcl_set_state(struct vcl *vcl, const char *state)
if (vcl->busy == 0) {
vcl->temp = vcl_temp_cold;
(void)vcl->conf->event_vcl(&ctx, VCL_EVENT_COLD);
+ vcl_BackendEvent(vcl, VCL_EVENT_COLD);
} else {
vcl->temp = vcl_temp_cooling;
}
@@ -356,6 +387,7 @@ vcl_set_state(struct vcl *vcl, const char *state)
else {
vcl->temp = vcl_temp_warm;
(void)vcl->conf->event_vcl(&ctx, VCL_EVENT_WARM);
+ vcl_BackendEvent(vcl, VCL_EVENT_WARM);
}
break;
default:
@@ -411,6 +443,7 @@ VCL_Load(struct cli *cli, const char *name, const char *fn, const char *state)
if (VSB_len(vsb))
VCLI_Out(cli, "\nMessage:\n\t%s", VSB_data(vsb));
AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_DISCARD));
+ vcl_KillBackends(vcl);
VCL_Close(&vcl);
VSB_delete(vsb);
return (1);
@@ -451,6 +484,7 @@ VCL_Nuke(struct vcl *vcl)
ctx.handling = &hand;
ctx.vcl = vcl;
AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_DISCARD));
+ vcl_KillBackends(vcl);
free(vcl->loaded_name);
VCL_Close(&vcl);
VSC_C_main->n_vcl--;
diff --git a/include/vrt.h b/include/vrt.h
index 27e738e..1dd5d0c 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -243,10 +243,6 @@ void VRT_synth_page(VRT_CTX, const char *, ...);
/* Backend related */
struct director *VRT_new_backend(VRT_CTX, const struct vrt_backend *);
-#ifdef VCL_RET_MAX
-void VRT_event_vbe(VRT_CTX, enum vcl_event_e, const struct director *,
- const struct vrt_backend *);
-#endif
void VRT_delete_backend(VRT_CTX, struct director **);
/* Suckaddr related */
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 2bb3693..9ef1c95 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -412,11 +412,6 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname)
VSB_printf(ifp->ini,
"\t%s =\n\t VRT_new_backend(ctx, &vgc_dir_priv_%s);",
vgcname, vgcname);
- VSB_printf(ifp->fin,
- "\t\tVRT_delete_backend(ctx, &%s);\n", vgcname);
- VSB_printf(ifp->event,
- "\tVRT_event_vbe(ctx, ev, %s, &vgc_dir_priv_%s);",
- vgcname, vgcname);
}
/*--------------------------------------------------------------------
More information about the varnish-commit
mailing list