[PATCH bpf-next v2 11/14] libbpf: add ring__map_fd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add ring__map_fd to get the file descriptor underlying a given
ringbuffer.

Signed-off-by: Martin Kelly <martin.kelly@xxxxxxxxxxxxxxx>
---
 tools/lib/bpf/libbpf.h   | 9 +++++++++
 tools/lib/bpf/libbpf.map | 1 +
 tools/lib/bpf/ringbuf.c  | 5 +++++
 3 files changed, 15 insertions(+)

diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 53e2a645c560..114e306c6507 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1303,6 +1303,15 @@ LIBBPF_API size_t ring__avail_data_size(const struct ring *r);
  */
 LIBBPF_API size_t ring__size(const struct ring *r);
 
+/**
+ * @brief **ring__map_fd()** returns the file descriptor underlying the given
+ * ringbuffer.
+ *
+ * @param r A ringbuffer object.
+ * @return The underlying ringbuffer file descriptor
+ */
+LIBBPF_API int ring__map_fd(const struct ring *r);
+
 struct user_ring_buffer_opts {
 	size_t sz; /* size of this struct, for forward/backward compatibility */
 };
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index a116d0bb3c5d..1b4225327ab6 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -402,6 +402,7 @@ LIBBPF_1.3.0 {
 		bpf_program__attach_uprobe_multi;
 		ring__avail_data_size;
 		ring__consumer_pos;
+		ring__map_fd;
 		ring__producer_pos;
 		ring__size;
 		ring_buffer__ring;
diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c
index 98d0767dbb50..8aec20216b7b 100644
--- a/tools/lib/bpf/ringbuf.c
+++ b/tools/lib/bpf/ringbuf.c
@@ -366,6 +366,11 @@ size_t ring__size(const struct ring *r)
 	return r->mask + 1;
 }
 
+int ring__map_fd(const struct ring *r)
+{
+	return r->map_fd;
+}
+
 static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb)
 {
 	if (rb->consumer_pos) {
-- 
2.34.1





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux