diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index 1cfd789ba36..d305a100698 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -713,7 +713,7 @@ mcf_wash_param(struct cli *cli, struct parspec *pp, enum mcf_which_e which, static struct cli_proto cli_params[] = { { CLICMD_PARAM_SHOW, "", mcf_param_show, mcf_param_show_json }, { CLICMD_PARAM_SET, "", mcf_param_set, mcf_param_set_json }, - { CLICMD_PARAM_RESET, "", mcf_param_reset }, + { CLICMD_PARAM_RESET, "", mcf_param_reset, mcf_param_set_json }, { NULL } }; diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c index 6990f1b79f0..07ad6ce303a 100644 --- a/bin/varnishd/mgt/mgt_param_tweak.c +++ b/bin/varnishd/mgt/mgt_param_tweak.c @@ -607,6 +607,13 @@ bit(uint8_t *p, unsigned no, enum bit_do act) return (*p & b); } +static inline void +bit_clear(uint8_t *p, unsigned l) +{ + + memset(p, 0, (l + 7) >> 3); +} + /*-------------------------------------------------------------------- */ @@ -627,6 +634,14 @@ bit_tweak(struct vsb *vsb, uint8_t *p, unsigned l, const char *arg, } for (i = 1; av[i] != NULL; i++) { s = av[i]; + if (sign == '+' && !strcmp(s, "none")) { + bit_clear(p, l); + continue; + } + if (sign == '-' && !strcmp(s, "all")) { + bit_clear(p, l); + continue; + } if (*s != '-' && *s != '+') { VSB_printf(vsb, "Missing '+' or '-' (%s)\n", s); VAV_Free(av); @@ -660,36 +675,26 @@ tweak_generic_bits(struct vsb *vsb, const struct parspec *par, const char *arg, uint8_t *p, unsigned l, const char * const *tags, const char *desc, char sign) { - const char *s; unsigned j; - if (arg != NULL && !strcmp(arg, "default") && - strcmp(par->def, "none")) { - memset(p, 0, l >> 3); + if (arg != NULL && !strcmp(arg, "default")) { + /* XXX: deprecated in favor of param.reset */ return (tweak_generic_bits(vsb, par, par->def, p, l, tags, desc, sign)); } - if (arg != NULL && arg != JSON_FMT) { - if (sign == '+' && !strcmp(arg, "none")) - memset(p, 0, l >> 3); - else - return (bit_tweak(vsb, p, l, arg, tags, desc, sign)); - } else { - if (arg == JSON_FMT) - VSB_putc(vsb, '"'); - s = ""; - for (j = 0; j < l; j++) { - if (bit(p, j, BTST)) { - VSB_printf(vsb, "%s%c%s", s, sign, tags[j]); - s = ","; - } - } - if (*s == '\0') - VSB_cat(vsb, sign == '+' ? "none" : "(all enabled)"); - if (arg == JSON_FMT) - VSB_putc(vsb, '"'); + if (arg != NULL && arg != JSON_FMT) + return (bit_tweak(vsb, p, l, arg, tags, desc, sign)); + + if (arg == JSON_FMT) + VSB_putc(vsb, '"'); + VSB_cat(vsb, sign == '+' ? "none" : "all"); + for (j = 0; j < l; j++) { + if (bit(p, j, BTST)) + VSB_printf(vsb, ",%c%s", sign, tags[j]); } + if (arg == JSON_FMT) + VSB_putc(vsb, '"'); return (0); } diff --git a/bin/varnishtest/tests/c00054.vtc b/bin/varnishtest/tests/c00054.vtc index 420386b89a1..0ee1c2674fc 100644 --- a/bin/varnishtest/tests/c00054.vtc +++ b/bin/varnishtest/tests/c00054.vtc @@ -1,13 +1,5 @@ varnishtest "bitmap params masking" - -server s1 { - rxreq - txresp -} -start - -varnish v1 -vcl+backend {} -start - varnish v1 -cliok "param.show vsl_mask" varnish v1 -cliok "param.set vsl_mask -VCL_trace" varnish v1 -cliok "param.show vsl_mask" @@ -15,6 +7,11 @@ varnish v1 -cliok "param.set vsl_mask -WorkThread,-TTL" varnish v1 -cliok "param.show vsl_mask" varnish v1 -cliok "param.set vsl_mask +WorkThread,+TTL,+Hash" varnish v1 -cliok "param.show vsl_mask" + +varnish v1 -cliexpect {"value": "none"} "param.set -j feature none" +varnish v1 -cliexpect {"value": "all"} "param.set -j vsl_mask all" +varnish v1 -cliexpect {"value": "all(,-\w+)+"} "param.reset -j vsl_mask" + varnish v1 -clierr 106 "param.set vsl_mask FooBar" varnish v1 -clierr 106 "param.set vsl_mask -FooBar" varnish v1 -clierr 106 {param.set vsl_mask \"} @@ -24,9 +21,3 @@ varnish v1 -cliok "param.show debug" varnish v1 -cliok "param.show feature" varnish v1 -cliok "param.set feature +short_panic" varnish v1 -cliok "param.show feature" - - -client c1 { - txreq - rxresp -} -run diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h index b4b9c3194db..3295b5844ee 100644 --- a/include/tbl/cli_cmds.h +++ b/include/tbl/cli_cmds.h @@ -172,9 +172,11 @@ CLI_CMD(VCL_LABEL, CLI_CMD(PARAM_RESET, "param.reset", - "param.reset ", + "param.reset [-j] ", "Reset parameter to default value.", - "", + " The JSON output is the same as ``param.show -j `` and" + " contains the updated value as it would be represented by a" + " subsequent execution of ``param.show``.\n\n", 1,1 ) diff --git a/include/tbl/params.h b/include/tbl/params.h index 073e5be3b38..c88809da709 100644 --- a/include/tbl/params.h +++ b/include/tbl/params.h @@ -1829,11 +1829,12 @@ PARAM_BITS( /* name */ feature, /* fld */ feature_bits, /* def */ + "none," "+validate_headers," "+vcl_req_reset", /* descr */ "Enable/Disable various minor features.\n" - "\tdefault\tSet default value\n" + "\tdefault\tSet default value (deprecated: use param.reset)\n" "\tnone\tDisable all features.\n\n" "Use +/- prefix to enable/disable individual feature:") #ifdef PARAM_ALL @@ -1847,11 +1848,12 @@ PARAM_BITS( /* name */ vcc_feature, /* fld */ vcc_feature_bits, /* def */ + "none," "+err_unref," "+unsafe_path", /* descr */ "Enable/Disable various VCC behaviors.\n" - "\tdefault\tSet default value\n" + "\tdefault\tSet default value (deprecated: use param.reset)\n" "\tnone\tDisable all behaviors.\n\n" "Use +/- prefix to enable/disable individual behavior:") #ifdef PARAM_ALL @@ -1865,6 +1867,7 @@ PARAM_BITS( /* name */ vsl_mask, /* fld */ vsl_mask, /* def */ + "all," "-Debug," "-ExpKill," "-H2RxBody," @@ -1881,7 +1884,8 @@ PARAM_BITS( "-WorkThread", /* descr */ "Mask individual VSL messages from being logged.\n" - "\tdefault\tSet default value\n" + "\tall\tEnable all tags\n" + "\tdefault\tSet default value (deprecated: use param.reset)\n" "\nUse +/- prefix in front of VSL tag name to unmask/mask " "individual VSL messages.") PARAM_POST