diff mbox series

[01/10] external/trace: Fall back to read()

Message ID 20201012025314.1070230-1-oohall@gmail.com
State New
Headers show
Series [01/10] external/trace: Fall back to read() | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (f901fcafae14d38e29f1cc11440086ee678785d0)
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

Oliver O'Halloran Oct. 12, 2020, 2:53 a.m. UTC
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 aba684b5b8b1..5a832c791fb6 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);