Add implementation for the port parameters
getting/setting.
Add bash completion for port param.
Add man description for port param.
Example:
$ devlink dev param set netdevsim/netdevsim0/0 name test_port_parameter value
false cmode runtime
$ devlink port param show netdevsim/netdevsim0/0 name test_port_parameter
netdevsim/netdevsim0/0:
name test_port_parameter type driver-specific
values:
cmode runtime value false
$ devlink port -jp param show netdevsim/netdevsim0/0 name test_port_parameter
{
"param": {
"netdevsim/netdevsim0/0": [ {
"name": "test_port_parameter",
"type": "driver-specific",
"values": [ {
"cmode": "runtime",
"value": false
} ]
} ]
}
}
Signed-off-by: Oleksandr Mazur
---
V3:
1) Add usage example;
2) Remove stray newline in code;
V2:
1) Add bash completion for port param;
2) Add man decsription / examples for port param;
bash-completion/devlink | 55
devlink/devlink.c | 274 +++-
man/man8/devlink-port.8 | 65 ++
3 files changed, 388 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..1984ddbb 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;
@@ -2723,9 +2724,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 +2752,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 +2768,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 +2966,21 @@