[master] d00de5d7c Also eliminat C-enum detour for 'healthy' arguments
Poul-Henning Kamp
phk at FreeBSD.org
Wed Aug 7 08:23:11 UTC 2019
commit d00de5d7ca7e8aa8653de26e77bc4c9f66cec759
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Aug 7 08:22:27 2019 +0000
Also eliminat C-enum detour for 'healthy' arguments
diff --git a/lib/libvmod_directors/Makefile.am b/lib/libvmod_directors/Makefile.am
index 73fccf7d5..646357100 100644
--- a/lib/libvmod_directors/Makefile.am
+++ b/lib/libvmod_directors/Makefile.am
@@ -12,8 +12,7 @@ libvmod_directors_la_SOURCES = \
shard_cfg.c \
shard_cfg.h \
shard_dir.c \
- shard_dir.h \
- tbl_healthy.h
+ shard_dir.h
# Use vmodtool.py generated automake boilerplate
include $(srcdir)/automake_boilerplate.am
diff --git a/lib/libvmod_directors/shard_dir.c b/lib/libvmod_directors/shard_dir.c
index 4c707dc5e..db2c5be78 100644
--- a/lib/libvmod_directors/shard_dir.c
+++ b/lib/libvmod_directors/shard_dir.c
@@ -43,6 +43,7 @@
#include "vsha256.h"
#include "vend.h"
+#include "vcc_if.h"
#include "shard_dir.h"
struct shard_be_info {
@@ -323,7 +324,7 @@ sharddir_any_healthy(VRT_CTX, struct sharddir *shardd, VCL_TIME *changed)
static VCL_BACKEND
sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
- VCL_INT alt, VCL_REAL warmup, VCL_BOOL rampup, enum healthy_e healthy,
+ VCL_INT alt, VCL_REAL warmup, VCL_BOOL rampup, VCL_ENUM healthy,
struct shard_state *state)
{
VCL_BACKEND be;
@@ -345,7 +346,8 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
key, state->idx, shardd->hashcircle[state->idx].host);
if (alt > 0) {
- if (shard_next(state, alt - 1, healthy == ALL ? 1 : 0) == -1) {
+ if (shard_next(state, alt - 1,
+ healthy == VENUM(ALL) ? 1 : 0) == -1) {
if (state->previous.hostid != -1) {
be = sharddir_backend(shardd,
state->previous.hostid);
@@ -356,7 +358,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
}
}
- if (shard_next(state, 0, healthy == IGNORE ? 0 : 1) == -1) {
+ if (shard_next(state, 0, healthy == VENUM(IGNORE) ? 0 : 1) == -1) {
if (state->previous.hostid != -1) {
be = sharddir_backend(shardd, state->previous.hostid);
AN(be);
@@ -372,7 +374,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
warmup = shardd->warmup;
/* short path for cases we dont want ramup/warmup or can't */
- if (alt > 0 || healthy == IGNORE || (!rampup && warmup == 0) ||
+ if (alt > 0 || healthy == VENUM(IGNORE) || (!rampup && warmup == 0) ||
shard_next(state, 0, 1) == -1)
return (be);
@@ -415,7 +417,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key,
VCL_BACKEND
sharddir_pick_be(VRT_CTX, struct sharddir *shardd, uint32_t key, VCL_INT alt,
- VCL_REAL warmup, VCL_BOOL rampup, enum healthy_e healthy)
+ VCL_REAL warmup, VCL_BOOL rampup, VCL_ENUM healthy)
{
VCL_BACKEND be;
struct shard_state state[1];
diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h
index d67b6a7bf..6d70a7603 100644
--- a/lib/libvmod_directors/shard_dir.h
+++ b/lib/libvmod_directors/shard_dir.h
@@ -27,13 +27,6 @@
* SUCH DAMAGE.
*/
-enum healthy_e {
- _HEALTHY_E_INVALID = 0,
-#define VMODENUM(x) x,
-#include "tbl_healthy.h"
- _HEALTHY_E_MAX
-};
-
struct vbitmap;
struct shard_circlepoint {
@@ -116,7 +109,7 @@ void sharddir_wrlock(struct sharddir *shardd);
void sharddir_unlock(struct sharddir *shardd);
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);
+ VCL_REAL, VCL_BOOL, VCL_ENUM healthy);
/* in shard_cfg.c */
void shardcfg_delete(const struct sharddir *shardd);
diff --git a/lib/libvmod_directors/tbl_healthy.h b/lib/libvmod_directors/tbl_healthy.h
deleted file mode 100644
index 7be0e44a7..000000000
--- a/lib/libvmod_directors/tbl_healthy.h
+++ /dev/null
@@ -1,4 +0,0 @@
-VMODENUM(CHOSEN)
-VMODENUM(IGNORE)
-VMODENUM(ALL)
-#undef VMODENUM
diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index 906214551..a5e07e14e 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -128,7 +128,7 @@ struct vmod_directors_shard_param {
/* parameters */
VCL_ENUM by;
- enum healthy_e healthy;
+ VCL_ENUM healthy;
uint32_t mask;
VCL_BOOL rampup;
VCL_INT alt;
@@ -144,13 +144,13 @@ static const struct vmod_directors_shard_param shard_param_default = {
.scope = SCOPE_VMOD,
.mask = arg_mask_param_,
- .healthy = CHOSEN,
.rampup = 1,
.alt = 0,
.warmup = -1,
};
#define default_by(ptr) (ptr == NULL ? VENUM(HASH) : ptr)
+#define default_healthy(ptr) (ptr == NULL ? VENUM(CHOSEN) : ptr)
static struct vmod_directors_shard_param *
shard_param_stack(struct vmod_directors_shard_param *p,
@@ -182,20 +182,6 @@ struct vmod_directors_shard {
VCL_BACKEND dir;
};
-static enum healthy_e
-parse_healthy_e(VCL_ENUM e)
-{
-#define VMODENUM(n) if (e == VENUM(n)) return(n);
-#include "tbl_healthy.h"
- WRONG("illegal healthy enum");
-}
-
-static const char * const healthy_str[_HEALTHY_E_MAX] = {
- [_HEALTHY_E_INVALID] = "*INVALID*",
-#define VMODENUM(n) [n] = #n,
-#include "tbl_healthy.h"
-};
-
static void
shard__assert(void)
{
@@ -504,7 +490,6 @@ shard_param_args(VRT_CTX,
uint32_t args, VCL_ENUM by_s, VCL_INT key_int, VCL_BLOB key_blob,
VCL_INT alt, VCL_REAL warmup, VCL_BOOL rampup, VCL_ENUM healthy_s)
{
- enum healthy_e healthy;
CHECK_OBJ_NOTNULL(p, VMOD_SHARD_SHARD_PARAM_MAGIC);
AN(p->vcl_name);
@@ -514,7 +499,6 @@ shard_param_args(VRT_CTX,
if (!(args & arg_by))
by_s = NULL;
by_s = default_by(by_s);
- healthy = (args & arg_healthy) ? parse_healthy_e(healthy_s) : CHOSEN;
/* by_s / key_int / key_blob */
if (by_s == VENUM(KEY)) {
@@ -587,7 +571,7 @@ shard_param_args(VRT_CTX,
p->rampup = !!rampup;
if (args & arg_healthy)
- p->healthy = healthy;
+ p->healthy = healthy_s;
p->mask = args & arg_mask_param_;
return (p);
@@ -1063,9 +1047,7 @@ vmod_shard_param_get_healthy(VRT_CTX,
"shard_param.get_healthy()");
if (pp == NULL)
return (NULL);
- assert(pp->healthy > _HEALTHY_E_INVALID);
- return (healthy_str[pp->healthy]);
-
+ return (default_healthy(pp->healthy));
}
static const struct vmod_directors_shard_param *
More information about the varnish-commit
mailing list