From: Ido Schimmel <idosch@nvidia.com>
To: Jiri Pirko <jiri@resnulli.us>
Cc: netdev@vger.kernel.org, sthemmin@microsoft.com,
dsahern@gmail.com, mlxsw@nvidia.com
Subject: Re: [patch iproute2/net-next v2] devlink: add support for linecard show and type set
Date: Thu, 14 Jul 2022 16:18:45 +0300 [thread overview]
Message-ID: <YtAXtakVePIxAdyL@shredder> (raw)
In-Reply-To: <20220713134749.2988396-1-jiri@resnulli.us>
On Wed, Jul 13, 2022 at 03:47:49PM +0200, Jiri Pirko wrote:
> diff --git a/bash-completion/devlink b/bash-completion/devlink
> index 361be9feee83..45c7a8121401 100644
> --- a/bash-completion/devlink
> +++ b/bash-completion/devlink
> @@ -43,6 +43,18 @@ _devlink_direct_complete()
> | jq '.port as $ports | $ports | keys[] as $key
> | ($ports[$key].netdev // $key)')
> ;;
> + lc)
> + dev=${words[3]}
> + value=$(devlink -j lc show 2>/dev/null \
> + | jq ".lc[\"$dev\"]" \
> + | jq '. as $lcs | $lcs | keys[] as $key |($lcs[$key].lc)')
> + ;;
On a system that has a devlink instance without line cards I'm getting
the following error during completion:
$ devlink lc set pci/0000:06:00.0 lc jq: error (at <stdin>:1): null (null) has no keys
jq: error (at <stdin>:1): null (null) has no keys
This fixes the issue for me and should still work on a system with line
cards (test):
diff --git a/bash-completion/devlink b/bash-completion/devlink
index 45c7a8121401..757e03b749ce 100644
--- a/bash-completion/devlink
+++ b/bash-completion/devlink
@@ -47,7 +47,8 @@ _devlink_direct_complete()
dev=${words[3]}
value=$(devlink -j lc show 2>/dev/null \
| jq ".lc[\"$dev\"]" \
- | jq '. as $lcs | $lcs | keys[] as $key |($lcs[$key].lc)')
+ | jq '. as $lcs | $lcs | keys[] as $key |($lcs[$key].lc)' \
+ 2>/dev/null)
;;
lc_type)
dev=${words[3]}
> + lc_type)
> + dev=${words[3]}
> + lc=${words[5]}
> + value=$(devlink lc show $dev lc $lc -j 2>/dev/null \
> + | jq '.[][][]["supported_types"][]')
> + ;;
> region)
> value=$(devlink -j region show 2>/dev/null \
> | jq '.regions' | jq 'keys[]')
> @@ -395,6 +407,62 @@ _devlink_port()
> esac
> }
>
> +# Completion for devlink lc set
> +_devlink_lc_set()
> +{
> + case "$cword" in
> + 3)
> + _devlink_direct_complete "dev"
> + return
> + ;;
> + 4)
> + COMPREPLY=( $( compgen -W "lc" -- "$cur" ) )
> + ;;
> + 5)
> + _devlink_direct_complete "lc"
> + ;;
> + 6)
> + COMPREPLY=( $( compgen -W "type notype" -- "$cur" ) )
> + return
> + ;;
> + 7)
> + if [[ "$prev" == "type" ]]; then
> + _devlink_direct_complete "lc_type"
> + fi
> + esac
> +}
> +
> +# Completion for devlink lc show
> +_devlink_lc_show()
> +{
> + case $cword in
> + 3)
> + _devlink_direct_complete "dev"
> + ;;
> + 4)
> + COMPREPLY=( $( compgen -W "lc" -- "$cur" ) )
> + ;;
> + 5)
> + _devlink_direct_complete "lc"
> + ;;
> + esac
> +}
> +
> +# Completion for devlink lc
> +_devlink_lc()
> +{
> + case $command in
> + set)
> + _devlink_lc_set
> + return
> + ;;
> + show)
> + _devlink_lc_show
> + return
> + ;;
> + esac
> +}
> +
> # Completion for devlink dpipe
> _devlink_dpipe()
> {
> @@ -988,6 +1056,7 @@ _devlink()
> local object=${words[1]}
> local command=${words[2]}
> local pprev=${words[cword - 2]}
> + local prev=${words[cword - 1]}
>
> if [[ $objects =~ $object ]]; then
> if [[ $cword -eq 2 ]]; then
> diff --git a/devlink/devlink.c b/devlink/devlink.c
> index ddf430bbb02a..1e2cfc3d4285 100644
> --- a/devlink/devlink.c
> +++ b/devlink/devlink.c
Code itself looks consistent with other commands
[...]
> --- /dev/null
> +++ b/man/man8/devlink-lc.8
> @@ -0,0 +1,103 @@
> +.TH DEVLINK\-LC 8 "20 Apr 2022" "iproute2" "Linux"
> +.SH NAME
> +devlink-lc \- devlink line card configuration
> +.SH SYNOPSIS
> +.sp
> +.ad l
> +.in +8
> +.ti -8
> +.B devlink
> +.RI "[ " OPTIONS " ]"
> +.B lc
> +.RI " { " COMMAND " | "
> +.BR help " }"
> +.sp
> +
> +.ti -8
> +.IR OPTIONS " := { "
> +\fB\-V\fR[\fIersion\fR] }
> +
> +.ti -8
> +.B "devlink lc set"
> +.IB DEV " lc " LC_INDEX
> +.RB [ " type " {
> +.IR LC_TYPE " | "
> +.BR notype " } ] "
> +
> +.ti -8
> +.B "devlink lc show"
> +.RI "[ " DEV " [ "
> +.BI lc " LC_INDEX
> +.R " ] ]"
> +
> +.ti -8
> +.B devlink lc help
> +
> +.SH "DESCRIPTION"
> +.SS devlink lc set - change line card attributes
> +
> +.PP
> +.TP
> +.I "DEV"
> +Specifies the devlink device to operate on.
> +
> +.in +4
> +Format is:
> +.in +2
> +BUS_NAME/BUS_ADDRESS
> +
> +.TP
> +.BI lc " LC_INDEX "
> +Specifies index of a line card slot to set.
> +
> +.TP
> +.BR type " { "
> +.IR LC_TYPE " | "
> +.BR notype " } "
> +Type of line card to provision. Each driver provides a list of supported line card types which is shown in the output of
> +.BR "devlink lc show " command.
> +
> +.SS devlink lc show - display line card attributes
> +
> +.PP
> +.TP
> +.I "DEV"
> +.RB "Specifies the devlink device to operate on. If this and " lc " arguments are omitted all line cards of all devices are listed.
> +
> +.TP
> +.BI lc " LC_INDEX "
> +Specifies index of a line card slot to show.
> +
> +.SH "EXAMPLES"
> +.PP
> +devlink ls show
s/ls/lc/
> +.RS 4
> +Shows the state of all line cards on the system.
> +.RE
> +.PP
> +devlink lc show pci/0000:01:00.0 lc 1
> +.RS 4
> +Shows the state of line card with index 1.
> +.RE
> +.PP
> +devlink lc set pci/0000:01:00.0 lc 1 type 16x100G
> +.RS 4
> +.RI "Set type of specified line card to type " 16x100G "."
s/Set/Sets/
Or change the first two
> +.RE
> +.PP
> +devlink lc set pci/0000:01:00.0 lc 1 notype
> +.RS 4
> +Clear provisioning on a line card.
s/Clear/Clears/
> +.RE
> +
> +.SH SEE ALSO
> +.BR devlink (8),
> +.BR devlink-dev (8),
> +.BR devlink-port (8),
> +.BR devlink-sb (8),
Irrelevant
> +.BR devlink-monitor (8),
> +.BR devlink-health (8),
Same
> +.br
> +
> +.SH AUTHOR
> +Jiri Pirko <jiri@nvidia.com>
> --
> 2.35.3
>
next prev parent reply other threads:[~2022-07-14 13:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-13 13:47 [patch iproute2/net-next v2] devlink: add support for linecard show and type set Jiri Pirko
2022-07-14 13:18 ` Ido Schimmel [this message]
2022-07-16 11:23 ` Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YtAXtakVePIxAdyL@shredder \
--to=idosch@nvidia.com \
--cc=dsahern@gmail.com \
--cc=jiri@resnulli.us \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=sthemmin@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.