lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 14 Jul 2022 16:18:45 +0300
From:   Ido Schimmel <idosch@...dia.com>
To:     Jiri Pirko <jiri@...nulli.us>
Cc:     netdev@...r.kernel.org, sthemmin@...rosoft.com, dsahern@...il.com,
        mlxsw@...dia.com
Subject: Re: [patch iproute2/net-next v2] devlink: add support for linecard
 show and type set

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@...dia.com>
> -- 
> 2.35.3
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ