diff mbox series

[05/22] external/trace: Fall back to read()

Message ID 20210625061937.47314-6-hegdevasant@linux.vnet.ibm.com
State Accepted
Headers show
Series P9 cleanup and fixes | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (9d52c580d3fabbea6b276b98f925ab0fceebb96c)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Vasant Hegde June 25, 2021, 6:19 a.m. UTC
From: Oliver O'Halloran <oohall@gmail.com>

Not all kernels support mmap() on an OPAL exported memory range. Fall
back to allocating a buffer and using the normal file IO system calls
to read the contents of the trace buffer in those cases.

This does mean we can't use "follow" mode since we can't monitor the
raw trace data effectively, but otherwise it works fine.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 external/trace/dump_trace.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/external/trace/dump_trace.c b/external/trace/dump_trace.c
index aba684b5b..5a832c791 100644
--- a/external/trace/dump_trace.c
+++ b/external/trace/dump_trace.c
@@ -261,6 +261,7 @@  int main(int argc, char *argv[])
 {
 	struct trace_reader *trs;
 	struct trace_info *ti;
+	bool no_mmap = false;
 	struct stat sb;
 	int fd, opt, i;
 
@@ -296,13 +297,26 @@  int main(int argc, char *argv[])
 			err(1, "Stating %s", argv[1]);
 
 		ti = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-		if (ti == MAP_FAILED)
-			err(1, "Mmaping %s", argv[i]);
+		if (ti == MAP_FAILED) {
+			no_mmap = true;
+
+			ti = ezalloc(sb.st_size);
+			if (!ti)
+				err(1, "allocating memory for %s", argv[i]);
+
+			if (read(fd, ti, sb.st_size) == -1)
+				err(1, "reading from %s", argv[i]);
+		}
 
 		trs[i].tb = &ti->tb;
 		list_head_init(&trs[i].traces);
 	}
 
+	if (no_mmap) {
+		fprintf(stderr, "disabling follow mode: can't mmap() OPAL export files\n");
+		follow = 0;
+	}
+
 	do {
 		load_traces(trs, argc);
 		display_traces(trs, argc);