libbpf-tools: update fsdist for libbpf 1.0
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 17 Dec 2021 22:23:14 +0000 (14:23 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 20 Dec 2021 21:21:26 +0000 (13:21 -0800)
Switch to libbpf 1.0 mode and adapt libbpf API usage accordingly.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
libbpf-tools/fsdist.c

index 3dc8eefe57d463e965b2161c60609775c14939cc..4fb405db215228291e3a3bcdac213b25723690a9 100644 (file)
@@ -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");