From 21586658c86e1a20e9195d8715d37d714be93bb6 Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Fri, 17 Dec 2021 14:23:14 -0800 Subject: [PATCH] libbpf-tools: update fsdist for libbpf 1.0 Switch to libbpf 1.0 mode and adapt libbpf API usage accordingly. Signed-off-by: Andrii Nakryiko --- libbpf-tools/fsdist.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/libbpf-tools/fsdist.c b/libbpf-tools/fsdist.c index 3dc8eefe..4fb405db 100644 --- a/libbpf-tools/fsdist.c +++ b/libbpf-tools/fsdist.c @@ -300,53 +300,44 @@ static int attach_kprobes(struct fsdist_bpf *obj) /* READ */ obj->links.file_read_entry = bpf_program__attach_kprobe(obj->progs.file_read_entry, false, cfg->op_funcs[READ]); - err = libbpf_get_error(obj->links.file_read_entry); - if (err) + if (!obj->links.file_read_entry) goto errout; obj->links.file_read_exit = bpf_program__attach_kprobe(obj->progs.file_read_exit, true, cfg->op_funcs[READ]); - err = libbpf_get_error(obj->links.file_read_exit); - if (err) + if (!obj->links.file_read_exit) goto errout; /* WRITE */ obj->links.file_write_entry = bpf_program__attach_kprobe(obj->progs.file_write_entry, false, cfg->op_funcs[WRITE]); - err = libbpf_get_error(obj->links.file_write_entry); - if (err) + if (!obj->links.file_write_entry) goto errout; obj->links.file_write_exit = bpf_program__attach_kprobe(obj->progs.file_write_exit, true, cfg->op_funcs[WRITE]); - err = libbpf_get_error(obj->links.file_write_exit); - if (err) + if (!obj->links.file_write_exit) goto errout; /* OPEN */ obj->links.file_open_entry = bpf_program__attach_kprobe(obj->progs.file_open_entry, false, cfg->op_funcs[OPEN]); - err = libbpf_get_error(obj->links.file_open_entry); - if (err) + if (!obj->links.file_open_entry) goto errout; obj->links.file_open_exit = bpf_program__attach_kprobe(obj->progs.file_open_exit, true, cfg->op_funcs[OPEN]); - err = libbpf_get_error(obj->links.file_open_exit); - if (err) + if (!obj->links.file_open_exit) goto errout; /* FSYNC */ obj->links.file_sync_entry = bpf_program__attach_kprobe(obj->progs.file_sync_entry, false, cfg->op_funcs[FSYNC]); - err = libbpf_get_error(obj->links.file_sync_entry); - if (err) + if (!obj->links.file_sync_entry) goto errout; obj->links.file_sync_exit = bpf_program__attach_kprobe(obj->progs.file_sync_exit, true, cfg->op_funcs[FSYNC]); - err = libbpf_get_error(obj->links.file_sync_exit); - if (err) + if (!obj->links.file_sync_exit) goto errout; /* GETATTR */ if (!cfg->op_funcs[GETATTR]) return 0; obj->links.getattr_entry = bpf_program__attach_kprobe(obj->progs.getattr_entry, false, cfg->op_funcs[GETATTR]); - err = libbpf_get_error(obj->links.getattr_entry); - if (err) + if (!obj->links.getattr_entry) goto errout; obj->links.getattr_exit = bpf_program__attach_kprobe(obj->progs.getattr_exit, true, cfg->op_funcs[GETATTR]); - err = libbpf_get_error(obj->links.getattr_exit); - if (err) + if (!obj->links.getattr_exit) goto errout; return 0; errout: + err = -errno; warn("failed to attach kprobe: %ld\n", err); return err; } @@ -374,14 +365,9 @@ int main(int argc, char **argv) return 1; } + libbpf_set_strict_mode(LIBBPF_STRICT_ALL); libbpf_set_print(libbpf_print_fn); - err = bump_memlock_rlimit(); - if (err) { - warn("failed to increase rlimit: %d\n", err); - return 1; - } - skel = fsdist_bpf__open(); if (!skel) { warn("failed to open BPF object\n"); -- 2.34.1