[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b845b429-0b9b-72cd-eaf4-3e621055fe71@isovalent.com>
Date: Fri, 17 Jul 2020 13:57:23 +0100
From: Quentin Monnet <quentin@...valent.com>
To: Yonghong Song <yhs@...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
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.
Best,
Quentin
Powered by blists - more mailing lists