Commit 7209a66e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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
parent 90b7074b
...@@ -430,7 +430,7 @@ VBE_UseHealth(const struct director *vdi) ...@@ -430,7 +430,7 @@ VBE_UseHealth(const struct director *vdi)
CAST_OBJ_NOTNULL(vs, vdi->priv, VDI_SIMPLE_MAGIC); CAST_OBJ_NOTNULL(vs, vdi->priv, VDI_SIMPLE_MAGIC);
if (vs->vrt->probe == NULL) if (vs->vrt->probe == NULL)
return; 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) ...@@ -475,7 +475,8 @@ vdi_simple_fini(const struct director *d)
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_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); VBE_DropRefVcl(vs->backend);
free(vs->dir.vcl_name); free(vs->dir.vcl_name);
vs->dir.magic = 0; vs->dir.magic = 0;
...@@ -506,8 +507,8 @@ VRT_init_dir_simple(struct cli *cli, struct director **bp, int idx, ...@@ -506,8 +507,8 @@ VRT_init_dir_simple(struct cli *cli, struct director **bp, int idx,
vs->vrt = t; vs->vrt = t;
vs->backend = VBE_AddBackend(cli, t); vs->backend = VBE_AddBackend(cli, t);
if (vs->backend->probe == NULL) if (vs->vrt->probe != NULL)
VBP_Start(vs->backend, vs->vrt->probe, vs->vrt->hosthdr); VBP_Insert(vs->backend, vs->vrt->probe, vs->vrt->hosthdr);
bp[idx] = &vs->dir; bp[idx] = &vs->dir;
} }
...@@ -145,8 +145,9 @@ void VBE_DropRefVcl(struct backend *); ...@@ -145,8 +145,9 @@ void VBE_DropRefVcl(struct backend *);
void VBE_DropRefLocked(struct backend *b); void VBE_DropRefLocked(struct backend *b);
/* cache_backend_poll.c */ /* cache_backend_poll.c */
void VBP_Start(struct backend *b, struct vrt_backend_probe const *p, const char *hosthdr); void VBP_Insert(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_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 */ /* Init functions for directors */
typedef void dir_init_f(struct cli *, struct director **, int , const void*); typedef void dir_init_f(struct cli *, struct director **, int , const void*);
......
...@@ -463,11 +463,11 @@ vbp_new_vcl(const struct vrt_backend_probe *p, const char *hosthdr) ...@@ -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 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_target *vt;
struct vbp_vcl *vcl; struct vbp_vcl *vcl;
...@@ -475,9 +475,7 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host ...@@ -475,9 +475,7 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host
unsigned u; unsigned u;
ASSERT_CLI(); ASSERT_CLI();
AN(p);
if (p == NULL)
return;
if (b->probe == NULL) { if (b->probe == NULL) {
ALLOC_OBJ(vt, VBP_TARGET_MAGIC); ALLOC_OBJ(vt, VBP_TARGET_MAGIC);
...@@ -493,21 +491,12 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host ...@@ -493,21 +491,12 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host
vt = b->probe; vt = b->probe;
} }
VTAILQ_FOREACH(vcl, &vt->vcls, list) { VTAILQ_FOREACH(vcl, &vt->vcls, list)
if (vcl->probep != p) assert (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;
}
vcl = vbp_new_vcl(p, hosthdr); vcl = vbp_new_vcl(p, hosthdr);
Lck_Lock(&vbp_mtx); Lck_Lock(&vbp_mtx);
VTAILQ_INSERT_HEAD(&vt->vcls, vcl, list); VTAILQ_INSERT_TAIL(&vt->vcls, vcl, list);
Lck_Unlock(&vbp_mtx); Lck_Unlock(&vbp_mtx);
if (startthread) { if (startthread) {
...@@ -521,21 +510,42 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host ...@@ -521,21 +510,42 @@ VBP_Start(struct backend *b, const struct vrt_backend_probe *p, const char *host
} }
void 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_target *vt;
struct vbp_vcl *vcl; struct vbp_vcl *vcl;
void *ret;
ASSERT_CLI(); 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; 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); AN(b->probe);
vt = b->probe; vt = b->probe;
VTAILQ_FOREACH(vcl, &vt->vcls, list) VTAILQ_FOREACH(vcl, &vt->vcls, list)
if (vcl->probep == p) if (vcl->probep == p)
break; break;
......
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