Skip to content

Commit ae76939

Browse files
Martin Kellyanakryiko
authored andcommitted
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
1 parent bb32dd2 commit ae76939

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

tools/lib/bpf/libbpf.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,15 @@ LIBBPF_API size_t ring__avail_data_size(const struct ring *r);
13031303
*/
13041304
LIBBPF_API size_t ring__size(const struct ring *r);
13051305

1306+
/**
1307+
* @brief **ring__map_fd()** returns the file descriptor underlying the given
1308+
* ringbuffer.
1309+
*
1310+
* @param r A ringbuffer object.
1311+
* @return The underlying ringbuffer file descriptor
1312+
*/
1313+
LIBBPF_API int ring__map_fd(const struct ring *r);
1314+
13061315
struct user_ring_buffer_opts {
13071316
size_t sz; /* size of this struct, for forward/backward compatibility */
13081317
};

tools/lib/bpf/libbpf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ LIBBPF_1.3.0 {
402402
bpf_program__attach_uprobe_multi;
403403
ring__avail_data_size;
404404
ring__consumer_pos;
405+
ring__map_fd;
405406
ring__producer_pos;
406407
ring__size;
407408
ring_buffer__ring;

tools/lib/bpf/ringbuf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ size_t ring__size(const struct ring *r)
366366
return r->mask + 1;
367367
}
368368

369+
int ring__map_fd(const struct ring *r)
370+
{
371+
return r->map_fd;
372+
}
373+
369374
static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
370375
{
371376
if (rb->consumer_pos) {

0 commit comments

Comments
 (0)