Skip to contentSkip to conversation

trace-cmd: Fix trace-cmd convert

PATCH New Steven Rostedt 1 participant 3 messages Jun 15, 2022

lore
Share & tools
lore
#0 lore raw

cover trace-cmd: Fix trace-cmd convert

From: "Steven Rostedt (Google)" <[email protected]>

When fixing tracecmd_read_at() the convert command was broken. This was due to it using the temp file and not the zpage. The offsets were not accounted for in this path. trace-cmd convert uses the temp files and not the zpage so it was a casualty of the situation.

Steven Rostedt (Google) (2):
trace-cmd library: Fail if tracecmd_init_data() fails trace-cmd library: Fix reading of temp file used to decompress

 lib/trace-cmd/trace-input.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/2 trace-cmd library: Fail if tracecmd_init_data() fails

From: "Steven Rostedt (Google)" <[email protected]>

If the initialization of tracecmd_init_data() fails, the processing will continue and this can cause errors latter on that are unrelated to the actual problem. Fail immediately instead.

---
 lib/trace-cmd/trace-input.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/trace-cmd/trace-input.c +4 -2
index 11c0057589b6..c181c7d93be4 100644
@@ -5382,12 +5382,14 @@ static int copy_trace_data_from_v6(struct tracecmd_input *in_handle,
 static int copy_trace_data_from_v7(struct tracecmd_input *in_handle,
 				   struct tracecmd_output *out_handle)
 {
-	int ret = 0;
+	int ret;
 	int i;
 
 	/* Force using temporary files for trace data decompression */
 	in_handle->read_zpage = false;
-	tracecmd_init_data(in_handle);
+	ret = tracecmd_init_data(in_handle);
+	if (ret < 0)
+		return ret;
 	tracecmd_set_out_clock(out_handle, in_handle->trace_clock);
 
 	/* copy top buffer */
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/2 trace-cmd library: Fix reading of temp file used to decompress

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

When not using read_zpage, and reading from a temporary file, the offsets are not accounted for properly. That is, it uses the offset of the location of the trace.dat file to map the temporary file (that starts at offset zero).

Account for mapping of the temporary file when appropriate.

Fixes add83e0c8b51 ("trace-cmd library: Fix tracecmd_read_at()")
---
 lib/trace-cmd/trace-input.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
lib/trace-cmd/trace-input.c +8 -6
index c181c7d93be4..0fef2ca7bb70 100644
@@ -1401,8 +1401,11 @@ static void *allocate_page_map(struct tracecmd_input *handle,
 	int ret;
 	int fd;
 
-	if (handle->cpu_compressed && handle->read_zpage)
-		return read_zpage(handle, cpu, offset);
+	if (handle->cpu_compressed) {
+		if (handle->read_zpage)
+			return read_zpage(handle, cpu, offset);
+		offset -= cpu_data->file_offset;
+	}
 
 	if (handle->read_page) {
 		map = malloc(handle->page_size);
@@ -1419,7 +1422,7 @@ static void *allocate_page_map(struct tracecmd_input *handle,
 	map_size = handle->page_map_size;
 	map_offset = offset & ~(map_size - 1);
 
-	if (map_offset < cpu_data->file_offset) {
+	if (!handle->cpu_compressed && map_offset < cpu_data->file_offset) {
 		map_size -= cpu_data->file_offset - map_offset;
 		map_offset = cpu_data->file_offset;
 	}
@@ -1442,10 +1445,9 @@ static void *allocate_page_map(struct tracecmd_input *handle,
 		map_size -= map_offset + map_size -
 			(cpu_data->file_offset + cpu_data->file_size);
 
-	if (cpu_data->compress.fd >= 0) {
-		map_offset -= cpu_data->file_offset;
+	if (cpu_data->compress.fd >= 0)
 		fd = cpu_data->compress.fd;
-	} else
+	else
 		fd = handle->fd;
  again:
 	page_map->size = map_size;
Signature · 1 line
2.35.1