diff options
author | Martin Kelly <martin.kelly@crowdstrike.com> | 2023-09-26 00:50:44 +0300 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2023-09-26 02:22:43 +0300 |
commit | 16058ff28b7eedd62f1643beb841e3bd611674fe (patch) | |
tree | 0b419a0d7d89786071693e3fac64782d61c25706 /tools/lib/bpf/ringbuf.c | |
parent | 6e38ba5291f9e082f9472a8ef682dc54cff0b3e4 (diff) | |
download | linux-16058ff28b7eedd62f1643beb841e3bd611674fe.tar.xz |
libbpf: Add ring__consume
Add ring__consume to consume a single ringbuffer, analogous to
ring_buffer__consume.
Signed-off-by: Martin Kelly <martin.kelly@crowdstrike.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230925215045.2375758-14-martin.kelly@crowdstrike.com
Diffstat (limited to 'tools/lib/bpf/ringbuf.c')
-rw-r--r-- | tools/lib/bpf/ringbuf.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 8aec20216b7b..aacb64278a01 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -371,6 +371,17 @@ int ring__map_fd(const struct ring *r) return r->map_fd; } +int ring__consume(struct ring *r) +{ + int64_t res; + + res = ringbuf_process_ring(r); + if (res < 0) + return libbpf_err(res); + + return res > INT_MAX ? INT_MAX : res; +} + static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb) { if (rb->consumer_pos) { |