diff mbox series

[2/7] libtracefs: Have tracefs_mmap_read() include subbuf meta data

Message ID 20240110030116.81837-3-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 2b5bb095dfecb4c7e1623c11892a68c0577f97a2
Headers show
Series libtracefs: More fixes for memory mapping ring buffer API | expand

Commit Message

Steven Rostedt Jan. 10, 2024, 2:51 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The tracefs_cpu_read() returns tracefs_mmap_read() when the tcpu is mapped.
But tracefs_cpu_read() is supposed to return the amount that was read, which
includes the sub-buffer meta data. But kbuffer_read_buffer() only returns
the amount of data that was read and does not include the sub-buffer meta
data.

Fixes: 2ed14b59 ("libtracefs: Add ring buffer memory mapping APIs")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/tracefs-mmap.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/tracefs-mmap.c b/src/tracefs-mmap.c
index 0f90f51e9339..f481bda37eaf 100644
--- a/src/tracefs-mmap.c
+++ b/src/tracefs-mmap.c
@@ -207,5 +207,10 @@  __hidden int trace_mmap_read(void *mapping, void *buffer)
 		return ret;
 
 	/* Update the buffer */
-	return kbuffer_read_buffer(kbuf, buffer, tmap->map->subbuf_size);
+	ret = kbuffer_read_buffer(kbuf, buffer, tmap->map->subbuf_size);
+	if (ret <= 0)
+		return ret;
+
+	/* This needs to include the size of the meta data too */
+	return ret + kbuffer_start_of_data(kbuf);
 }