Skip to content

Commit

Permalink
libbpf-tools: update fsdist for libbpf 1.0
Browse files Browse the repository at this point in the history
Switch to libbpf 1.0 mode and adapt libbpf API usage accordingly.

Signed-off-by: Andrii Nakryiko <[email protected]>
  • Loading branch information
anakryiko committed Dec 20, 2021
1 parent e6d1512 commit 2158665
Showing 1 changed file with 12 additions and 26 deletions.
38 changes: 12 additions & 26 deletions libbpf-tools/fsdist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 2158665

Please sign in to comment.