mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-02 14:49:06 +08:00
libbpf: add support for BPF cookie for raw_tp/tp_btf programs
Wire up BPF cookie passing or raw_tp and tp_btf programs, both in low-level and high-level APIs. Acked-by: Stanislav Fomichev <sdf@google.com> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Message-ID: <20240319233852.1977493-5-andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Andrii Nakryiko
parent
cbd6e3596c
commit
f5828cc352
20
src/libbpf.c
20
src/libbpf.c
@@ -12309,13 +12309,19 @@ static int attach_tp(const struct bpf_program *prog, long cookie, struct bpf_lin
|
||||
return libbpf_get_error(*link);
|
||||
}
|
||||
|
||||
struct bpf_link *bpf_program__attach_raw_tracepoint(const struct bpf_program *prog,
|
||||
const char *tp_name)
|
||||
struct bpf_link *
|
||||
bpf_program__attach_raw_tracepoint_opts(const struct bpf_program *prog,
|
||||
const char *tp_name,
|
||||
struct bpf_raw_tracepoint_opts *opts)
|
||||
{
|
||||
LIBBPF_OPTS(bpf_raw_tp_opts, raw_opts);
|
||||
char errmsg[STRERR_BUFSIZE];
|
||||
struct bpf_link *link;
|
||||
int prog_fd, pfd;
|
||||
|
||||
if (!OPTS_VALID(opts, bpf_raw_tracepoint_opts))
|
||||
return libbpf_err_ptr(-EINVAL);
|
||||
|
||||
prog_fd = bpf_program__fd(prog);
|
||||
if (prog_fd < 0) {
|
||||
pr_warn("prog '%s': can't attach before loaded\n", prog->name);
|
||||
@@ -12327,7 +12333,9 @@ struct bpf_link *bpf_program__attach_raw_tracepoint(const struct bpf_program *pr
|
||||
return libbpf_err_ptr(-ENOMEM);
|
||||
link->detach = &bpf_link__detach_fd;
|
||||
|
||||
pfd = bpf_raw_tracepoint_open(tp_name, prog_fd);
|
||||
raw_opts.tp_name = tp_name;
|
||||
raw_opts.cookie = OPTS_GET(opts, cookie, 0);
|
||||
pfd = bpf_raw_tracepoint_open_opts(prog_fd, &raw_opts);
|
||||
if (pfd < 0) {
|
||||
pfd = -errno;
|
||||
free(link);
|
||||
@@ -12339,6 +12347,12 @@ struct bpf_link *bpf_program__attach_raw_tracepoint(const struct bpf_program *pr
|
||||
return link;
|
||||
}
|
||||
|
||||
struct bpf_link *bpf_program__attach_raw_tracepoint(const struct bpf_program *prog,
|
||||
const char *tp_name)
|
||||
{
|
||||
return bpf_program__attach_raw_tracepoint_opts(prog, tp_name, NULL);
|
||||
}
|
||||
|
||||
static int attach_raw_tp(const struct bpf_program *prog, long cookie, struct bpf_link **link)
|
||||
{
|
||||
static const char *const prefixes[] = {
|
||||
|
||||
Reference in New Issue
Block a user