devlink: implement dump selector for devlink objects show commands
Subsystems (3)
v2 cover devlink: implement dump selector for devlink objects show commands
From: Jiri Pirko <[email protected]>
First 5 patches are preparations for the last one.
Motivation:
For SFs, one devlink instance per SF is created. There might be thousands of these on a single host. When a user needs to know port handle for specific SF, he needs to dump all devlink ports on the host which does not scale good.
Solution:
Allow user to pass devlink handle (and possibly other attributes) alongside the dump command and dump only objects which are matching the selection.
Example:
$ devlink port show auxiliary/mlx5_core.eth.0/65535: type eth netdev eth2 flavour physical port 0 splittable false auxiliary/mlx5_core.eth.1/131071: type eth netdev eth3 flavour physical port 1 splittable false
$ devlink port show auxiliary/mlx5_core.eth.0 auxiliary/mlx5_core.eth.0/65535: type eth netdev eth2 flavour physical port 0 splittable false
$ devlink port show auxiliary/mlx5_core.eth.1 auxiliary/mlx5_core.eth.1/131071: type eth netdev eth3 flavour physical port 1 splittable false
Jiri Pirko (6):
devlink: move DL_OPT_SB into required options
devlink: make parsing of handle non-destructive to argv
devlink: implement command line args dry parsing
devlink: return -ENOENT if argument is missing
mnl_utils: introduce a helper to check if dump policy exists for
command
devlink: implement dump selector for devlink objects show commands
devlink/devlink.c | 382 ++++++++++++++++++++++++++------------------ include/mnl_utils.h | 1 + lib/mnl_utils.c | 121 +++++++++++++- 3 files changed, 345 insertions(+), 159 deletions(-)
Signature · 1 line
2.41.0
PATCH v2 1/6 devlink: move DL_OPT_SB into required options
From: Jiri Pirko <[email protected]>
This is basically a cosmetic change. The SB index is not required to be passed by user and implicitly index 0 is used. This is ensured by special treating at the end of dl_argv_parse(). Move this option from optional to required options.
---v1->v2:
- fixed o_found bit set
--- devlink/devlink.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-)
devlink/devlink.c +20 -21
@@ -2269,13 +2269,13 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, } } - opts->present = o_found; - -if ((o_optional &DL_OPT_SB ) && !(o_found &DL_OPT_SB )) { +if ((o_required &DL_OPT_SB ) && !(o_found &DL_OPT_SB )) { opts->sb_index =0 ; - opts->present |=DL_OPT_SB ; + o_found |=DL_OPT_SB ; } + opts->present = o_found; +return dl_args_finding_required_validate (o_required, o_found); }
@@ -5721,7 +5721,7 @@ static int cmd_sb_show(struct dl *dl) flags |=NLM_F_DUMP ; }else { - err =dl_argv_parse (dl,DL_OPT_HANDLE ,DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB ,0 );if (err)return err; }
@@ -5800,8 +5800,8 @@ static int cmd_sb_pool_show(struct dl *dl) flags |=NLM_F_DUMP ; }else { - err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB_POOL , -DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB | +DL_OPT_SB_POOL ,0 );if (err)return err; }
@@ -5821,8 +5821,8 @@ static int cmd_sb_pool_set(struct dl *dl)struct nlmsghdr *nlh;int err; - err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB_POOL | -DL_OPT_SB_SIZE |DL_OPT_SB_THTYPE ,DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB |DL_OPT_SB_POOL | +DL_OPT_SB_SIZE |DL_OPT_SB_THTYPE ,0 );if (err)return err;
@@ -5889,8 +5889,8 @@ static int cmd_sb_port_pool_show(struct dl *dl) flags |=NLM_F_DUMP ; }else { - err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB_POOL , -DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB | +DL_OPT_SB_POOL ,0 );if (err)return err; }
@@ -5910,8 +5910,8 @@ static int cmd_sb_port_pool_set(struct dl *dl)struct nlmsghdr *nlh;int err; - err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB_POOL |DL_OPT_SB_TH , -DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB |DL_OPT_SB_POOL | +DL_OPT_SB_TH ,0 );if (err)return err;
@@ -5996,8 +5996,8 @@ static int cmd_sb_tc_bind_show(struct dl *dl) flags |=NLM_F_DUMP ; }else { - err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB_TC | -DL_OPT_SB_TYPE ,DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB |DL_OPT_SB_TC | +DL_OPT_SB_TYPE ,0 );if (err)return err; }
@@ -6017,9 +6017,8 @@ static int cmd_sb_tc_bind_set(struct dl *dl)struct nlmsghdr *nlh;int err; - err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB_TC | -DL_OPT_SB_TYPE |DL_OPT_SB_POOL |DL_OPT_SB_TH , -DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB |DL_OPT_SB_TC | +DL_OPT_SB_TYPE |DL_OPT_SB_POOL |DL_OPT_SB_TH ,0 );if (err)return err;
@@ -6338,7 +6337,7 @@ static int cmd_sb_occ_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK |NLM_F_DUMP ;int err; - err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_HANDLEP ,DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_HANDLEP |DL_OPT_SB ,0 );if (err)return err;
@@ -6374,7 +6373,7 @@ static int cmd_sb_occ_snapshot(struct dl *dl)struct nlmsghdr *nlh;int err; - err =dl_argv_parse (dl,DL_OPT_HANDLE ,DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB ,0 );if (err)return err;
@@ -6391,7 +6390,7 @@ static int cmd_sb_occ_clearmax(struct dl *dl)struct nlmsghdr *nlh;int err; - err =dl_argv_parse (dl,DL_OPT_HANDLE ,DL_OPT_SB ); + err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB ,0 );if (err)return err;
Signature · 1 line
2.41.0
PATCH v2 2/6 devlink: make parsing of handle non-destructive to argv
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Currently, handle parsing is destructive as the "\0" string ends are being put in certain positions during parsing. That prevents it from being used repeatedly. This is problematic with the follow-up patch implementing dry-parsing. Fix by making a copy of handle argv during parsing.
--- devlink/devlink.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-)
devlink/devlink.c +26 -20
@@ -378,6 +378,7 @@ struct dl {struct list_head ifname_map_list;int argc;char **argv; +char *handle_argv;bool no_nice_names;struct dl_opts opts;bool json_output;
@@ -1066,9 +1067,8 @@ static int __dl_argv_handle(char *str, char **p_bus_name, char **p_dev_name)return 0 ; } -static int dl_argv_handle (struct dl *dl,char **p_bus_name,char **p_dev_name) +static int dl_argv_handle (char *str,char **p_bus_name,char **p_dev_name) { -char *str =dl_argv_next (dl);int err; err =ident_str_validate (str,1 );
@@ -1121,10 +1121,9 @@ static int __dl_argv_handle_port_ifname(struct dl *dl, char *str,return 0 ; } -static int dl_argv_handle_port (struct dl *dl,char **p_bus_name, +static int dl_argv_handle_port (struct dl *dl,char *str,char **p_bus_name,char **p_dev_name,uint32_t *p_port_index) { -char *str =dl_argv_next (dl);unsigned int slash_count;if (!str) {
@@ -1146,11 +1145,10 @@ static int dl_argv_handle_port(struct dl *dl, char **p_bus_name, } } -static int dl_argv_handle_both (struct dl *dl,char **p_bus_name, +static int dl_argv_handle_both (struct dl *dl,char *str,char **p_bus_name,char **p_dev_name,uint32_t *p_port_index,uint64_t *p_handle_bit) { -char *str =dl_argv_next (dl);unsigned int slash_count;int err;
@@ -1199,10 +1197,9 @@ static int __dl_argv_handle_name(char *str, char **p_bus_name,return str_split_by_char (handlestr, p_bus_name, p_dev_name,'/' ); } -static int dl_argv_handle_region (struct dl *dl,char **p_bus_name, +static int dl_argv_handle_region (char *str,char **p_bus_name,char **p_dev_name,char **p_region) { -char *str =dl_argv_next (dl);int err; err =ident_str_validate (str,2 );
@@ -1218,10 +1215,9 @@ static int dl_argv_handle_region(struct dl *dl, char **p_bus_name, } -static int dl_argv_handle_rate_node (struct dl *dl,char **p_bus_name, +static int dl_argv_handle_rate_node (char *str,char **p_bus_name,char **p_dev_name,char **p_node) { -char *str =dl_argv_next (dl);int err; err =ident_str_validate (str,2 );
@@ -1244,11 +1240,10 @@ static int dl_argv_handle_rate_node(struct dl *dl, char **p_bus_name,return err; } -static int dl_argv_handle_rate (struct dl *dl,char **p_bus_name, +static int dl_argv_handle_rate (char *str,char **p_bus_name,char **p_dev_name,uint32_t *p_port_index,char **p_node_name,uint64_t *p_handle_bit) { -char *str =dl_argv_next (dl);char *identifier;int err;
@@ -1698,14 +1693,24 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, {struct dl_opts *opts = &dl->opts;uint64_t o_all = o_required | o_optional; +char *str =dl_argv_next (dl);uint64_t o_found =0 ;int err; +if (str) { + str =strdup (str); +if (!str) +return -ENOMEM ; +free (dl->handle_argv); + dl->handle_argv = str; + } +if (o_required &DL_OPT_HANDLE && o_required &DL_OPT_HANDLEP ) {uint64_t handle_bit; - err =dl_argv_handle_both (dl, &opts->bus_name, &opts->dev_name, - &opts->port_index, &handle_bit); + err =dl_argv_handle_both (dl, str, &opts->bus_name, + &opts->dev_name, &opts->port_index, + &handle_bit);if (err)return err; o_required &= ~(DL_OPT_HANDLE |DL_OPT_HANDLEP ) | handle_bit;
@@ -1714,7 +1719,7 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, o_required & DL_OPT_PORT_FN_RATE_NODE_NAME) {uint64_t handle_bit; - err =dl_argv_handle_rate (dl, &opts->bus_name, &opts->dev_name, + err =dl_argv_handle_rate (str, &opts->bus_name, &opts->dev_name, &opts->port_index, &opts->rate_node_name, &handle_bit);
@@ -1724,25 +1729,25 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, handle_bit; o_found |= handle_bit; }else if (o_required &DL_OPT_HANDLE ) { - err =dl_argv_handle (dl, &opts->bus_name, &opts->dev_name); + err =dl_argv_handle (str, &opts->bus_name, &opts->dev_name);if (err)return err; o_found |=DL_OPT_HANDLE ; }else if (o_required &DL_OPT_HANDLEP ) { - err =dl_argv_handle_port (dl, &opts->bus_name, &opts->dev_name, - &opts->port_index); + err =dl_argv_handle_port (dl, str, &opts->bus_name, + &opts->dev_name, &opts->port_index);if (err)return err; o_found |=DL_OPT_HANDLEP ; }else if (o_required &DL_OPT_HANDLE_REGION ) { - err =dl_argv_handle_region (dl, &opts->bus_name, + err =dl_argv_handle_region (str, &opts->bus_name, &opts->dev_name, &opts->region_name);if (err)return err; o_found |=DL_OPT_HANDLE_REGION ; }else if (o_required &DL_OPT_PORT_FN_RATE_NODE_NAME ) { - err =dl_argv_handle_rate_node (dl, &opts->bus_name, + err =dl_argv_handle_rate_node (str, &opts->bus_name, &opts->dev_name, &opts->rate_node_name);if (err)
@@ -9902,6 +9907,7 @@ static struct dl *dl_alloc(void)static void dl_free (struct dl *dl) { +free (dl->handle_argv);free (dl); }
Signature · 1 line
2.41.0
PATCH v2 3/6 devlink: implement command line args dry parsing
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In preparation to the follow-up dump selector patch, introduce function dl_argv_dry_parse() which allows to do dry parsing of command line arguments without printing out any error messages to the user.
--- devlink/devlink.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
devlink/devlink.c +18 -0
@@ -64,6 +64,7 @@static int g_new_line_count;static int g_indent_level;static bool g_indent_newline; +static bool g_err_suspended;#define INDENT_STR_STEP 2#define INDENT_STR_MAXLEN 32
@@ -74,6 +75,8 @@ pr_err(const char *fmt, ...) {va_list ap; +if (g_err_suspended) +return ;va_start (ap, fmt);vfprintf (stderr, fmt, ap);va_end (ap);
@@ -2284,6 +2287,21 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,return dl_args_finding_required_validate (o_required, o_found); } +static int dl_argv_dry_parse (struct dl *dl,uint64_t o_required, +uint64_t o_optional) +{ +char **argv = dl->argv; +int argc = dl->argc; +int err; + + g_err_suspended = true; + err =dl_argv_parse (dl, o_required, o_optional); + g_err_suspended = false; + dl->argv = argv; + dl->argc = argc; +return err; +} +static void dl_function_attr_put (struct nlmsghdr *nlh,const struct dl_opts *opts) {
Signature · 1 line
2.41.0
PATCH v2 4/6 devlink: return -ENOENT if argument is missing
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
In preparation to the follow-up dump selector patch, make sure that the command line arguments parsing function returns -ENOENT in case the option is missing so the caller can distinguish.
--- devlink/devlink.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
devlink/devlink.c +4 -4
@@ -1048,7 +1048,7 @@ static int strtobool(const char *str, bool *p_val)static int ident_str_validate (char *str,unsigned int expected) {if (!str) -return -EINVAL ; +return -ENOENT ;if (get_str_char_count (str,'/' ) != expected) {pr_err ("Wrong identification string format.\n" );
@@ -1131,7 +1131,7 @@ static int dl_argv_handle_port(struct dl *dl, char *str, char **p_bus_name,if (!str) {pr_err ("Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\") expected.\n" ); -return -EINVAL ; +return -ENOENT ; } slash_count =get_str_char_count (str,'/' );switch (slash_count) {
@@ -1159,7 +1159,7 @@ static int dl_argv_handle_both(struct dl *dl, char *str, char **p_bus_name,pr_err ("One of following identifications expected:\n" "Devlink identification (\"bus_name/dev_name\")\n" "Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\")\n" ); -return -EINVAL ; +return -ENOENT ; } slash_count =get_str_char_count (str,'/' );if (slash_count ==1 ) {
@@ -1681,7 +1681,7 @@ static int dl_args_finding_required_validate(uint64_t o_required, o_flag = dl_args_required[i].o_flag;if ((o_required & o_flag) && !(o_found & o_flag)) {pr_err ("%s\n" , dl_args_required[i].err_msg); -return -EINVAL ; +return -ENOENT ; } }if (o_required & ~o_found) {
Signature · 1 line
2.41.0
PATCH v2 5/6 mnl_utils: introduce a helper to check if dump policy exists for command
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Benefit from GET_POLICY command of ctrl netlink and introduce a helper that dumps policies and finds out, if there is a separate policy specified for dump op of specified command.
--- include/mnl_utils.h | 1 + lib/mnl_utils.c | 121 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 2 deletions(-)
include/mnl_utils.h +1 -0
@@ -30,5 +30,6 @@ int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, siz mnl_cb_t cb, void *data);int mnlu_gen_socket_recv_run (struct mnlu_gen_socket *nlg,mnl_cb_t cb,void *data); +int mnlu_gen_cmd_dump_policy (struct mnlu_gen_socket *nlg,uint8_t cmd);#endif /* __MNL_UTILS_H__ */
lib/mnl_utils.c +119 -2
142 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH v2 6/6 devlink: implement dump selector for devlink objects show commands
In reply to Jiri PirkoFrom: Jiri Pirko <[email protected]>
Introduce a new helper dl_argv_parse_with_selector() to be used by show() functions instead of dl_argv().
Implement it to check if all needed options got get commands are specified. In case they are not, ask kernel for dump passing only the options (attributes) that are present, creating sort of partial key to instruct kernel to do partial dump.
--- devlink/devlink.c | 283 +++++++++++++++++++++++++++------------------- 1 file changed, 164 insertions(+), 119 deletions(-)
devlink/devlink.c +164 -119
@@ -2302,6 +2302,88 @@ static int dl_argv_dry_parse(struct dl *dl, uint64_t o_required,return err; } +/* List of extented handles with two slashes. */ +static const uint64_t dl_opt_extended_handle[] = { +DL_OPT_HANDLEP , +DL_OPT_HANDLE_REGION , +DL_OPT_PORT_FN_RATE_NODE_NAME , +}; + +static int dl_argv_parse_with_selector (struct dl *dl,uint16_t *flags, +uint8_t cmd, +uint64_t o_required, +uint64_t o_optional, +uint64_t o_dump_required, +uint64_t o_dump_optional) +{ +int err; +int i; + +if (dl_no_arg (dl)) + goto flag_set; + +/* In case the handle suggests it, do dry parsing first +* to see if all required options are there. Proceed with +* dump selector in case there are missing options on the +* command line. That means user provided partial +* object identification. +*/ + +if ((o_required & (DL_OPT_HANDLE |DL_OPT_HANDLEP )) == + (DL_OPT_HANDLE |DL_OPT_HANDLEP )) { +/* Handle case when both devlink handle and port handle +* are allowed. Try both alone, if parsing of either +* is successful, we have a do parse case. +*/ + err =dl_argv_dry_parse (dl, o_required & ~DL_OPT_HANDLEP , + o_optional); +if (err == -ENOENT ) + goto dump_parse; +else if (!err) + goto do_parse; + err =dl_argv_dry_parse (dl, o_required & ~DL_OPT_HANDLE , + o_optional); +if (err == -ENOENT ) + goto dump_parse; + goto do_parse; + } + +for (i =0 ; i <ARRAY_SIZE (dl_opt_extended_handle); i++) { +uint64_t handle = dl_opt_extended_handle[i]; + +if ((o_required & handle) == handle) { + err =dl_argv_dry_parse (dl, (o_required & ~handle) | +DL_OPT_HANDLE , + o_optional); +if (err == -ENOENT || !err) + goto dump_parse; + goto do_parse; + } + } + + err =dl_argv_dry_parse (dl, o_required, o_optional); +if (err == -ENOENT ) + goto dump_parse; + +do_parse: +return dl_argv_parse (dl, o_required, o_optional); + +dump_parse: + err =mnlu_gen_cmd_dump_policy (&dl->nlg, cmd); +if (err) { +pr_err ("Dump selectors are not supported by kernel for this command\n" ); +return -ENOTSUP ; + } + + err =dl_argv_parse (dl, o_dump_required, o_dump_optional); +if (err) +return err; + +flag_set: + *flags |=NLM_F_DUMP ; +return 0 ; +} +static void dl_function_attr_put (struct nlmsghdr *nlh,const struct dl_opts *opts) {
@@ -3580,13 +3662,11 @@ static int cmd_dev_param_show(struct dl *dl)struct nlmsghdr *nlh;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - }else { - err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_PARAM_NAME ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_PARAM_GET , +DL_OPT_HANDLE |DL_OPT_PARAM_NAME ,0 , +DL_OPT_HANDLE ,0 ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_PARAM_GET , flags);
@@ -4784,14 +4864,11 @@ static int cmd_port_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLEP ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_PORT_GET , +DL_OPT_HANDLEP ,0 , +DL_OPT_HANDLE ,0 ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_PORT_GET , flags);
@@ -4860,14 +4937,12 @@ static int cmd_port_param_show(struct dl *dl)struct nlmsghdr *nlh;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_PARAM_NAME ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags, +DEVLINK_CMD_PORT_PARAM_GET , +DL_OPT_HANDLE |DL_OPT_PARAM_NAME ,0 , +DL_OPT_HANDLE |DL_OPT_HANDLEP ,0 ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_PORT_PARAM_GET , flags);
@@ -5234,16 +5309,9 @@ static int cmd_port_fn_rate_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl, -DL_OPT_HANDLEP |DL_OPT_PORT_FN_RATE_NODE_NAME , -0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_RATE_GET , +DL_OPT_HANDLEP |DL_OPT_PORT_FN_RATE_NODE_NAME , +0 ,DL_OPT_HANDLE ,0 ); nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_RATE_GET , flags);
@@ -5622,14 +5690,11 @@ static int cmd_linecard_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLE ,DL_OPT_LINECARD ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_LINECARD_GET , +DL_OPT_HANDLE |DL_OPT_LINECARD ,0 , +DL_OPT_HANDLE ,0 ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_LINECARD_GET , flags);
@@ -5740,14 +5805,11 @@ static int cmd_sb_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_SB_GET , +DL_OPT_HANDLE |DL_OPT_SB ,0 , +DL_OPT_HANDLE ,DL_OPT_SB ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_SB_GET , flags);
@@ -5819,15 +5881,12 @@ static int cmd_sb_pool_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_SB | -DL_OPT_SB_POOL ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_SB_POOL_GET , +DL_OPT_HANDLE |DL_OPT_SB | +DL_OPT_SB_POOL ,0 , +DL_OPT_HANDLE ,DL_OPT_SB ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_SB_POOL_GET , flags);
@@ -5908,15 +5967,13 @@ static int cmd_sb_port_pool_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB | -DL_OPT_SB_POOL ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags, +DEVLINK_CMD_SB_PORT_POOL_GET , +DL_OPT_HANDLEP |DL_OPT_SB | +DL_OPT_SB_POOL ,0 , +DL_OPT_HANDLE |DL_OPT_HANDLEP ,DL_OPT_SB ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_SB_PORT_POOL_GET , flags);
@@ -6015,15 +6072,14 @@ static int cmd_sb_tc_bind_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLEP |DL_OPT_SB |DL_OPT_SB_TC | -DL_OPT_SB_TYPE ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags, +DEVLINK_CMD_SB_TC_POOL_BIND_GET , +DL_OPT_HANDLEP |DL_OPT_SB | +DL_OPT_SB_TC |DL_OPT_SB_TYPE ,0 , +DL_OPT_HANDLE |DL_OPT_HANDLEP , +DL_OPT_SB ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_SB_TC_POOL_BIND_GET , flags);
@@ -8697,14 +8753,11 @@ static int cmd_region_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLE_REGION ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_REGION_GET , +DL_OPT_HANDLE_REGION ,0 , +DL_OPT_HANDLE ,0 ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_REGION_GET , flags);
@@ -9388,19 +9441,20 @@ static int __cmd_health_show(struct dl *dl, bool show_device, bool show_port)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - }else { + err =dl_argv_parse_with_selector (dl, &flags, +DEVLINK_CMD_HEALTH_REPORTER_GET , +DL_OPT_HANDLE |DL_OPT_HANDLEP | +DL_OPT_HEALTH_REPORTER_NAME ,0 , +DL_OPT_HANDLE |DL_OPT_HANDLEP ,0 ); +if (err) +return err; + +if (!(flags &NLM_F_DUMP )) ctx.show_port = true; - err =dl_argv_parse (dl, -DL_OPT_HANDLE |DL_OPT_HANDLEP | -DL_OPT_HEALTH_REPORTER_NAME ,0 ); -if (err) -return err; - } nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_HEALTH_REPORTER_GET , flags); +dl_opts_put (nlh, dl);pr_out_section_start (dl,"health" );
@@ -9582,14 +9636,11 @@ static int cmd_trap_show(struct dl *dl)struct nlmsghdr *nlh;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl,DL_OPT_HANDLE |DL_OPT_TRAP_NAME ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_TRAP_GET , +DL_OPT_HANDLE |DL_OPT_TRAP_NAME ,0 , +DL_OPT_HANDLE ,0 ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_TRAP_GET , flags);
@@ -9660,15 +9711,12 @@ static int cmd_trap_group_show(struct dl *dl)struct nlmsghdr *nlh;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl, -DL_OPT_HANDLE |DL_OPT_TRAP_GROUP_NAME ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags, +DEVLINK_CMD_TRAP_GROUP_GET , +DL_OPT_HANDLE |DL_OPT_TRAP_GROUP_NAME ,0 , +DL_OPT_HANDLE ,0 ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_TRAP_GROUP_GET , flags);
@@ -9759,15 +9807,12 @@ static int cmd_trap_policer_show(struct dl *dl)struct nlmsghdr *nlh;int err; -if (dl_no_arg (dl)) { - flags |=NLM_F_DUMP ; - } -else { - err =dl_argv_parse (dl, -DL_OPT_HANDLE |DL_OPT_TRAP_POLICER_ID ,0 ); -if (err) -return err; - } + err =dl_argv_parse_with_selector (dl, &flags, +DEVLINK_CMD_TRAP_POLICER_GET , +DL_OPT_HANDLE |DL_OPT_TRAP_POLICER_ID ,0 , +DL_OPT_HANDLE ,0 ); +if (err) +return err; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_TRAP_POLICER_GET , flags);
Signature · 1 line
2.41.0
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Hello:
This series was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:
Quoted 4 lines · On Wed, 6 Sep 2023 13:11:07 +0200 you wrote:
From: Jiri Pirko <[email protected]>
First 5 patches are preparations for the last one.
Quoted 8 lines
Motivation:
For SFs, one devlink instance per SF is created. There might be thousands of these on a single host. When a user needs to know port handle for specific SF, he needs to dump all devlink ports on the host which does not scale good.
[...]
Here is the summary with links:
- [iproute2-next,v2,1/6] devlink: move DL_OPT_SB into required options
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=158215c53677 - [iproute2-next,v2,2/6] devlink: make parsing of handle non-destructive to argv https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=5d9f42124ccd - [iproute2-next,v2,3/6] devlink: implement command line args dry parsing https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=8eb894eda67d - [iproute2-next,v2,4/6] devlink: return -ENOENT if argument is missing https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=fd1c2af8cbaa - [iproute2-next,v2,5/6] mnl_utils: introduce a helper to check if dump policy exists for command https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=20b299a3ec35
- [iproute2-next,v2,6/6] devlink: implement dump selector for devlink objects show commands
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=70faecdca8f5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html