[master] c25ed7e Give VCL_BACKEND->healthy() a VRT_CTX and VCL_typed args
Poul-Henning Kamp
phk at FreeBSD.org
Thu Apr 26 08:31:11 UTC 2018
commit c25ed7e1e71c6743b95461909e1bc40c341cb71c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Apr 26 07:31:18 2018 +0000
Give VCL_BACKEND->healthy() a VRT_CTX and VCL_typed args
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 7ca57d5..2fb9ba8 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -153,14 +153,13 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo,
return (pfd);
}
-static unsigned v_matchproto_(vdi_healthy_f)
-vbe_dir_healthy(const struct director *d, const struct busyobj *bo,
- double *changed)
+static VCL_BOOL v_matchproto_(vdi_healthy_f)
+vbe_dir_healthy(VRT_CTX, VCL_BACKEND d, VCL_TIME *changed)
{
struct backend *be;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
- CHECK_OBJ_ORNULL(bo, BUSYOBJ_MAGIC);
CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
return (VDI_Healthy(be->director, changed));
}
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index dca50c3..145d86e 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -231,7 +231,7 @@ VRT_Healthy(VRT_CTX, VCL_BACKEND d)
return (0);
if (d->methods->healthy == NULL)
return (1);
- return (d->methods->healthy(d, ctx->bo, NULL));
+ return (d->methods->healthy(ctx, d, NULL));
}
/* Send Event ----------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index b6629bd..05f282a 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -39,9 +39,9 @@
struct vcldir;
-typedef unsigned vdi_healthy_f(const struct director *, const struct busyobj *,
- double *changed);
+typedef VCL_BOOL vdi_healthy_f(VRT_CTX, VCL_BACKEND, VCL_TIME *);
typedef VCL_BACKEND vdi_resolve_f(VRT_CTX, VCL_BACKEND);
+
typedef int vdi_gethdrs_f(const struct director *, struct worker *,
struct busyobj *);
typedef int vdi_getbody_f(const struct director *, struct worker *,
diff --git a/lib/libvmod_directors/fall_back.c b/lib/libvmod_directors/fall_back.c
index 46d1cf0..01f32fa 100644
--- a/lib/libvmod_directors/fall_back.c
+++ b/lib/libvmod_directors/fall_back.c
@@ -46,14 +46,15 @@ struct vmod_directors_fallback {
unsigned cur;
};
-static unsigned v_matchproto_(vdi_healthy)
-vmod_fallback_healthy(const struct director *dir, const struct busyobj *bo,
- double *changed)
+static VCL_BOOL v_matchproto_(vdi_healthy)
+vmod_fallback_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
{
struct vmod_directors_fallback *fb;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(fb, dir->priv, VMOD_DIRECTORS_FALLBACK_MAGIC);
- return (vdir_any_healthy(fb->vd, bo, changed));
+ return (vdir_any_healthy(ctx, fb->vd, changed));
}
static VCL_BACKEND v_matchproto_(vdi_resolve_f)
@@ -73,7 +74,7 @@ vmod_fallback_resolve(VRT_CTX, VCL_BACKEND dir)
for (u = 0; u < fb->vd->n_backend; u++) {
be = fb->vd->backend[fb->cur];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
- if (be->methods->healthy(be, ctx->bo, NULL))
+ if (be->methods->healthy(ctx, be, NULL))
break;
if (++fb->cur == fb->vd->n_backend)
fb->cur = 0;
diff --git a/lib/libvmod_directors/hash.c b/lib/libvmod_directors/hash.c
index 50d4ce9..1e4d9de 100644
--- a/lib/libvmod_directors/hash.c
+++ b/lib/libvmod_directors/hash.c
@@ -129,6 +129,6 @@ vmod_hash_backend(VRT_CTX, struct vmod_directors_hash *rr,
r = vbe32dec(sha256);
r = scalbn(r, -32);
assert(r >= 0 && r <= 1.0);
- be = vdir_pick_be(rr->vd, r, ctx->bo);
+ be = vdir_pick_be(ctx, rr->vd, r);
return (be);
}
diff --git a/lib/libvmod_directors/random.c b/lib/libvmod_directors/random.c
index cab3f7c..c89fb8e 100644
--- a/lib/libvmod_directors/random.c
+++ b/lib/libvmod_directors/random.c
@@ -46,14 +46,15 @@ struct vmod_directors_random {
struct vdir *vd;
};
-static unsigned v_matchproto_(vdi_healthy)
-vmod_random_healthy(const struct director *dir, const struct busyobj *bo,
- double *changed)
+static VCL_BOOL v_matchproto_(vdi_healthy)
+vmod_random_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
{
struct vmod_directors_random *rr;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);
- return (vdir_any_healthy(rr->vd, bo, changed));
+ return (vdir_any_healthy(ctx, rr->vd, changed));
}
static VCL_BACKEND v_matchproto_(vdi_resolve_f)
@@ -68,7 +69,7 @@ vmod_random_resolve(VRT_CTX, VCL_BACKEND dir)
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_RANDOM_MAGIC);
r = scalbn(VRND_RandomTestable(), -31);
assert(r >= 0 && r < 1.0);
- be = vdir_pick_be(rr->vd, r, ctx->bo);
+ be = vdir_pick_be(ctx, rr->vd, r);
return (be);
}
diff --git a/lib/libvmod_directors/round_robin.c b/lib/libvmod_directors/round_robin.c
index adaf0f5..3a983a7 100644
--- a/lib/libvmod_directors/round_robin.c
+++ b/lib/libvmod_directors/round_robin.c
@@ -45,14 +45,15 @@ struct vmod_directors_round_robin {
unsigned nxt;
};
-static unsigned v_matchproto_(vdi_healthy)
-vmod_rr_healthy(const struct director *dir, const struct busyobj *bo,
- double *changed)
+static VCL_BOOL v_matchproto_(vdi_healthy)
+vmod_rr_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
{
struct vmod_directors_round_robin *rr;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DIRECTORS_ROUND_ROBIN_MAGIC);
- return (vdir_any_healthy(rr->vd, bo, changed));
+ return (vdir_any_healthy(ctx, rr->vd, changed));
}
static VCL_BACKEND v_matchproto_(vdi_resolve_f)
@@ -72,7 +73,7 @@ vmod_rr_resolve(VRT_CTX, VCL_BACKEND dir)
rr->nxt = nxt + 1;
be = rr->vd->backend[nxt];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
- if (be->methods->healthy(be, ctx->bo, NULL))
+ if (be->methods->healthy(ctx, be, NULL))
break;
}
vdir_unlock(rr->vd);
diff --git a/lib/libvmod_directors/shard_dir.c b/lib/libvmod_directors/shard_dir.c
index 2594962..20cfc42 100644
--- a/lib/libvmod_directors/shard_dir.c
+++ b/lib/libvmod_directors/shard_dir.c
@@ -189,7 +189,7 @@ shard_next(struct shard_state *state, VCL_INT skip, VCL_BOOL healthy)
sbe = NULL;
be = state->shardd->backend[c].backend;
AN(be);
- if (be->methods->healthy(be, state->ctx->bo, &changed)) {
+ if (be->methods->healthy(state->ctx, be, &changed)) {
if (skip-- == 0) {
chosen = c;
sbe = &state->last;
@@ -309,9 +309,8 @@ init_state(struct shard_state *state,
* - XXX should we return the health state of the actual backend
* for healthy=IGNORE ?
*/
-unsigned
-sharddir_any_healthy(struct sharddir *shardd, const struct busyobj *bo,
- double *changed)
+VCL_BOOL
+sharddir_any_healthy(VRT_CTX, struct sharddir *shardd, VCL_TIME *changed)
{
unsigned retval = 0;
VCL_BACKEND be;
@@ -319,14 +318,13 @@ sharddir_any_healthy(struct sharddir *shardd, const struct busyobj *bo,
double c;
CHECK_OBJ_NOTNULL(shardd, SHARDDIR_MAGIC);
- CHECK_OBJ_ORNULL(bo, BUSYOBJ_MAGIC);
sharddir_rdlock(shardd);
if (changed != NULL)
*changed = 0;
for (u = 0; u < shardd->n_backend; u++) {
be = shardd->backend[u].backend;
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
- retval = be->methods->healthy(be, bo, &c);
+ retval = be->methods->healthy(ctx, be, &c);
if (changed != NULL && c > *changed)
*changed = c;
if (retval)
diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h
index f1b1b00..350437f 100644
--- a/lib/libvmod_directors/shard_dir.h
+++ b/lib/libvmod_directors/shard_dir.h
@@ -128,8 +128,7 @@ void sharddir_new(struct sharddir **sharddp, const char *vcl_name);
void sharddir_delete(struct sharddir **sharddp);
void sharddir_wrlock(struct sharddir *shardd);
void sharddir_unlock(struct sharddir *shardd);
-unsigned sharddir_any_healthy(struct sharddir *shardd, const struct busyobj *bo,
- double *changed);
+VCL_BOOL sharddir_any_healthy(VRT_CTX, struct sharddir *, VCL_TIME *);
VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *, uint32_t, VCL_INT,
VCL_REAL, VCL_BOOL, enum healthy_e);
diff --git a/lib/libvmod_directors/vdir.c b/lib/libvmod_directors/vdir.c
index f57e303..81cb8ee 100644
--- a/lib/libvmod_directors/vdir.c
+++ b/lib/libvmod_directors/vdir.c
@@ -55,7 +55,7 @@ vdir_new(VRT_CTX, struct vdir **vdp, const char *vcl_name,
{
struct vdir *vd;
- AN(ctx);
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(m, DIRECTOR_METHODS_MAGIC);
AN(vcl_name);
AN(vdp);
@@ -118,6 +118,7 @@ vdir_add_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, double weight)
{
unsigned u;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
if (be == NULL) {
VRT_fail(ctx, "NULL backend cannot be added");
@@ -140,6 +141,7 @@ vdir_remove_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, unsigned *cur)
{
unsigned u, n;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
if (be == NULL) {
VRT_fail(ctx, "NULL backend cannot be removed");
@@ -170,23 +172,23 @@ vdir_remove_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, unsigned *cur)
vdir_unlock(vd);
}
-unsigned
-vdir_any_healthy(struct vdir *vd, const struct busyobj *bo, double *changed)
+VCL_BOOL
+vdir_any_healthy(VRT_CTX, struct vdir *vd, VCL_TIME *changed)
{
unsigned retval = 0;
VCL_BACKEND be;
unsigned u;
double c;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
- CHECK_OBJ_ORNULL(bo, BUSYOBJ_MAGIC);
vdir_rdlock(vd);
if (changed != NULL)
*changed = 0;
for (u = 0; u < vd->n_backend; u++) {
be = vd->backend[u];
CHECK_OBJ_NOTNULL(be, DIRECTOR_MAGIC);
- retval = be->methods->healthy(be, bo, &c);
+ retval = be->methods->healthy(ctx, be, &c);
if (changed != NULL && c > *changed)
*changed = c;
if (retval)
@@ -218,15 +220,17 @@ vdir_pick_by_weight(const struct vdir *vd, double w,
}
VCL_BACKEND
-vdir_pick_be(struct vdir *vd, double w, const struct busyobj *bo)
+vdir_pick_be(VRT_CTX, struct vdir *vd, double w)
{
unsigned u;
double tw = 0.0;
VCL_BACKEND be = NULL;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
vdir_wrlock(vd);
for (u = 0; u < vd->n_backend; u++) {
- if (vd->backend[u]->methods->healthy(vd->backend[u], bo, NULL)) {
+ if (vd->backend[u]->methods->healthy(ctx, vd->backend[u], NULL)) {
vbit_clr(vd->vbm, u);
tw += vd->weight[u];
} else
diff --git a/lib/libvmod_directors/vdir.h b/lib/libvmod_directors/vdir.h
index 4e7d9e6..6c8331d 100644
--- a/lib/libvmod_directors/vdir.h
+++ b/lib/libvmod_directors/vdir.h
@@ -49,6 +49,5 @@ void vdir_wrlock(struct vdir *vd);
void vdir_unlock(struct vdir *vd);
void vdir_add_backend(VRT_CTX, struct vdir *, VCL_BACKEND, double weight);
void vdir_remove_backend(VRT_CTX, struct vdir *, VCL_BACKEND, unsigned *cur);
-unsigned vdir_any_healthy(struct vdir *, const struct busyobj *,
- double *changed);
-VCL_BACKEND vdir_pick_be(struct vdir *, double w, const struct busyobj *);
+VCL_BOOL vdir_any_healthy(VRT_CTX, struct vdir *, VCL_TIME *);
+VCL_BACKEND vdir_pick_be(VRT_CTX, struct vdir *, double w);
diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index 563f0a8..b546495 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -130,10 +130,7 @@ vmod_shard_param_read(VRT_CTX, const void *id,
/* -------------------------------------------------------------------------
* shard vmod interface
*/
-static unsigned v_matchproto_(vdi_healthy)
-vmod_shard_healthy(const struct director *dir, const struct busyobj *bo,
- double *changed);
-
+static vdi_healthy_f vmod_shard_healthy;
static vdi_resolve_f vmod_shard_resolve;
struct vmod_directors_shard {
@@ -680,14 +677,15 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
pp->rampup, pp->healthy));
}
-static unsigned v_matchproto_(vdi_healthy)
-vmod_shard_healthy(const struct director *dir, const struct busyobj *bo,
- double *changed)
+static VCL_BOOL v_matchproto_(vdi_healthy)
+vmod_shard_healthy(VRT_CTX, VCL_BACKEND dir, VCL_TIME *changed)
{
struct vmod_directors_shard *vshard;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(dir, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(vshard, dir->priv, VMOD_SHARD_SHARD_MAGIC);
- return (sharddir_any_healthy(vshard->shardd, bo, changed));
+ return (sharddir_any_healthy(ctx, vshard->shardd, changed));
}
static VCL_BACKEND v_matchproto_(vdi_resolve_f)
More information about the varnish-commit
mailing list