From b37a863cb2d09ad0736334bd6606c05b802c85cf Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Sat, 4 Apr 2020 18:16:14 +0200 Subject: devlink: remove custom bool command line options parsing Change the code that is doing custom processing of boolean command line options to use dl_argv_bool(). Extend strtobool() to accept "enable"/"disable" to maintain current behavior. Signed-off-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- devlink/devlink.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'devlink/devlink.c') diff --git a/devlink/devlink.c b/devlink/devlink.c index 6405d4be..ce6e349e 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -739,9 +739,11 @@ static int strtobool(const char *str, bool *p_val) { bool val; - if (!strcmp(str, "true") || !strcmp(str, "1")) + if (!strcmp(str, "true") || !strcmp(str, "1") || + !strcmp(str, "enable")) val = true; - else if (!strcmp(str, "false") || !strcmp(str, "0")) + else if (!strcmp(str, "false") || !strcmp(str, "0") || + !strcmp(str, "disable")) val = false; else return -EINVAL; @@ -1076,20 +1078,6 @@ static int eswitch_inline_mode_get(const char *typestr, return 0; } -static int dpipe_counters_enable_get(const char *typestr, - bool *counters_enable) -{ - if (strcmp(typestr, "enable") == 0) { - *counters_enable = 1; - } else if (strcmp(typestr, "disable") == 0) { - *counters_enable = 0; - } else { - pr_err("Unknown counter_state \"%s\"\n", typestr); - return -EINVAL; - } - return 0; -} - static int eswitch_encap_mode_get(const char *typestr, bool *p_mode) { if (strcmp(typestr, "enable") == 0) { @@ -1336,14 +1324,8 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, o_found |= DL_OPT_DPIPE_TABLE_NAME; } else if (dl_argv_match(dl, "counters") && (o_all & DL_OPT_DPIPE_TABLE_COUNTERS)) { - const char *typestr; - dl_arg_inc(dl); - err = dl_argv_str(dl, &typestr); - if (err) - return err; - err = dpipe_counters_enable_get(typestr, - &opts->dpipe_counters_enable); + err = dl_argv_bool(dl, &opts->dpipe_counters_enable); if (err) return err; o_found |= DL_OPT_DPIPE_TABLE_COUNTERS; -- cgit v1.2.3 From 90ce848b05fc1883ddafcf57af4c7fcbafd85833 Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Sat, 4 Apr 2020 18:16:15 +0200 Subject: devlink: Fix help and man of "devlink health set" command Fix the help and man page of "devlink health set" command to be aligned with the rest of helps and man pages. Signed-off-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- devlink/devlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'devlink/devlink.c') diff --git a/devlink/devlink.c b/devlink/devlink.c index ce6e349e..6a410810 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -6924,7 +6924,9 @@ static void cmd_health_help(void) pr_err(" devlink health diagnose DEV reporter REPORTER_NAME\n"); pr_err(" devlink health dump show DEV reporter REPORTER_NAME\n"); pr_err(" devlink health dump clear DEV reporter REPORTER_NAME\n"); - pr_err(" devlink health set DEV reporter REPORTER_NAME { grace_period | auto_recover } { msec | boolean }\n"); + pr_err(" devlink health set DEV reporter REPORTER_NAME\n"); + pr_err(" [ grace_period MSEC ]\n"); + pr_err(" [ auto_recover { true | false } ]\n"); } static int cmd_health(struct dl *dl) -- cgit v1.2.3 From 0b1875cdc69f49184445781a62e0bf603bdfc414 Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Sat, 4 Apr 2020 18:16:16 +0200 Subject: devlink: fix encap mode manupulation DEVLINK_ATTR_ESWITCH_ENCAP_MODE netlink attribute carries enum. But the code assumes bool value. Fix this by treating the encap mode in the same way as other eswitch mode attributes, switching from "enable"/"disable" to "basic"/"none", according to the enum. Maintain the backward compatibility to allow user to pass "enable"/"disable" too. Also to be in-sync with the rest of the "mode" commands, rename to "encap-mode". Adjust the help and man page accordingly. Signed-off-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- devlink/devlink.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'devlink/devlink.c') diff --git a/devlink/devlink.c b/devlink/devlink.c index 6a410810..6a24f28f 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -41,6 +41,9 @@ #define ESWITCH_INLINE_MODE_NETWORK "network" #define ESWITCH_INLINE_MODE_TRANSPORT "transport" +#define ESWITCH_ENCAP_MODE_NONE "none" +#define ESWITCH_ENCAP_MODE_BASIC "basic" + #define PARAM_CMODE_RUNTIME_STR "runtime" #define PARAM_CMODE_DRIVERINIT_STR "driverinit" #define PARAM_CMODE_PERMANENT_STR "permanent" @@ -284,7 +287,7 @@ struct dl_opts { enum devlink_eswitch_inline_mode eswitch_inline_mode; const char *dpipe_table_name; bool dpipe_counters_enable; - bool eswitch_encap_mode; + enum devlink_eswitch_encap_mode eswitch_encap_mode; const char *resource_path; uint64_t resource_size; uint32_t resource_id; @@ -1078,12 +1081,19 @@ static int eswitch_inline_mode_get(const char *typestr, return 0; } -static int eswitch_encap_mode_get(const char *typestr, bool *p_mode) +static int +eswitch_encap_mode_get(const char *typestr, + enum devlink_eswitch_encap_mode *p_encap_mode) { - if (strcmp(typestr, "enable") == 0) { - *p_mode = true; - } else if (strcmp(typestr, "disable") == 0) { - *p_mode = false; + /* The initial implementation incorrectly accepted "enable"/"disable". + * Carry it to maintain backward compatibility. + */ + if (strcmp(typestr, "disable") == 0 || + strcmp(typestr, ESWITCH_ENCAP_MODE_NONE) == 0) { + *p_encap_mode = DEVLINK_ESWITCH_ENCAP_MODE_NONE; + } else if (strcmp(typestr, "enable") == 0 || + strcmp(typestr, ESWITCH_ENCAP_MODE_BASIC) == 0) { + *p_encap_mode = DEVLINK_ESWITCH_ENCAP_MODE_BASIC; } else { pr_err("Unknown eswitch encap mode \"%s\"\n", typestr); return -EINVAL; @@ -1329,7 +1339,8 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, if (err) return err; o_found |= DL_OPT_DPIPE_TABLE_COUNTERS; - } else if (dl_argv_match(dl, "encap") && + } else if ((dl_argv_match(dl, "encap") || /* Original incorrect implementation */ + dl_argv_match(dl, "encap-mode")) && (o_all & DL_OPT_ESWITCH_ENCAP_MODE)) { const char *typestr; @@ -1700,7 +1711,7 @@ static void cmd_dev_help(void) pr_err("Usage: devlink dev show [ DEV ]\n"); pr_err(" devlink dev eswitch set DEV [ mode { legacy | switchdev } ]\n"); pr_err(" [ inline-mode { none | link | network | transport } ]\n"); - pr_err(" [ encap { disable | enable } ]\n"); + pr_err(" [ encap-mode { none | basic } ]\n"); pr_err(" devlink dev eswitch show DEV\n"); pr_err(" devlink dev param set DEV name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n"); pr_err(" devlink dev param show [DEV name PARAMETER]\n"); @@ -2130,6 +2141,18 @@ static const char *eswitch_inline_mode_name(uint32_t mode) } } +static const char *eswitch_encap_mode_name(uint32_t mode) +{ + switch (mode) { + case DEVLINK_ESWITCH_ENCAP_MODE_NONE: + return ESWITCH_ENCAP_MODE_NONE; + case DEVLINK_ESWITCH_ENCAP_MODE_BASIC: + return ESWITCH_ENCAP_MODE_BASIC; + default: + return ""; + } +} + static void pr_out_eswitch(struct dl *dl, struct nlattr **tb) { __pr_out_handle_start(dl, tb, true, false); @@ -2147,11 +2170,10 @@ static void pr_out_eswitch(struct dl *dl, struct nlattr **tb) tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE]))); } if (tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]) { - bool encap_mode = !!mnl_attr_get_u8(tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]); - check_indent_newline(dl); - print_string(PRINT_ANY, "encap", "encap %s", - encap_mode ? "enable" : "disable"); + print_string(PRINT_ANY, "encap-mode", "encap-mode %s", + eswitch_encap_mode_name(mnl_attr_get_u8( + tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]))); } pr_out_handle_end(dl); -- cgit v1.2.3 From 192e7b3ffa1de43dc65b95b8c19a1e73baa251ff Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Sat, 4 Apr 2020 18:16:17 +0200 Subject: devlink: Add alias "counters_enabled" for "counters" option To be consistent with netlink attribute name and also with the "dpipe table show" output, add "counters_enabled" for "counters" in "dpipe table set" command. Signed-off-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- devlink/devlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'devlink/devlink.c') diff --git a/devlink/devlink.c b/devlink/devlink.c index 6a24f28f..476f8df6 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -1332,7 +1332,8 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, if (err) return err; o_found |= DL_OPT_DPIPE_TABLE_NAME; - } else if (dl_argv_match(dl, "counters") && + } else if ((dl_argv_match(dl, "counters") || + dl_argv_match(dl, "counters_enabled")) && (o_all & DL_OPT_DPIPE_TABLE_COUNTERS)) { dl_arg_inc(dl); err = dl_argv_bool(dl, &opts->dpipe_counters_enable); -- cgit v1.2.3 From 342f462efa9f51966c4e92ad5d3e487680ba16d4 Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Sat, 4 Apr 2020 18:16:18 +0200 Subject: devlink: rename dpipe_counters_enable struct field to dpipe_counters_enabled To be consistent with the rest of the code and name of netlink attribute, rename the dpipe_counters_enable struct fielt to dpipe_counters_enabled. Signed-off-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- devlink/devlink.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'devlink/devlink.c') diff --git a/devlink/devlink.c b/devlink/devlink.c index 476f8df6..02339ec0 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -286,7 +286,7 @@ struct dl_opts { enum devlink_eswitch_mode eswitch_mode; enum devlink_eswitch_inline_mode eswitch_inline_mode; const char *dpipe_table_name; - bool dpipe_counters_enable; + bool dpipe_counters_enabled; enum devlink_eswitch_encap_mode eswitch_encap_mode; const char *resource_path; uint64_t resource_size; @@ -1336,7 +1336,7 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, dl_argv_match(dl, "counters_enabled")) && (o_all & DL_OPT_DPIPE_TABLE_COUNTERS)) { dl_arg_inc(dl); - err = dl_argv_bool(dl, &opts->dpipe_counters_enable); + err = dl_argv_bool(dl, &opts->dpipe_counters_enabled); if (err) return err; o_found |= DL_OPT_DPIPE_TABLE_COUNTERS; @@ -1592,7 +1592,7 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) opts->dpipe_table_name); if (opts->present & DL_OPT_DPIPE_TABLE_COUNTERS) mnl_attr_put_u8(nlh, DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED, - opts->dpipe_counters_enable); + opts->dpipe_counters_enabled); if (opts->present & DL_OPT_ESWITCH_ENCAP_MODE) mnl_attr_put_u8(nlh, DEVLINK_ATTR_ESWITCH_ENCAP_MODE, opts->eswitch_encap_mode); -- cgit v1.2.3 From b2522187d85fcf75533bb123c9574df282286db6 Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Sat, 4 Apr 2020 18:16:19 +0200 Subject: devlink: Fix help message for dpipe Have one help message for all dpipe commands, as it is done for the rest of the devlink object. Possible and required options to the help. Signed-off-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- devlink/devlink.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'devlink/devlink.c') diff --git a/devlink/devlink.c b/devlink/devlink.c index 02339ec0..2df7ad47 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -4976,15 +4976,19 @@ static int cmd_dpipe_headers_show(struct dl *dl) return err; } -static void cmd_dpipe_header_help(void) +static void cmd_dpipe_help(void) { - pr_err("Usage: devlink dpipe headers show DEV\n"); + pr_err("Usage: devlink dpipe table show DEV [ name TABLE_NAME ]\n"); + pr_err(" devlink dpipe table set DEV name TABLE_NAME\n"); + pr_err(" [ counters_enabled { true | false } ]\n"); + pr_err(" devlink dpipe table dump DEV name TABLE_NAME\n"); + pr_err(" devlink dpipe header show DEV\n"); } static int cmd_dpipe_header(struct dl *dl) { if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { - cmd_dpipe_header_help(); + cmd_dpipe_help(); return 0; } else if (dl_argv_match(dl, "show")) { dl_arg_inc(dl); @@ -5800,16 +5804,10 @@ out: return err; } -static void cmd_dpipe_table_help(void) -{ - pr_err("Usage: devlink dpipe table [ OBJECT-LIST ]\n" - "where OBJECT-LIST := { show | set | dump }\n"); -} - static int cmd_dpipe_table(struct dl *dl) { if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { - cmd_dpipe_table_help(); + cmd_dpipe_help(); return 0; } else if (dl_argv_match(dl, "show")) { dl_arg_inc(dl); @@ -5825,12 +5823,6 @@ static int cmd_dpipe_table(struct dl *dl) return -ENOENT; } -static void cmd_dpipe_help(void) -{ - pr_err("Usage: devlink dpipe [ OBJECT-LIST ]\n" - "where OBJECT-LIST := { header | table }\n"); -} - static int cmd_dpipe(struct dl *dl) { if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { -- cgit v1.2.3 From 885f4b0d7ad6edcb2c99034abe69c916973185f9 Mon Sep 17 00:00:00 2001 From: Jiri Pirko Date: Sat, 4 Apr 2020 18:16:20 +0200 Subject: devlink: remove "dev" object sub help messages Remove duplicate sub help messages for "dev" object and have them all show help message for "dev". Signed-off-by: Jiri Pirko Signed-off-by: Stephen Hemminger --- devlink/devlink.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'devlink/devlink.c') diff --git a/devlink/devlink.c b/devlink/devlink.c index 2df7ad47..51be0efa 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -2765,18 +2765,13 @@ static int cmd_dev_show(struct dl *dl) return err; } -static void cmd_dev_reload_help(void) -{ - pr_err("Usage: devlink dev reload DEV [ netns { PID | NAME | ID } ]\n"); -} - static int cmd_dev_reload(struct dl *dl) { struct nlmsghdr *nlh; int err; if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { - cmd_dev_reload_help(); + cmd_dev_help(); return 0; } @@ -2898,11 +2893,6 @@ static int cmd_versions_show_cb(const struct nlmsghdr *nlh, void *data) return MNL_CB_OK; } -static void cmd_dev_info_help(void) -{ - pr_err("Usage: devlink dev info [ DEV ]\n"); -} - static int cmd_dev_info(struct dl *dl) { struct nlmsghdr *nlh; @@ -2910,7 +2900,7 @@ static int cmd_dev_info(struct dl *dl) int err; if (dl_argv_match(dl, "help")) { - cmd_dev_info_help(); + cmd_dev_help(); return 0; } @@ -2931,12 +2921,6 @@ static int cmd_dev_info(struct dl *dl) return err; } -static void cmd_dev_flash_help(void) -{ - pr_err("Usage: devlink dev flash DEV file PATH [ component NAME ]\n"); -} - - struct cmd_dev_flash_status_ctx { struct dl *dl; char *last_msg; @@ -3084,7 +3068,7 @@ static int cmd_dev_flash(struct dl *dl) int err; if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { - cmd_dev_flash_help(); + cmd_dev_help(); return 0; } -- cgit v1.2.3