diff options
author | Quentin Monnet <quentin.monnet@netronome.com> | 2019-08-20 05:31:52 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-08-20 12:51:06 -0400 |
commit | a6e130c4203bcc73450a00f647d99bd75ded95cb (patch) | |
tree | 4c4cd0d9d661d310578123bed3b5169e620a72dd | |
parent | d2648e1ebbceb4da4f2edf5d471963f8831f3554 (diff) |
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: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/lib/bpf/bpf.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index c7d7993c44bb..1439e99c9be5 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -568,7 +568,7 @@ int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr) | |||
568 | return ret; | 568 | return ret; |
569 | } | 569 | } |
570 | 570 | ||
571 | int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id) | 571 | static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd) |
572 | { | 572 | { |
573 | union bpf_attr attr; | 573 | union bpf_attr attr; |
574 | int err; | 574 | int err; |
@@ -576,26 +576,21 @@ int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id) | |||
576 | memset(&attr, 0, sizeof(attr)); | 576 | memset(&attr, 0, sizeof(attr)); |
577 | attr.start_id = start_id; | 577 | attr.start_id = start_id; |
578 | 578 | ||
579 | err = sys_bpf(BPF_PROG_GET_NEXT_ID, &attr, sizeof(attr)); | 579 | err = sys_bpf(cmd, &attr, sizeof(attr)); |
580 | if (!err) | 580 | if (!err) |
581 | *next_id = attr.next_id; | 581 | *next_id = attr.next_id; |
582 | 582 | ||
583 | return err; | 583 | return err; |
584 | } | 584 | } |
585 | 585 | ||
586 | int bpf_map_get_next_id(__u32 start_id, __u32 *next_id) | 586 | int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id) |
587 | { | 587 | { |
588 | union bpf_attr attr; | 588 | return bpf_obj_get_next_id(start_id, next_id, BPF_PROG_GET_NEXT_ID); |
589 | int err; | 589 | } |
590 | |||
591 | memset(&attr, 0, sizeof(attr)); | ||
592 | attr.start_id = start_id; | ||
593 | |||
594 | err = sys_bpf(BPF_MAP_GET_NEXT_ID, &attr, sizeof(attr)); | ||
595 | if (!err) | ||
596 | *next_id = attr.next_id; | ||
597 | 590 | ||
598 | return err; | 591 | int bpf_map_get_next_id(__u32 start_id, __u32 *next_id) |
592 | { | ||
593 | return bpf_obj_get_next_id(start_id, next_id, BPF_MAP_GET_NEXT_ID); | ||
599 | } | 594 | } |
600 | 595 | ||
601 | int bpf_prog_get_fd_by_id(__u32 id) | 596 | int bpf_prog_get_fd_by_id(__u32 id) |