Re: [PATCH net-next] tools: bpftool: add bash completion for bpftool

2017-10-29 Thread David Miller
From: Jakub Kicinski 
Date: Thu, 26 Oct 2017 14:16:05 -0700

> From: Quentin Monnet 
> 
> Add a completion file for bash. The completion function runs bpftool
> when needed, making it smart enough to help users complete ids or tags
> for eBPF programs and maps currently on the system.
> 
> Update Makefile to install completion file to
> /usr/share/bash-completion/completions when running `make install`.
> 
> Emacs file mode and (at the end) Vim modeline have been added, to keep
> the style in use for most existing bash completion files. In this, it
> differs from tools/perf/perf-completion.sh, which seems to be the only
> other completion file among the kernel sources repository. This is also
> valid for indent style: 4-space indents, as in other completion files.
> 
> Signed-off-by: Quentin Monnet 
> Signed-off-by: Jakub Kicinski 

I'll apply this for now.

If there are major objections I can revert.

Thanks.


Re: [PATCH net-next] tools: bpftool: add bash completion for bpftool

2017-10-29 Thread David Miller
From: Jakub Kicinski 
Date: Thu, 26 Oct 2017 14:16:05 -0700

> From: Quentin Monnet 
> 
> Add a completion file for bash. The completion function runs bpftool
> when needed, making it smart enough to help users complete ids or tags
> for eBPF programs and maps currently on the system.
> 
> Update Makefile to install completion file to
> /usr/share/bash-completion/completions when running `make install`.
> 
> Emacs file mode and (at the end) Vim modeline have been added, to keep
> the style in use for most existing bash completion files. In this, it
> differs from tools/perf/perf-completion.sh, which seems to be the only
> other completion file among the kernel sources repository. This is also
> valid for indent style: 4-space indents, as in other completion files.
> 
> Signed-off-by: Quentin Monnet 
> Signed-off-by: Jakub Kicinski 

I'll apply this for now.

If there are major objections I can revert.

Thanks.


[PATCH net-next] tools: bpftool: add bash completion for bpftool

2017-10-26 Thread Jakub Kicinski
From: Quentin Monnet 

Add a completion file for bash. The completion function runs bpftool
when needed, making it smart enough to help users complete ids or tags
for eBPF programs and maps currently on the system.

Update Makefile to install completion file to
/usr/share/bash-completion/completions when running `make install`.

Emacs file mode and (at the end) Vim modeline have been added, to keep
the style in use for most existing bash completion files. In this, it
differs from tools/perf/perf-completion.sh, which seems to be the only
other completion file among the kernel sources repository. This is also
valid for indent style: 4-space indents, as in other completion files.

Signed-off-by: Quentin Monnet 
Signed-off-by: Jakub Kicinski 
---
CCing LKML for wider input on whether editor tags in completion 
files under tools/ are OK.

 tools/bpf/bpftool/Makefile|   3 +
 tools/bpf/bpftool/bash-completion/bpftool | 354 ++
 2 files changed, 357 insertions(+)
 create mode 100644 tools/bpf/bpftool/bash-completion/bpftool

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 4f339824ca57..813826c50936 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -46,6 +46,7 @@ $(LIBBPF): FORCE
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
 
 prefix = /usr
+bash_compdir ?= $(prefix)/share/bash-completion/completions
 
 CC = gcc
 
@@ -76,6 +77,8 @@ clean: $(LIBBPF)-clean
 
 install:
install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
+   install -m 0755 -d $(bash_compdir)
+   install -m 0644 bash-completion/bpftool $(bash_compdir)
 
 doc:
$(Q)$(MAKE) -C Documentation/
diff --git a/tools/bpf/bpftool/bash-completion/bpftool 
b/tools/bpf/bpftool/bash-completion/bpftool
new file mode 100644
index ..7febee05c8e7
--- /dev/null
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -0,0 +1,354 @@
+# bpftool(8) bash completion   -*- shell-script -*-
+#
+# Copyright (C) 2017 Netronome Systems, Inc.
+#
+# This software is dual licensed under the GNU General License
+# Version 2, June 1991 as shown in the file COPYING in the top-level
+# directory of this source tree or the BSD 2-Clause License provided
+# below.  You have the option to license this software under the
+# complete terms of either license.
+#
+# The BSD 2-Clause License:
+#
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+#
+#  1. Redistributions of source code must retain the above
+# copyright notice, this list of conditions and the following
+# disclaimer.
+#
+#  2. Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+# Author: Quentin Monnet 
+
+# Takes a list of words in argument; each one of them is added to COMPREPLY if
+# it is not already present on the command line. Returns no value.
+_bpftool_once_attr()
+{
+local w idx found
+for w in $*; do
+found=0
+for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
+if [[ $w == ${words[idx]} ]]; then
+found=1
+break
+fi
+done
+[[ $found -eq 0 ]] && \
+COMPREPLY+=( $( compgen -W "$w" -- "$cur" ) )
+done
+}
+
+# Takes a list of words in argument; adds them all to COMPREPLY if none of them
+# is already present on the command line. Returns no value.
+_bpftool_one_of_list()
+{
+local w idx
+for w in $*; do
+for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
+[[ $w == ${words[idx]} ]] && return 1
+done
+done
+COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) )
+}
+
+_bpftool_get_map_ids()
+{
+COMPREPLY+=( $( compgen -W "$( bpftool -jp map  2>&1 | \
+command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
+}
+
+_bpftool_get_prog_ids()
+{
+COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
+command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
+}
+
+_bpftool_get_prog_tags()
+{
+COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
+command sed -n 

[PATCH net-next] tools: bpftool: add bash completion for bpftool

2017-10-26 Thread Jakub Kicinski
From: Quentin Monnet 

Add a completion file for bash. The completion function runs bpftool
when needed, making it smart enough to help users complete ids or tags
for eBPF programs and maps currently on the system.

Update Makefile to install completion file to
/usr/share/bash-completion/completions when running `make install`.

Emacs file mode and (at the end) Vim modeline have been added, to keep
the style in use for most existing bash completion files. In this, it
differs from tools/perf/perf-completion.sh, which seems to be the only
other completion file among the kernel sources repository. This is also
valid for indent style: 4-space indents, as in other completion files.

Signed-off-by: Quentin Monnet 
Signed-off-by: Jakub Kicinski 
---
CCing LKML for wider input on whether editor tags in completion 
files under tools/ are OK.

 tools/bpf/bpftool/Makefile|   3 +
 tools/bpf/bpftool/bash-completion/bpftool | 354 ++
 2 files changed, 357 insertions(+)
 create mode 100644 tools/bpf/bpftool/bash-completion/bpftool

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 4f339824ca57..813826c50936 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -46,6 +46,7 @@ $(LIBBPF): FORCE
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
 
 prefix = /usr
+bash_compdir ?= $(prefix)/share/bash-completion/completions
 
 CC = gcc
 
@@ -76,6 +77,8 @@ clean: $(LIBBPF)-clean
 
 install:
install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
+   install -m 0755 -d $(bash_compdir)
+   install -m 0644 bash-completion/bpftool $(bash_compdir)
 
 doc:
$(Q)$(MAKE) -C Documentation/
diff --git a/tools/bpf/bpftool/bash-completion/bpftool 
b/tools/bpf/bpftool/bash-completion/bpftool
new file mode 100644
index ..7febee05c8e7
--- /dev/null
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -0,0 +1,354 @@
+# bpftool(8) bash completion   -*- shell-script -*-
+#
+# Copyright (C) 2017 Netronome Systems, Inc.
+#
+# This software is dual licensed under the GNU General License
+# Version 2, June 1991 as shown in the file COPYING in the top-level
+# directory of this source tree or the BSD 2-Clause License provided
+# below.  You have the option to license this software under the
+# complete terms of either license.
+#
+# The BSD 2-Clause License:
+#
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+#
+#  1. Redistributions of source code must retain the above
+# copyright notice, this list of conditions and the following
+# disclaimer.
+#
+#  2. Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+# Author: Quentin Monnet 
+
+# Takes a list of words in argument; each one of them is added to COMPREPLY if
+# it is not already present on the command line. Returns no value.
+_bpftool_once_attr()
+{
+local w idx found
+for w in $*; do
+found=0
+for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
+if [[ $w == ${words[idx]} ]]; then
+found=1
+break
+fi
+done
+[[ $found -eq 0 ]] && \
+COMPREPLY+=( $( compgen -W "$w" -- "$cur" ) )
+done
+}
+
+# Takes a list of words in argument; adds them all to COMPREPLY if none of them
+# is already present on the command line. Returns no value.
+_bpftool_one_of_list()
+{
+local w idx
+for w in $*; do
+for (( idx=3; idx < ${#words[@]}-1; idx++ )); do
+[[ $w == ${words[idx]} ]] && return 1
+done
+done
+COMPREPLY+=( $( compgen -W "$*" -- "$cur" ) )
+}
+
+_bpftool_get_map_ids()
+{
+COMPREPLY+=( $( compgen -W "$( bpftool -jp map  2>&1 | \
+command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
+}
+
+_bpftool_get_prog_ids()
+{
+COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
+command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
+}
+
+_bpftool_get_prog_tags()
+{
+COMPREPLY+=( $( compgen -W "$( bpftool -jp prog 2>&1 | \
+command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ) )
+}
+
+# For bpftool map update: retrieve type of the map to update.