samples: bpf: Refactor task_fd_query program with libbpf
authorDaniel T. Lee <danieltimlee@gmail.com>
Tue, 24 Nov 2020 09:03:06 +0000 (09:03 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 27 Nov 2020 03:33:35 +0000 (19:33 -0800)
commit4fe6641526dbee115d9d037e94a344f4f448aaa4
treeb96f1888c4586c54e1e5c9f17ccce26496d75966
parentd89af13c92056c46dfc4bcb3d90efe88937c3381
samples: bpf: Refactor task_fd_query program with libbpf

This commit refactors the existing kprobe program with libbpf bpf
loader. To attach bpf program, this uses generic bpf_program__attach()
approach rather than using bpf_load's load_bpf_file().

To attach bpf to perf_event, instead of using previous ioctl method,
this commit uses bpf_program__attach_perf_event since it manages the
enable of perf_event and attach of BPF programs to it, which is much
more intuitive way to achieve.

Also, explicit close(fd) has been removed since event will be closed
inside bpf_link__destroy() automatically.

Furthermore, to prevent conflict of same named uprobe events, O_TRUNC
flag has been used to clear 'uprobe_events' interface.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201124090310.24374-4-danieltimlee@gmail.com
samples/bpf/Makefile
samples/bpf/task_fd_query_user.c