Martin Kelly
6413c2d063
libbpf: Add ring__map_fd
...
Add ring__map_fd to get the file descriptor underlying a given
ringbuffer.
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-12-martin.kelly@crowdstrike.com
2023-10-02 11:17:48 -07:00
Martin Kelly
cd3fe56c75
libbpf: Add ring__size
...
Add ring__size to get the total size of a given ringbuffer.
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-10-martin.kelly@crowdstrike.com
2023-10-02 11:17:48 -07:00
Martin Kelly
3e675ed6ab
libbpf: Add ring__avail_data_size
...
Add ring__avail_data_size for querying the currently available data in
the ringbuffer, similar to the BPF_RB_AVAIL_DATA flag in
bpf_ringbuf_query. This is racy during ongoing operations but is still
useful for overall information on how a ringbuffer is behaving.
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-8-martin.kelly@crowdstrike.com
2023-10-02 11:17:48 -07:00
Martin Kelly
2ad16b970a
libbpf: Add ring__producer_pos, ring__consumer_pos
...
Add APIs to get the producer and consumer position for a given
ringbuffer.
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-6-martin.kelly@crowdstrike.com
2023-10-02 11:17:48 -07:00
Martin Kelly
a20576f5f2
libbpf: Add ring_buffer__ring
...
Add a new function ring_buffer__ring, which exposes struct ring * to the
user, representing a single ringbuffer.
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-4-martin.kelly@crowdstrike.com
2023-10-02 11:17:48 -07:00
Martin Kelly
bfa471bc85
libbpf: Switch rings to array of pointers
...
Switch rb->rings to be an array of pointers instead of a contiguous
block. This allows for each ring pointer to be stable after
ring_buffer__add is called, which allows us to expose struct ring * to
the user without gotchas. Without this change, the realloc in
ring_buffer__add could invalidate a struct ring *, making it unsafe to
give to the user.
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-3-martin.kelly@crowdstrike.com
2023-10-02 11:17:48 -07:00
Martin Kelly
64f2b4ab49
libbpf: Refactor cleanup in ring_buffer__add
...
Refactor the cleanup code in ring_buffer__add to use a unified err_out
label. This reduces code duplication, as well as plugging a potential
leak if mmap_sz != (__u64)(size_t)mmap_sz (currently this would miss
unmapping tmp because ringbuf_unmap_ring isn't called).
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-2-martin.kelly@crowdstrike.com
2023-10-02 11:17:48 -07:00