linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] trace-cmd: Fix trace-cmd convert
@ 2022-06-15  2:54 Steven Rostedt
  2022-06-15  2:54 ` [PATCH 1/2] trace-cmd library: Fail if tracecmd_init_data() fails Steven Rostedt
  2022-06-15  2:54 ` [PATCH 2/2] trace-cmd library: Fix reading of temp file used to decompress Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-06-15  2:54 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] trace-cmd library: Fail if tracecmd_init_data() fails
  2022-06-15  2:54 [PATCH 0/2] trace-cmd: Fix trace-cmd convert Steven Rostedt
@ 2022-06-15  2:54 ` Steven Rostedt
  2022-06-15  2:54 ` [PATCH 2/2] trace-cmd library: Fix reading of temp file used to decompress Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-06-15  2:54 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (Google)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 11c0057589b6..c181c7d93be4 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -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 */
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] trace-cmd library: Fix reading of temp file used to decompress
  2022-06-15  2:54 [PATCH 0/2] trace-cmd: Fix trace-cmd convert Steven Rostedt
  2022-06-15  2:54 ` [PATCH 1/2] trace-cmd library: Fail if tracecmd_init_data() fails Steven Rostedt
@ 2022-06-15  2:54 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-06-15  2:54 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (Google), Johannes Berg

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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.

Reported-by: Johannes Berg <johannes@sipsolutions.net>
Fixes: add83e0c8b51 ("trace-cmd library: Fix tracecmd_read_at()")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index c181c7d93be4..0fef2ca7bb70 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -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;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-15  2:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15  2:54 [PATCH 0/2] trace-cmd: Fix trace-cmd convert Steven Rostedt
2022-06-15  2:54 ` [PATCH 1/2] trace-cmd library: Fail if tracecmd_init_data() fails Steven Rostedt
2022-06-15  2:54 ` [PATCH 2/2] trace-cmd library: Fix reading of temp file used to decompress Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).