Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
39 lines
779 B
C
39 lines
779 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2022 Google */
|
|
#include <vmlinux.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
int terminate_early = 0;
|
|
u64 terminal_cgroup = 0;
|
|
|
|
static inline u64 cgroup_id(struct cgroup *cgrp)
|
|
{
|
|
return cgrp->kn->id;
|
|
}
|
|
|
|
SEC("iter/cgroup")
|
|
int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
|
|
{
|
|
struct seq_file *seq = ctx->meta->seq;
|
|
struct cgroup *cgrp = ctx->cgroup;
|
|
|
|
/* epilogue */
|
|
if (cgrp == NULL) {
|
|
BPF_SEQ_PRINTF(seq, "epilogue\n");
|
|
return 0;
|
|
}
|
|
|
|
/* prologue */
|
|
if (ctx->meta->seq_num == 0)
|
|
BPF_SEQ_PRINTF(seq, "prologue\n");
|
|
|
|
BPF_SEQ_PRINTF(seq, "%8llu\n", cgroup_id(cgrp));
|
|
|
|
if (terminal_cgroup == cgroup_id(cgrp))
|
|
return 1;
|
|
|
|
return terminate_early ? 1 : 0;
|
|
}
|