[experimental-ims] 7209a66 Split registration and selection of backend poll functions into two different functions.
Geoff Simmons
geoff at varnish-cache.org
Fri Jul 8 11:47:52 CEST 2011
commit 7209a66e764e7afd9d8ca179494b1656f0ec0c9b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Jun 30 11:06:51 2011 +0000
Split registration and selection of backend poll functions into two
different functions.
I have not managed to write a vtc case for this one, but I am pretty
sure this:
Fixes: #945
diff --git a/bin/varnishd/cache_backend.c b/bin/varnishd/cache_backend.c
index 8c13112..3d6a405 100644
--- a/bin/varnishd/cache_backend.c
+++ b/bin/varnishd/cache_backend.c
@@ -430,7 +430,7 @@ VBE_UseHealth(const struct director *vdi)
CAST_OBJ_NOTNULL(vs, vdi->priv, VDI_SIMPLE_MAGIC);
if (vs->vrt->probe == NULL)
return;
- VBP_Start(vs->backend, vs->vrt->probe, vs->vrt->hosthdr);
+ VBP_Use(vs->backend, vs->vrt->probe);
}
/*--------------------------------------------------------------------
@@ -475,7 +475,8 @@ vdi_simple_fini(const struct director *d)
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
- VBP_Stop(vs->backend, vs->vrt->probe);
+ if (vs->vrt->probe != NULL)
+ VBP_Remove(vs->backend, vs->vrt->probe);
VBE_DropRefVcl(vs->backend);
free(vs->dir.vcl_name);
vs->dir.magic = 0;
@@ -506,8 +507,8 @@ VRT_init_dir_simple(struct cli *cli, struct director **bp, int idx,
vs->vrt = t;
vs->backend = VBE_AddBackend(cli, t);
- if (vs->backend->probe == NULL)
- VBP_Start(vs->backend, vs->vrt->probe, vs->vrt->hosthdr);
+ if (vs->vrt->probe != NULL)
+ VBP_Insert(vs->backend, vs->vrt->probe, vs->vrt->hosthdr);
bp[idx] = &vs->dir;
}
diff --git a/bin/varnishd/cache_backend.h b/bin/varnishd/cache_backend.h
index cb707ba..c065218 100644
--- a/bin/varnishd/cache_backend.h
+++ b/bin/varnishd/cache_backend.h
@@ -145,8 +145,9 @@ void VBE_DropRefVcl(struct backend *);
void VBE_DropRefLocked(struct backend *b);
/* cache_backend_poll.c */
-void VBP_Start(struct backend *b, struct vrt_backend_probe const *p, const char *hosthdr);
-void VBP_Stop(struct backend *b, struct vrt_backend_probe const *p);
+void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p, const char *hosthdr);
+void VBP_Remove(struct backend *b, struct vrt_backend_probe const *p);
+void VBP_Use(struct backend *b, const struct vrt_backend_probe const *p);
/* Init functions for directors */
typedef void dir_init_f(struct cli *, struct director **, int , const void*);
diff --git a/bin/varnishd/cache_backend_poll.c b/bin/varnishd/cache_backend_poll.c
index d1acf2a..d7b5268 100644
--- a/bin/varnishd/cache_backend_poll.c
+++ b/bin/varnishd/cache_backend_poll.c
@@ -463,11 +463,11 @@ vbp_new_vcl(const struct vrt_backend_probe *p, const char *hosthdr)
}
/*--------------------------------------------------------------------
- * Start/Stop called from cache_backend.c
+ * Insert/Remove/Use called from cache_backend.c
*/
void
-VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *hosthdr)
+VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, const char *hosthdr)
{
struct vbp_target *vt;
struct vbp_vcl *vcl;
@@ -475,9 +475,7 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host
unsigned u;
ASSERT_CLI();
-
- if (p == NULL)
- return;
+ AN(p);
if (b->probe == NULL) {
ALLOC_OBJ(vt, VBP_TARGET_MAGIC);
@@ -493,21 +491,12 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host
vt = b->probe;
}
- VTAILQ_FOREACH(vcl, &vt->vcls, list) {
- if (vcl->probep != p)
- continue;
-
- AZ(startthread);
- Lck_Lock(&vbp_mtx);
- VTAILQ_REMOVE(&vt->vcls, vcl, list);
- VTAILQ_INSERT_HEAD(&vt->vcls, vcl, list);
- Lck_Unlock(&vbp_mtx);
- return;
- }
+ VTAILQ_FOREACH(vcl, &vt->vcls, list)
+ assert (vcl->probep != p);
vcl = vbp_new_vcl(p, hosthdr);
Lck_Lock(&vbp_mtx);
- VTAILQ_INSERT_HEAD(&vt->vcls, vcl, list);
+ VTAILQ_INSERT_TAIL(&vt->vcls, vcl, list);
Lck_Unlock(&vbp_mtx);
if (startthread) {
@@ -521,21 +510,42 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host
}
void
-VBP_Stop(struct backend *b, struct vrt_backend_probe const *p)
+VBP_Use(struct backend *b, const struct vrt_backend_probe *p)
{
struct vbp_target *vt;
struct vbp_vcl *vcl;
- void *ret;
ASSERT_CLI();
+ AN(p);
+ CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
+ AN(b->probe);
+ vt = b->probe;
- if (p == NULL)
+ VTAILQ_FOREACH(vcl, &vt->vcls, list) {
+ if (vcl->probep != p)
+ continue;
+
+ Lck_Lock(&vbp_mtx);
+ VTAILQ_REMOVE(&vt->vcls, vcl, list);
+ VTAILQ_INSERT_HEAD(&vt->vcls, vcl, list);
+ Lck_Unlock(&vbp_mtx);
return;
+ }
+}
- CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
+void
+VBP_Remove(struct backend *b, struct vrt_backend_probe const *p)
+{
+ struct vbp_target *vt;
+ struct vbp_vcl *vcl;
+ void *ret;
+ ASSERT_CLI();
+ AN(p);
+ CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
AN(b->probe);
vt = b->probe;
+
VTAILQ_FOREACH(vcl, &vt->vcls, list)
if (vcl->probep == p)
break;
More information about the varnish-commit
mailing list