All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump
@ 2019-05-26  0:01 Andrii Nakryiko
  2019-05-28  8:25 ` Quentin Monnet
  2019-05-28  9:24 ` Daniel Borkmann
  0 siblings, 2 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2019-05-26  0:01 UTC (permalink / raw)
  To: andrii.nakryiko, netdev, bpf, ast, daniel, quentin.monnet, kernel-team
  Cc: Andrii Nakryiko

Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
IDs is scavenged from loaded BPF programs that have associated BTFs, as
there is currently no API in libbpf to fetch list of all BTFs in the
system.

Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/bpf/bpftool/bash-completion/bpftool | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index 75c01eafd3a1..fbbad0ed8e82 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -71,6 +71,12 @@ _bpftool_get_prog_tags()
         command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
 }
 
+_bpftool_get_btf_ids()
+{
+    COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
+        command sed -n 's/.*"btf_id": \(.*\),\?$/\1/p' )" -- "$cur" ) )
+}
+
 _bpftool_get_obj_map_names()
 {
     local obj
@@ -635,6 +641,9 @@ _bpftool()
                                 map)
                                     _bpftool_get_map_ids
                                     ;;
+                                dump)
+                                    _bpftool_get_btf_ids
+                                    ;;
                             esac
                             return 0
                             ;;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump
  2019-05-26  0:01 [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump Andrii Nakryiko
@ 2019-05-28  8:25 ` Quentin Monnet
  2019-05-28  9:24 ` Daniel Borkmann
  1 sibling, 0 replies; 7+ messages in thread
From: Quentin Monnet @ 2019-05-28  8:25 UTC (permalink / raw)
  To: Andrii Nakryiko, andrii.nakryiko, netdev, bpf, ast, daniel, kernel-team

2019-05-25 17:01 UTC-0700 ~ Andrii Nakryiko <andriin@fb.com>
> Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
> IDs is scavenged from loaded BPF programs that have associated BTFs, as
> there is currently no API in libbpf to fetch list of all BTFs in the
> system.
> 
> Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>

Thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump
  2019-05-26  0:01 [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump Andrii Nakryiko
  2019-05-28  8:25 ` Quentin Monnet
@ 2019-05-28  9:24 ` Daniel Borkmann
  2019-05-28 16:41   ` Andrii Nakryiko
  1 sibling, 1 reply; 7+ messages in thread
From: Daniel Borkmann @ 2019-05-28  9:24 UTC (permalink / raw)
  To: Andrii Nakryiko, andrii.nakryiko, netdev, bpf, ast,
	quentin.monnet, kernel-team

On 05/26/2019 02:01 AM, Andrii Nakryiko wrote:
> Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
> IDs is scavenged from loaded BPF programs that have associated BTFs, as
> there is currently no API in libbpf to fetch list of all BTFs in the
> system.
> 
> Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Applied, thanks!

(Please add versioning in the subject in future, e.g. [PATCH v2 bpf-next])

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump
  2019-05-28  9:24 ` Daniel Borkmann
@ 2019-05-28 16:41   ` Andrii Nakryiko
  0 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2019-05-28 16:41 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Andrii Nakryiko, Networking, bpf, Alexei Starovoitov,
	Quentin Monnet, Kernel Team

On Tue, May 28, 2019 at 2:24 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> On 05/26/2019 02:01 AM, Andrii Nakryiko wrote:
> > Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
> > IDs is scavenged from loaded BPF programs that have associated BTFs, as
> > there is currently no API in libbpf to fetch list of all BTFs in the
> > system.
> >
> > Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> Applied, thanks!

Thanks!

>
> (Please add versioning in the subject in future, e.g. [PATCH v2 bpf-next])

Ah yeah, sorry about that, forgot to update --subject-prefix when
generating patch :(

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump
  2019-05-25 11:55 ` Quentin Monnet
@ 2019-05-26  0:00   ` Andrii Nakryiko
  0 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2019-05-26  0:00 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: Andrii Nakryiko, Kernel Team, Networking, bpf,
	Alexei Starovoitov, Daniel Borkmann

On Sat, May 25, 2019 at 4:55 AM Quentin Monnet
<quentin.monnet@netronome.com> wrote:
>
> 2019-05-24 22:38 UTC-0700 ~ Andrii Nakryiko <andriin@fb.com>
> > Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
> > IDs is scavenged from loaded BPF programs that have associated BTFs, as
> > there is currently no API in libbpf to fetch list of all BTFs in the
> > system.
> >
> > Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> >  tools/bpf/bpftool/bash-completion/bpftool | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
> > index 75c01eafd3a1..9fbc33e93689 100644
> > --- a/tools/bpf/bpftool/bash-completion/bpftool
> > +++ b/tools/bpf/bpftool/bash-completion/bpftool
> > @@ -71,6 +71,13 @@ _bpftool_get_prog_tags()
> >          command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
> >  }
> >
> > +_bpftool_get_btf_ids()
> > +{
> > +    COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
> > +        command sed -n 's/.*"btf_id": \(.*\),\?$/\1/p' | \
> > +        command sort -nu )" -- "$cur" ) )
> > +}
>
> Thanks! It works well. It looks like the "sort -nu" is not required,
> however? Bash completion on my system seems to run the equivalent of
> "sort -u" on the results anyway, ignoring the ordering you made just
> before. As I understand this is what completion always does, unless we
> pass "-o nosort" to "complete".
>
> E.g. I get the same following output:
>
>         1     1234  191   222   25
>
> When completing with this function:
>
>         _bpftool()
>         {
>                 COMPREPLY+=( $( compgen -W "$( \
>                         command echo '1 1 1 191 1234 25 222')"))
>         }
>         complete -F _bpftool bpftool
>
> or with that one:
>
>         _bpftool()
>         {
>                 COMPREPLY+=( $( compgen -W "$( \
>                         command echo '1 1 1 191 1234 25 222' | \
>                         command sort -nu )" ) )
>         }
>         complete -F _bpftool bpftool
>
> Could you double check you have the same thing on your setup, please? If
> so we can just remove the "sort -nu".

Yeah, seems like it behaves the same without sort -nu, I dropped it in
v2. Thanks!

>
> Quentin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump
  2019-05-25  5:38 Andrii Nakryiko
@ 2019-05-25 11:55 ` Quentin Monnet
  2019-05-26  0:00   ` Andrii Nakryiko
  0 siblings, 1 reply; 7+ messages in thread
From: Quentin Monnet @ 2019-05-25 11:55 UTC (permalink / raw)
  To: Andrii Nakryiko, andrii.nakryiko, kernel-team, netdev, bpf, ast, daniel

2019-05-24 22:38 UTC-0700 ~ Andrii Nakryiko <andriin@fb.com>
> Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
> IDs is scavenged from loaded BPF programs that have associated BTFs, as
> there is currently no API in libbpf to fetch list of all BTFs in the
> system.
> 
> Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
>  tools/bpf/bpftool/bash-completion/bpftool | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
> index 75c01eafd3a1..9fbc33e93689 100644
> --- a/tools/bpf/bpftool/bash-completion/bpftool
> +++ b/tools/bpf/bpftool/bash-completion/bpftool
> @@ -71,6 +71,13 @@ _bpftool_get_prog_tags()
>          command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
>  }
>  
> +_bpftool_get_btf_ids()
> +{
> +    COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
> +        command sed -n 's/.*"btf_id": \(.*\),\?$/\1/p' | \
> +        command sort -nu )" -- "$cur" ) )
> +}

Thanks! It works well. It looks like the "sort -nu" is not required,
however? Bash completion on my system seems to run the equivalent of
"sort -u" on the results anyway, ignoring the ordering you made just
before. As I understand this is what completion always does, unless we
pass "-o nosort" to "complete".

E.g. I get the same following output:

	1     1234  191   222   25

When completing with this function:

	_bpftool()
	{
		COMPREPLY+=( $( compgen -W "$( \
			command echo '1 1 1 191 1234 25 222')"))
	}
	complete -F _bpftool bpftool

or with that one:

	_bpftool()
	{
		COMPREPLY+=( $( compgen -W "$( \
			command echo '1 1 1 191 1234 25 222' | \
			command sort -nu )" ) )
	}
	complete -F _bpftool bpftool

Could you double check you have the same thing on your setup, please? If
so we can just remove the "sort -nu".

Quentin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump
@ 2019-05-25  5:38 Andrii Nakryiko
  2019-05-25 11:55 ` Quentin Monnet
  0 siblings, 1 reply; 7+ messages in thread
From: Andrii Nakryiko @ 2019-05-25  5:38 UTC (permalink / raw)
  To: andrii.nakryiko, kernel-team, netdev, bpf, ast, daniel, quentin.monnet
  Cc: Andrii Nakryiko

Auto-complete BTF IDs for `btf dump id` sub-command. List of possible BTF
IDs is scavenged from loaded BPF programs that have associated BTFs, as
there is currently no API in libbpf to fetch list of all BTFs in the
system.

Suggested-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/bpf/bpftool/bash-completion/bpftool | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index 75c01eafd3a1..9fbc33e93689 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -71,6 +71,13 @@ _bpftool_get_prog_tags()
         command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
 }
 
+_bpftool_get_btf_ids()
+{
+    COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
+        command sed -n 's/.*"btf_id": \(.*\),\?$/\1/p' | \
+        command sort -nu )" -- "$cur" ) )
+}
+
 _bpftool_get_obj_map_names()
 {
     local obj
@@ -635,6 +642,9 @@ _bpftool()
                                 map)
                                     _bpftool_get_map_ids
                                     ;;
+                                dump)
+                                    _bpftool_get_btf_ids
+                                    ;;
                             esac
                             return 0
                             ;;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-05-28 16:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-26  0:01 [PATCH bpf-next] bpftool: auto-complete BTF IDs for btf dump Andrii Nakryiko
2019-05-28  8:25 ` Quentin Monnet
2019-05-28  9:24 ` Daniel Borkmann
2019-05-28 16:41   ` Andrii Nakryiko
  -- strict thread matches above, loose matches on Subject: below --
2019-05-25  5:38 Andrii Nakryiko
2019-05-25 11:55 ` Quentin Monnet
2019-05-26  0:00   ` Andrii Nakryiko

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.