diff mbox series

[bpf-next,5/5] tools/bpftool: add documentation and bash-completion for `link detach`

Message ID 20200729230520.693207-6-andriin@fb.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series BPF link force-detach support | expand

Commit Message

Andrii Nakryiko July 29, 2020, 11:05 p.m. UTC
Add info on link detach sub-command to man page. Add detach to bash-completion
as well.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/bpf/bpftool/Documentation/bpftool-link.rst | 8 ++++++++
 tools/bpf/bpftool/bash-completion/bpftool        | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

Comments

Song Liu July 30, 2020, 9:13 p.m. UTC | #1
> On Jul 29, 2020, at 4:05 PM, Andrii Nakryiko <andriin@fb.com> wrote:
> 
> Add info on link detach sub-command to man page. Add detach to bash-completion
> as well.
> 
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>

Acked-by: Song Liu <songliubraving@fb.com>

With one nitpick below. 

> ---

[...]

> @@ -49,6 +50,13 @@ DESCRIPTION
> 		  contain a dot character ('.'), which is reserved for future
> 		  extensions of *bpffs*.
> 
> +	**bpftool link detach** *LINK*
> +		  Force-detach link *LINK*. BPF link and its underlying BPF
> +		  program will stay valid, but they will be detached from the
> +		  respective BPF hook and BPF link will transition into
> +		  a defunct state until last open file descriptor for that

Shall we say "a defunct state when the last open file descriptor for that..."?


> +		  link is closed.
> +
> 	**bpftool link help**
> 		  Print short help message.
> 

[...]
Andrii Nakryiko July 30, 2020, 9:16 p.m. UTC | #2
On Thu, Jul 30, 2020 at 2:13 PM Song Liu <songliubraving@fb.com> wrote:
>
>
>
> > On Jul 29, 2020, at 4:05 PM, Andrii Nakryiko <andriin@fb.com> wrote:
> >
> > Add info on link detach sub-command to man page. Add detach to bash-completion
> > as well.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> Acked-by: Song Liu <songliubraving@fb.com>
>
> With one nitpick below.
>
> > ---
>
> [...]
>
> > @@ -49,6 +50,13 @@ DESCRIPTION
> >                 contain a dot character ('.'), which is reserved for future
> >                 extensions of *bpffs*.
> >
> > +     **bpftool link detach** *LINK*
> > +               Force-detach link *LINK*. BPF link and its underlying BPF
> > +               program will stay valid, but they will be detached from the
> > +               respective BPF hook and BPF link will transition into
> > +               a defunct state until last open file descriptor for that
>
> Shall we say "a defunct state when the last open file descriptor for that..."?


No-no, it is in defunc state between LINK_DETACH and last FD being
closed. Once last FD is closed, BPF link will get destructed and freed
in kernel. So I think until is more precise here?

>
>
> > +               link is closed.
> > +
> >       **bpftool link help**
> >                 Print short help message.
> >
>
> [...]
Song Liu July 30, 2020, 9:50 p.m. UTC | #3
> On Jul 30, 2020, at 2:16 PM, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
> 
> On Thu, Jul 30, 2020 at 2:13 PM Song Liu <songliubraving@fb.com> wrote:
>> 
>> 
>> 
>>> On Jul 29, 2020, at 4:05 PM, Andrii Nakryiko <andriin@fb.com> wrote:
>>> 
>>> Add info on link detach sub-command to man page. Add detach to bash-completion
>>> as well.
>>> 
>>> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>> 
>> Acked-by: Song Liu <songliubraving@fb.com>
>> 
>> With one nitpick below.
>> 
>>> ---
>> 
>> [...]
>> 
>>> @@ -49,6 +50,13 @@ DESCRIPTION
>>>                contain a dot character ('.'), which is reserved for future
>>>                extensions of *bpffs*.
>>> 
>>> +     **bpftool link detach** *LINK*
>>> +               Force-detach link *LINK*. BPF link and its underlying BPF
>>> +               program will stay valid, but they will be detached from the
>>> +               respective BPF hook and BPF link will transition into
>>> +               a defunct state until last open file descriptor for that
>> 
>> Shall we say "a defunct state when the last open file descriptor for that..."?
> 
> 
> No-no, it is in defunc state between LINK_DETACH and last FD being
> closed. Once last FD is closed, BPF link will get destructed and freed
> in kernel. So I think until is more precise here?

Ah, I see. I misunderstood "defunct state". Please ignore the comment. 

Thanks,
Song
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/Documentation/bpftool-link.rst b/tools/bpf/bpftool/Documentation/bpftool-link.rst
index 38b0949a185b..4a52e7a93339 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-link.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-link.rst
@@ -21,6 +21,7 @@  LINK COMMANDS
 
 |	**bpftool** **link { show | list }** [*LINK*]
 |	**bpftool** **link pin** *LINK* *FILE*
+|	**bpftool** **link detach *LINK*
 |	**bpftool** **link help**
 |
 |	*LINK* := { **id** *LINK_ID* | **pinned** *FILE* }
@@ -49,6 +50,13 @@  DESCRIPTION
 		  contain a dot character ('.'), which is reserved for future
 		  extensions of *bpffs*.
 
+	**bpftool link detach** *LINK*
+		  Force-detach link *LINK*. BPF link and its underlying BPF
+		  program will stay valid, but they will be detached from the
+		  respective BPF hook and BPF link will transition into
+		  a defunct state until last open file descriptor for that
+		  link is closed.
+
 	**bpftool link help**
 		  Print short help message.
 
diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index 257fa310ea2b..f53ed2f1a4aa 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -1122,7 +1122,7 @@  _bpftool()
             ;;
         link)
             case $command in
-                show|list|pin)
+                show|list|pin|detach)
                     case $prev in
                         id)
                             _bpftool_get_link_ids
@@ -1139,7 +1139,7 @@  _bpftool()
                     COMPREPLY=( $( compgen -W "$LINK_TYPE" -- "$cur" ) )
                     return 0
                     ;;
-                pin)
+                pin|detach)
                     if [[ $prev == "$command" ]]; then
                         COMPREPLY=( $( compgen -W "$LINK_TYPE" -- "$cur" ) )
                     else