Re: [PATCH iproute-next v2] devlink: add support for port params get/set

2021-01-29 Thread David Ahern
On 1/25/21 6:48 AM, Oleksandr Mazur wrote:
> Add implementation for the port parameters getting/setting.
> Add bash completion for port param.
> Add man description for port param.
> 

Add example commands here - both set and show. Include a json version of
the show.

> Signed-off-by: Oleksandr Mazur 
> ---
> V2:
> 1) Add bash completion for port param;
> 2) Add man decsription / examples for port param;
> 
>  bash-completion/devlink |  55 
>  devlink/devlink.c   | 275 +++-
>  man/man8/devlink-port.8 |  65 ++
>  3 files changed, 389 insertions(+), 6 deletions(-)
> 

> diff --git a/devlink/devlink.c b/devlink/devlink.c
> index a2e06644..0fc1d4f0 100644
> --- a/devlink/devlink.c
> +++ b/devlink/devlink.c
> @@ -2706,7 +2706,8 @@ static void pr_out_param_value(struct dl *dl, const 
> char *nla_name,
>   }
>  }
>  
> -static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array)
> +static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array,
> +  bool is_port_param)
>  {
>   struct nlattr *nla_param[DEVLINK_ATTR_MAX + 1] = {};
>   struct nlattr *param_value_attr;
> @@ -2714,6 +2715,7 @@ static void pr_out_param(struct dl *dl, struct nlattr 
> **tb, bool array)
>   int nla_type;
>   int err;
>  
> +

stray newline here




[PATCH iproute-next v2] devlink: add support for port params get/set

2021-01-25 Thread Oleksandr Mazur
Add implementation for the port parameters getting/setting.
Add bash completion for port param.
Add man description for port param.

Signed-off-by: Oleksandr Mazur 
---
V2:
1) Add bash completion for port param;
2) Add man decsription / examples for port param;

 bash-completion/devlink |  55 
 devlink/devlink.c   | 275 +++-
 man/man8/devlink-port.8 |  65 ++
 3 files changed, 389 insertions(+), 6 deletions(-)

diff --git a/bash-completion/devlink b/bash-completion/devlink
index 7395b504..361be9fe 100644
--- a/bash-completion/devlink
+++ b/bash-completion/devlink
@@ -319,6 +319,57 @@ _devlink_port_split()
 esac
 }
 
+# Completion for devlink port param set
+_devlink_port_param_set()
+{
+case $cword in
+7)
+COMPREPLY=( $( compgen -W "value" -- "$cur" ) )
+return
+;;
+8)
+# String argument
+return
+;;
+9)
+COMPREPLY=( $( compgen -W "cmode" -- "$cur" ) )
+return
+;;
+10)
+COMPREPLY=( $( compgen -W "runtime driverinit permanent" -- \
+"$cur" ) )
+return
+;;
+esac
+}
+
+# Completion for devlink port param
+_devlink_port_param()
+{
+case "$cword" in
+3)
+COMPREPLY=( $( compgen -W "show set" -- "$cur" ) )
+return
+;;
+4)
+_devlink_direct_complete "port"
+return
+;;
+5)
+COMPREPLY=( $( compgen -W "name" -- "$cur" ) )
+return
+;;
+6)
+_devlink_direct_complete "param_name"
+return
+;;
+esac
+
+if [[ "${words[3]}" == "set" ]]; then
+_devlink_port_param_set
+fi
+}
+
 # Completion for devlink port
 _devlink_port()
 {
@@ -331,6 +382,10 @@ _devlink_port()
 _devlink_port_split
 return
 ;;
+param)
+_devlink_port_param
+return
+;;
 show|unsplit)
 if [[ $cword -eq 3 ]]; then
 _devlink_direct_complete "port"
diff --git a/devlink/devlink.c b/devlink/devlink.c
index a2e06644..0fc1d4f0 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -2706,7 +2706,8 @@ static void pr_out_param_value(struct dl *dl, const char 
*nla_name,
}
 }
 
-static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array)
+static void pr_out_param(struct dl *dl, struct nlattr **tb, bool array,
+bool is_port_param)
 {
struct nlattr *nla_param[DEVLINK_ATTR_MAX + 1] = {};
struct nlattr *param_value_attr;
@@ -2714,6 +2715,7 @@ static void pr_out_param(struct dl *dl, struct nlattr 
**tb, bool array)
int nla_type;
int err;
 
+
err = mnl_attr_parse_nested(tb[DEVLINK_ATTR_PARAM], attr_cb, nla_param);
if (err != MNL_CB_OK)
return;
@@ -2723,9 +2725,15 @@ static void pr_out_param(struct dl *dl, struct nlattr 
**tb, bool array)
return;
 
if (array)
-   pr_out_handle_start_arr(dl, tb);
+   if (is_port_param)
+   pr_out_port_handle_start_arr(dl, tb, false);
+   else
+   pr_out_handle_start_arr(dl, tb);
else
-   __pr_out_handle_start(dl, tb, true, false);
+   if (is_port_param)
+   pr_out_port_handle_start(dl, tb, false);
+   else
+   __pr_out_handle_start(dl, tb, true, false);
 
nla_type = mnl_attr_get_u8(nla_param[DEVLINK_ATTR_PARAM_TYPE]);
 
@@ -2745,7 +2753,10 @@ static void pr_out_param(struct dl *dl, struct nlattr 
**tb, bool array)
pr_out_entry_end(dl);
}
pr_out_array_end(dl);
-   pr_out_handle_end(dl);
+   if (is_port_param)
+   pr_out_port_handle_end(dl);
+   else
+   pr_out_handle_end(dl);
 }
 
 static int cmd_dev_param_show_cb(const struct nlmsghdr *nlh, void *data)
@@ -2758,7 +2769,7 @@ static int cmd_dev_param_show_cb(const struct nlmsghdr 
*nlh, void *data)
if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
!tb[DEVLINK_ATTR_PARAM])
return MNL_CB_ERROR;
-   pr_out_param(dl, tb, true);
+   pr_out_param(dl, tb, true, false);
return MNL_CB_OK;
 }
 
@@ -2956,6 +2967,21 @@ err_param_value_parse:
return err;
 }
 
+static int cmd_port_param_show_cb(const struct nlmsghdr *nlh, void *data)
+{
+   struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+   struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+   struct dl *dl = data;
+
+   mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+   if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+   !tb[DEVLINK_ATTR_PORT_INDEX] || !tb[DEVLINK_ATTR_PARAM])
+   return