Commit a6e130c4 authored by Quentin Monnet's avatar Quentin Monnet Committed by Alexei Starovoitov

libbpf: refactor bpf_*_get_next_id() functions

In preparation for the introduction of a similar function for retrieving
the id of the next BTF object, consolidate the code from
bpf_prog_get_next_id() and bpf_map_get_next_id() in libbpf.
Signed-off-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent d2648e1e
...@@ -568,7 +568,7 @@ int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr) ...@@ -568,7 +568,7 @@ int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr)
return ret; return ret;
} }
int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id) static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd)
{ {
union bpf_attr attr; union bpf_attr attr;
int err; int err;
...@@ -576,26 +576,21 @@ int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id) ...@@ -576,26 +576,21 @@ int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id)
memset(&attr, 0, sizeof(attr)); memset(&attr, 0, sizeof(attr));
attr.start_id = start_id; attr.start_id = start_id;
err = sys_bpf(BPF_PROG_GET_NEXT_ID, &attr, sizeof(attr)); err = sys_bpf(cmd, &attr, sizeof(attr));
if (!err) if (!err)
*next_id = attr.next_id; *next_id = attr.next_id;
return err; return err;
} }
int bpf_map_get_next_id(__u32 start_id, __u32 *next_id) int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id)
{ {
union bpf_attr attr; return bpf_obj_get_next_id(start_id, next_id, BPF_PROG_GET_NEXT_ID);
int err; }
memset(&attr, 0, sizeof(attr));
attr.start_id = start_id;
err = sys_bpf(BPF_MAP_GET_NEXT_ID, &attr, sizeof(attr));
if (!err)
*next_id = attr.next_id;
return err; int bpf_map_get_next_id(__u32 start_id, __u32 *next_id)
{
return bpf_obj_get_next_id(start_id, next_id, BPF_MAP_GET_NEXT_ID);
} }
int bpf_prog_get_fd_by_id(__u32 id) int bpf_prog_get_fd_by_id(__u32 id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment