Re: [PATCH bpf-next] bpftool: Skip cgroups removed during cgroup tree walk

From: Quentin Monnet

Date: Wed Nov 11 2026 - 10:57:24 EST


2026-11-11 12:17 UTC+0700 ~ Jonathan Bastari Thamrin via B4 Relay
<devnull+thamrinjonathan.gmail.com@xxxxxxxxxx>
> From: Jonathan Bastari Thamrin <thamrinjonathan@xxxxxxxxx>
>
> When a cgroup is removed after being found by nftw(), open() or
> cgroup_has_attached_progs() in do_show_tree_fn() returns ENOENT.
> This is treated as a fatal error so the walk stops and the rest of
> the tree isn't listed. This is common on systemd hosts as
> transient scopes are created and removed all the time.
>
> With "systemd-run --user --scope true" running in a loop, the walk
> fails within a few hundred runs:
>
> Error: can't query bpf programs attached to /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/run-p126141-i75408.scope: No such file or directory
>
> Treat ENOENT as the cgroup being gone and continue the walk. With
> this patch, 2000 runs in a row complete without error.
>
> Link: https://github.com/libbpf/bpftool/issues/159
> Fixes: 2058b38371d0 ("bpftool: introduce cgroup tree command")
> Signed-off-by: Jonathan Bastari Thamrin <thamrinjonathan@xxxxxxxxx>
> ---
> The ENODEV originally reported in #159 was fixed by 98b303c9bf05
> ("bpftool: Query only cgroup-related attach types"). This fixes the
> ENOENT race that still breaks cgroup tree on bpftool v7.6.0.

Looks good to me, thank you for the fix.

Acked-by: Quentin Monnet <qmo@xxxxxxxxxx>