[master] 9a85dfd Clean up the code to configure parameter min/max/default values.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Apr 4 22:59:04 CEST 2016
commit 9a85dfdf327f0528dd67e9c4d2c2397a46eff92b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Apr 4 20:58:08 2016 +0000
Clean up the code to configure parameter min/max/default values.
diff --git a/bin/varnishd/cache/cache_ban_build.c b/bin/varnishd/cache/cache_ban_build.c
index 55c78ae..8401707 100644
--- a/bin/varnishd/cache/cache_ban_build.c
+++ b/bin/varnishd/cache/cache_ban_build.c
@@ -130,7 +130,7 @@ ban_error(struct ban_proto *bp, const char *fmt, ...)
/* Record the error message in the vsb */
VSB_clear(bp->vsb);
va_start(ap, fmt);
- (void)VSB_vprintf(bp->vsb, fmt, ap);
+ VSB_vprintf(bp->vsb, fmt, ap);
va_end(ap);
AZ(VSB_finish(bp->vsb));
bp->err = VSB_data(bp->vsb);
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 3cd8ddd..d174206 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -133,9 +133,14 @@ void MGT_complain(const char *loud, const char *, ...) __v_printflike(2, 3);
/* mgt_param.c */
void MCF_InitParams(struct cli *);
void MCF_CollectParams(void);
-void MCF_SetDefault(const char *param, const char *def);
-void MCF_SetMinimum(const char *param, const char *def);
-void MCF_SetMaximum(const char *param, const char *def);
+enum mcf_which_e {
+ MCF_DEFAULT = 32,
+ MCF_MINIMUM = 33,
+ MCF_MAXIMUM = 34,
+};
+void MCF_ParamConf(enum mcf_which_e, const char *param, const char *, ...)
+ __v_printflike(3, 4);
+
void MCF_ParamSet(struct cli *, const char *param, const char *val);
void MCF_ParamProtect(struct cli *, const char *arg);
void MCF_DumpRstParam(void);
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 2dc452a..267fee7 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -425,9 +425,6 @@ make_secret(const char *dirname)
/*--------------------------------------------------------------------*/
-static char stackmin[20];
-static char stackdef[20];
-
static void
init_params(struct cli *cli)
{
@@ -442,26 +439,24 @@ init_params(struct cli *cli)
* Adjust default parameters for 32 bit systems to conserve
* VM space.
*/
- MCF_SetDefault("workspace_client", "24k");
- MCF_SetDefault("workspace_backend", "16k");
- MCF_SetDefault("http_resp_size", "8k");
- MCF_SetDefault("http_req_size", "12k");
- MCF_SetDefault("gzip_buffer", "4k");
+ MCF_ParamConf(MCF_DEFAULT, "workspace_client", "24k");
+ MCF_ParamConf(MCF_DEFAULT, "workspace_backend", "16k");
+ MCF_ParamConf(MCF_DEFAULT, "http_resp_size", "8k");
+ MCF_ParamConf(MCF_DEFAULT, "http_req_size", "12k");
+ MCF_ParamConf(MCF_DEFAULT, "gzip_buffer", "4k");
}
#if !defined(HAVE_ACCEPT_FILTERS) || defined(__linux)
- MCF_SetDefault("accept_filter", "off");
+ MCF_ParamConf(MCF_DEFAULT, "accept_filter", "off");
#endif
low = sysconf(_SC_THREAD_STACK_MIN);
- bprintf(stackmin, "%jd", (intmax_t)low);
- MCF_SetMinimum("thread_pool_stack", stackmin);
+ MCF_ParamConf(MCF_MINIMUM, "thread_pool_stack", "%jd", (intmax_t)low);
def = 48 * 1024;
if (def < low)
def = low;
- bprintf(stackdef, "%jd", (intmax_t)def);
- MCF_SetDefault("thread_pool_stack", stackdef);
+ MCF_ParamConf(MCF_DEFAULT, "thread_pool_stack", "%jd", (intmax_t)def);
MCF_InitParams(cli);
}
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 71f9751..44c64d7 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -30,6 +30,7 @@
#include "config.h"
#include <ctype.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -483,38 +484,35 @@ MCF_CollectParams(void)
/*--------------------------------------------------------------------*/
void
-MCF_SetDefault(const char *param, const char *new_def)
-{
- struct parspec *pp;
-
- pp = mcf_findpar(param);
- AN(pp);
- pp->def = new_def;
- AN(pp->def);
-}
-
-void
-MCF_SetMinimum(const char *param, const char *new_min)
-{
- struct parspec *pp;
-
- AN(new_min);
- pp = mcf_findpar(param);
- AN(pp);
- pp->min = new_min;
- AN(pp->min);
-}
-
-void
-MCF_SetMaximum(const char *param, const char *new_max)
+MCF_ParamConf(enum mcf_which_e which, const char *param, const char *fmt, ...)
{
struct parspec *pp;
+ struct vsb *vsb;
+ va_list ap;
- AN(new_max);
pp = mcf_findpar(param);
AN(pp);
- pp->max = new_max;
- AN(pp->max);
+ vsb = VSB_new_auto();
+ AN(vsb);
+ va_start(ap, fmt);
+ VSB_vprintf(vsb, fmt, ap);
+ va_end(ap);
+ AZ(VSB_finish(vsb));
+ switch (which) {
+ case MCF_DEFAULT:
+ pp->def = strdup(VSB_data(vsb));
+ AN(pp->def);
+ break;
+ case MCF_MINIMUM:
+ pp->min = strdup(VSB_data(vsb));
+ AN(pp->min);
+ break;
+ case MCF_MAXIMUM:
+ pp->max = strdup(VSB_data(vsb));
+ AN(pp->max);
+ break;
+ }
+ VSB_delete(vsb);
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/mgt/mgt_param_tcp.c b/bin/varnishd/mgt/mgt_param_tcp.c
index ab8f6d4..6d40097 100644
--- a/bin/varnishd/mgt/mgt_param_tcp.c
+++ b/bin/varnishd/mgt/mgt_param_tcp.c
@@ -79,17 +79,12 @@ tcp_probe(int sock, int nam, const char *param, unsigned def)
int i;
socklen_t l;
unsigned u;
- char buf[10];
- const char *p;
l = sizeof u;
i = getsockopt(sock, IPPROTO_TCP, nam, &u, &l);
if (i < 0 || u == 0)
u = def;
- bprintf(buf, "%u", u);
- p = strdup(buf);
- AN(p);
- MCF_SetDefault(param, p);
+ MCF_ParamConf(MCF_DEFAULT, param, "%u", u);
}
static void
diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c
index 00ad35c..d58e032 100644
--- a/bin/varnishd/mgt/mgt_param_tweak.c
+++ b/bin/varnishd/mgt/mgt_param_tweak.c
@@ -329,16 +329,14 @@ tweak_vsl_buffer(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile unsigned *d1;
volatile ssize_t dest;
- char buf[20];
d1 = par->priv;
dest = *d1;
if (tweak_generic_bytes(vsb, &dest, arg, par->min, par->max))
return (-1);
*d1 = dest;
- bprintf(buf, "%u", *d1 - 12);
- MCF_SetMaximum("vsl_reclen", strdup(buf));
- MCF_SetMaximum("shm_reclen", strdup(buf));
+ MCF_ParamConf(MCF_MAXIMUM, "vsl_reclen", "%u", *d1 - 12);
+ MCF_ParamConf(MCF_MAXIMUM, "shm_reclen", "%u", *d1 - 12);
return (0);
}
@@ -347,15 +345,13 @@ tweak_vsl_reclen(struct vsb *vsb, const struct parspec *par, const char *arg)
{
volatile unsigned *d1;
volatile ssize_t dest;
- char buf[20];
d1 = par->priv;
dest = *d1;
if (tweak_generic_bytes(vsb, &dest, arg, par->min, par->max))
return (-1);
*d1 = dest;
- bprintf(buf, "%u", *d1 + 12);
- MCF_SetMinimum("vsl_buffer", strdup(buf));
+ MCF_ParamConf(MCF_MINIMUM, "vsl_buffer", "%u", *d1 + 12);
return (0);
}
diff --git a/bin/varnishd/mgt/mgt_pool.c b/bin/varnishd/mgt/mgt_pool.c
index d14a32f..398e468 100644
--- a/bin/varnishd/mgt/mgt_pool.c
+++ b/bin/varnishd/mgt/mgt_pool.c
@@ -53,21 +53,15 @@
* limit, so they don't end up crossing.
*/
-static char min_val[20];
-static char max_val[20];
-
static int
tweak_thread_pool_min(struct vsb *vsb, const struct parspec *par,
const char *arg)
{
- struct vsb v2;
if (tweak_generic_uint(vsb, par->priv, arg, par->min, par->max))
return (-1);
- AN(VSB_new(&v2, min_val, sizeof min_val, 0));
- AZ(tweak_generic_uint(&v2, &mgt_param.wthread_min, NULL, NULL, NULL));
- AZ(VSB_finish(&v2));
- MCF_SetMinimum("thread_pool_max", min_val);
+ MCF_ParamConf(MCF_MINIMUM, "thread_pool_max",
+ "%u", mgt_param.wthread_min);
return (0);
}
@@ -75,14 +69,11 @@ static int
tweak_thread_pool_max(struct vsb *vsb, const struct parspec *par,
const char *arg)
{
- struct vsb v2;
if (tweak_generic_uint(vsb, par->priv, arg, par->min, par->max))
return (-1);
- AN(VSB_new(&v2, max_val, sizeof max_val, 0));
- AZ(tweak_generic_uint(&v2, &mgt_param.wthread_max, NULL, NULL, NULL));
- AZ(VSB_finish(&v2));
- MCF_SetMaximum("thread_pool_min", max_val);
+ MCF_ParamConf(MCF_MAXIMUM, "thread_pool_min",
+ "%u", mgt_param.wthread_max);
return (0);
}
More information about the varnish-commit
mailing list