[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <2712b760-f203-564a-c559-f1b7546a0e83@fb.com>
Date: Fri, 17 Jul 2020 11:52:57 -0700
From: Yonghong Song <yhs@...com>
To: Quentin Monnet <quentin@...valent.com>, <bpf@...r.kernel.org>,
<netdev@...r.kernel.org>
CC: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>, <kernel-team@...com>,
Martin KaFai Lau <kafai@...com>
Subject: Re: [PATCH bpf-next 09/13] tools/bpftool: add bpftool support for bpf
map element iterator
On 7/17/20 5:57 AM, Quentin Monnet wrote:
> 2020-07-16 10:42 UTC-0700 ~ Yonghong Song <yhs@...com>
>>
>>
>> On 7/16/20 9:39 AM, Quentin Monnet wrote:
>>> 2020-07-13 09:17 UTC-0700 ~ Yonghong Song <yhs@...com>
>
> [...]
>
>>> Could you please also update the bash completion?
>>
>> This is always my hardest part! In this case it is
>> bpftool iter pin <filedir> <filedir> [map MAP]
>>
>> Any particular existing bpftool implementation I can imitate?
>
> I would say the closest/easiest to reuse we have would be
> completion for the MAP part in either
>
> bpftool prog attach PROG ATTACH_TYPE [MAP]
>
> or
>
> bpftool map pin MAP FILE
>
> But I'll save you some time, I gave it a go and this is what
> I came up with:
>
> ------
> diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
> index 25b25aca1112..6640e18096a8 100644
> --- a/tools/bpf/bpftool/bash-completion/bpftool
> +++ b/tools/bpf/bpftool/bash-completion/bpftool
> @@ -613,9 +613,26 @@ _bpftool()
> esac
> ;;
> iter)
> + local MAP_TYPE='id pinned name'
> case $command in
> pin)
> - _filedir
> + case $prev in
> + $command)
> + _filedir
> + ;;
> + id)
> + _bpftool_get_map_ids
> + ;;
> + name)
> + _bpftool_get_map_names
> + ;;
> + pinned)
> + _filedir
> + ;;
> + *)
> + _bpftool_one_of_list $MAP_TYPE
> + ;;
> + esac
> return 0
> ;;
> *)
> ------
>
> So if we complete "bpftool iter pin", if we're right after "pin"
> we still complete with file names (for the object file to pin).
> If we're after one of the map keywords (id|name|pinned), complete
> with map ids or map names or file names, depending on the case.
> For other cases (i.e. after object file to pin), offer the map
> keywords (id|name|pinned).
>
> Feel free to reuse.
Thanks a lot! Will reuse and mention your suggestion of this code
in commit message.
>
> Best,
> Quentin
>
Powered by blists - more mailing lists