bpftool: Add BPF_F_QUERY_EFFECTIVE support in bpftool cgroup [show|tree]
Subsystems (4)
PATCH v2 1/1 bpftool: Add BPF_F_QUERY_EFFECTIVE support in bpftool cgroup [show|tree]
With different bpf attach_flags available to attach bpf programs specially with BPF_F_ALLOW_OVERRIDE and BPF_F_ALLOW_MULTI, the list of effective bpf-programs available to any sub-cgroups really needs to be available for easy debugging.
Using BPF_F_QUERY_EFFECTIVE flag, one can get the list of not only attached bpf-programs to a cgroup but also the inherited ones from parent cgroup.
So additional "effective" option is introduced to use BPF_F_QUERY_EFFECTIVE query flag here to list all the effective bpf-programs available for execution at a specified cgroup.
Reused modified test program test_cgroup_attach from tools/testing/selftests/bpf:
# ./test_cgroup_attach
With old bpftool (without 'effective' option)
# bpftool cgroup show /sys/fs/cgroup/cgroup-test-work-dir/cg1/
ID AttachType AttachFlags Name 129 egress multi pkt_cntr_1 130 egress multi pkt_cntr_2
Attached new program pkt_cntr_4 in cg2 gives following:
# bpftool cgroup show /sys/fs/cgroup/cgroup-test-work-dir/cg1/cg2/
ID AttachType AttachFlags Name 131 egress override pkt_cntr_4
And with 'effective' option it shows all effective programs for cg2:
# bpftool cgroup show /sys/fs/cgroup/cgroup-test-work-dir/cg1/cg2/ effective
ID AttachType AttachFlags Name 131 egress override pkt_cntr_4 129 egress override pkt_cntr_1 130 egress override pkt_cntr_2
---
Changelog:
v2:
- Removed global '-e|--effective' query flag
- Added 'effective' option after cgroup path argument as proposed by Jakub
.../bpftool/Documentation/bpftool-cgroup.rst | 17 +++-- tools/bpf/bpftool/bash-completion/bpftool | 15 +++-- tools/bpf/bpftool/cgroup.c | 66 ++++++++++++------- 3 files changed, 66 insertions(+), 32 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-cgroup.rst +13 -4
@@ -20,8 +20,8 @@ SYNOPSIS CGROUP COMMANDS =============== -| **bpftool** **cgroup { show | list }** *CGROUP* -| **bpftool** **cgroup tree** [*CGROUP_ROOT*] +| **bpftool** **cgroup { show | list }** *CGROUP* [**effective**] +| **bpftool** **cgroup tree** [*CGROUP_ROOT*] [**effective**] | **bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*] | **bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG* | **bpftool** **cgroup help**
@@ -35,13 +35,18 @@ CGROUP COMMANDS DESCRIPTION =========== - **bpftool cgroup { show | list }** *CGROUP* + **bpftool cgroup { show | list }** *CGROUP* [**effective**] List all programs attached to the cgroup *CGROUP*. Output will start with program ID followed by attach type, attach flags and program name. - **bpftool cgroup tree** [*CGROUP_ROOT*] + If **effective** is specified, then it retrieves all the + effective programs that will be executed for events within + a cgroup. This includes inherited along with attached ones + to the cgroup. + + **bpftool cgroup tree** [*CGROUP_ROOT*] [**effective**] Iterate over all cgroups in *CGROUP_ROOT* and list all attached programs. If *CGROUP_ROOT* is not specified, bpftool uses cgroup v2 mountpoint.
@@ -50,6 +55,10 @@ DESCRIPTION commands: it starts with absolute cgroup path, followed by program ID, attach type, attach flags and program name. + With **effective** it retrieves all the effective programs + that will be executed for events at each cgroup level as + similar to show/list command output for a cgroup. + **bpftool cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*] Attach program *PROG* to the cgroup *CGROUP* with attach type *ATTACH_TYPE* and optional *ATTACH_FLAGS*.
tools/bpf/bpftool/bash-completion/bpftool +9 -6
@@ -679,12 +679,15 @@ _bpftool() ;; cgroup) case $command in - show|list) - _filedir - return 0 - ;; - tree) - _filedir + show|list|tree) + case $cword in + 3) + _filedir + ;; + 4) + COMPREPLY=( $( compgen -W 'effective' -- "$cur" ) ) + ;; + esac return 0 ;; attach|detach)
tools/bpf/bpftool/cgroup.c +44 -22
126 lines not on this page · raw message
Signature · 1 line
2.17.1
tools/bpf/bpftool/cgroup.c static int show_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type, · line 188
Quoted 4 lines · Takshak Chahande
tools/bpf/bpftool/cgroup.c +2
-1+ cgroup_fd =open (cgroup_path,O_RDONLY );if (cgroup_fd <0 ) { -p_err ("can't open cgroup %s" , argv[1 ]); +p_err ("can't open cgroup %s" , cgroup_path);
AFAICS the bpf tree has not been merged into bpf-next yet, and there will be a conflict here. For no good reason. Please wait, I will post my patch for inclusion when the time is right.
Quoted 2 lines
(quoted diff) +0
-0goto exit; }