perf data: Clean up use_stdio and structures
Ian Rogers
reviewerPATCH v2 1/1 perf data: Clean up use_stdio and structures
use_stdio was associated with struct perf_data and not perf_data_file meaning there was implicit use of fd rather than fptr that may not be safe. For example, in perf_data_file__write. Reorganize perf_data_file to better abstract use_stdio, add kernel-doc and more consistently use perf_data__ accessors so that use_stdio is better respected.
---
v2: Sashiko pointed out that fseek differs in result to lseek, fix.
--- tools/perf/builtin-inject.c | 7 ++-- tools/perf/builtin-record.c | 10 +++-- tools/perf/tests/topology.c | 3 +- tools/perf/util/data.c | 83 ++++++++++++++++++++++++------------- tools/perf/util/data.h | 52 +++++++++++++++++++---- tools/perf/util/session.c | 2 +- 6 files changed, 111 insertions(+), 46 deletions(-)
tools/perf/builtin-inject.c +3 -4
@@ -270,9 +270,8 @@ static s64 perf_event__repipe_auxtrace(const struct perf_tool *tool, inject->have_auxtrace = true;if (!inject->output.is_pipe) { -off_t offset; +off_t offset =perf_data__seek (&inject->output,0 ,SEEK_CUR ); - offset =lseek (inject->output.file.fd,0 ,SEEK_CUR );if (offset ==-1 )return -errno; ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
@@ -2479,12 +2478,12 @@ int cmd_inject(int argc, const char **argv) .output = { .path = "-", .mode = PERF_DATA_MODE_WRITE, - .use_stdio = true, + .file.use_stdio = true, }, };struct perf_data data = { .mode =PERF_DATA_MODE_READ , - .use_stdio = true, + .file.use_stdio = true, };int ret;const char *known_build_ids =NULL ;
tools/perf/builtin-record.c +6 -4
@@ -453,7 +453,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t sizestatic int record__aio_push (struct record *rec,struct mmap *map,off_t *off) {int ret, idx; -int trace_fd = rec->session->data->file.fd; +int trace_fd =perf_data__fd (rec->session->data);struct record_aio aio = { .rec = rec, .size =0 };/*
@@ -1640,7 +1640,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,int rc =0 ;int nr_mmaps;struct mmap **maps; -int trace_fd = rec->data.file.fd; +int trace_fd =perf_data__fd (&rec->data);off_t off =0 ;if (!evlist)
@@ -1847,8 +1847,10 @@ record__finish_output(struct record *rec) rec->session->header.data_size += rec->bytes_written; data->file.size =lseek (perf_data__fd (data),0 ,SEEK_CUR );if (record__threads_enabled (rec)) { -for (i =0 ; i < data->dir.nr; i++) - data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); +for (i =0 ; i < data->dir.nr; i++) { + data->dir.files[i].size = +perf_data_file__seek (&data->dir.files[i],0 ,SEEK_CUR ); + } }/* Buildid scanning disabled or build ID in kernel and synthesized map events. */
tools/perf/tests/topology.c +2 -1
@@ -54,7 +54,8 @@ static int session_write_header(char *path) session->header.data_size +=DATA_SIZE ;TEST_ASSERT_VAL ("failed to write header" , - !perf_session__write_header (session, session->evlist, data.file.fd, true)); + !perf_session__write_header (session, session->evlist, +perf_data__fd (&data), true));evlist__delete (session->evlist);perf_session__delete (session);
tools/perf/util/data.c +55 -28
154 lines not on this page · raw message
tools/perf/util/data.h +44 -8
102 lines not on this page · raw message
tools/perf/util/session.c +1 -1
@@ -2569,7 +2569,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)if (!data->dir.files[i].size)continue ; rd[readers] = (struct reader ) { - .fd = data->dir.files[i].fd, + .fd =perf_data_file__fd (&data->dir.files[i]), .path = data->dir.files[i].path, .data_size = data->dir.files[i].size, .data_offset =0 ,
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
[email protected]
AI reviewSashiko AI review found 3 potential issue(s): - [High] Uninitialized `use_stdio` flag in `perf_data__open_dir` leads to undefined behavior and potential segmentation faults. - [High]…
Sashiko AI review found 3 potential issue(s):
- [High] Uninitialized use_stdio flag in perf_data__open_dir leads to undefined behavior and potential segmentation faults.
- [High] perf_data__seek triggers an assertion failure when attempting to switch output on a pipe.
- [High] Unchecked fptr in perf_data_file__close leads to fclose(NULL) (segmentation fault) on error paths.
--
commit ec97569bb8fdfc232fc8bacde6d26424b25c9ef5
Author: Ian Rogers <[email protected]>
perf data: Clean up use_stdio and structures
use_stdio was associated with struct perf_data and not perf_data_file meaning there was implicit use of fd rather than fptr that may not be safe. For example, in perf_data_file__write. Reorganize perf_data_file to better abstract use_stdio, add kernel-doc and more consistently use perf_data__ accessors so that use_stdio is better respected.
Quoted 6 lines
tools/perf/util/data.c +0
-0@@ -20,18 +20,30 @@#include "rlimit.h"
tools/perf/util/data.c line 26
Quoted 10 lines
tools/perf/util/data.c +3
-4#include <internal/lib.h> -static void close_dir (struct perf_data_file *files,int nr) +static void perf_data_file__close (struct perf_data_file *file) { -while (--nr >=0 ) { -close (files[nr].fd); -zfree (&files[nr].path); +if (file->use_stdio) { +fclose (file->fptr);
Does this need a check for file->fptr != NULL before calling fclose()?
If a tool initializes its output with .file.use_stdio = true and .file.fptr = NULL (such as inject.output in cmd_inject() when using --in-place), and an error occurs before the file is fully opened, the error path jumps to out_close_output and calls perf_data__close(). This blindly executes fclose(NULL), which will cause a segmentation fault.
Also, since use_stdio is read here, can it contain uninitialized memory?
In perf_data__open_dir(), the files array is dynamically grown using realloc(files, (nr + 1) * sizeof(*files)). When a new struct perf_data_file is appended, its path, fd, and size fields are set, but the newly added use_stdio boolean is never explicitly initialized. Because realloc() does not zero memory, use_stdio will contain uninitialized heap garbage.
When perf_data__close_dir() iterates over the files to close them via this function, it reads this garbage flag. If it evaluates to true, the code incorrectly assumes the file uses stdio and calls fclose(file->fptr). Since fptr is part of a union with fd (or also garbage), this results in an arbitrary pointer dereference and a segmentation fault.
[ ... ]
Quoted 11 lines
tools/perf/util/data.c +6
-0+off_t perf_data__seek (struct perf_data *data,off_t offset,int whence) +{ +assert (!data->is_pipe); +return perf_data_file__seek (&data->file, offset, whence); +} + int perf_data__switch(struct perf_data *data, const char *postfix, size_t pos, bool at_exit,@@ -420,19 +448,18 @@ int perf_data__switch(struct perf_data *data,pr_warning ("Failed to rename %s to %s\n" , data->path, *new_filepath);
tools/perf/util/data.c int perf_data__switch(struct perf_data *data, · line 456
Quoted 10 lines
tools/perf/util/data.c +2
-2if (!at_exit) { -close (data->file.fd); +perf_data_file__close (&data->file); ret =perf_data__open (data);if (ret <0 ) goto out; -if (lseek (data->file.fd, pos,SEEK_SET ) == (off_t)-1 ) { +if (perf_data__seek (data, pos,SEEK_SET ) == (off_t)-1 ) {
Will this assertion crash the tool if a user specifies a pipe for output and triggers an output switch (e.g., perf record -o - --switch-output)?
When the user triggers an output switch, perf_data__switch() re-opens the pipe (correctly setting data->is_pipe = true) and then unconditionally calls perf_data__seek() to restore the offset.
Before this patch, calling lseek() on a pipe simply returned -1 with errno == ESPIPE and the tool handled the error gracefully. The new assertion turns this previously handled error into a hard crash that can be reached directly via user arguments.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerPATCH v3 1/1 perf data: Clean up use_stdio and structures
In reply to Ian Rogersuse_stdio was associated with struct perf_data and not perf_data_file meaning there was implicit use of fd rather than fptr that may not be safe. For example, in perf_data_file__write. Reorganize perf_data_file to better abstract use_stdio, add kernel-doc and more consistently use perf_data__ accessors so that use_stdio is better respected.
---
v2,v3: Sashiko fixes.
--- tools/perf/builtin-inject.c | 7 ++- tools/perf/builtin-record.c | 10 ++-- tools/perf/tests/topology.c | 3 +- tools/perf/util/data.c | 101 +++++++++++++++++++++++------------- tools/perf/util/data.h | 52 ++++++++++++++++--- tools/perf/util/session.c | 2 +- 6 files changed, 120 insertions(+), 55 deletions(-)
tools/perf/builtin-inject.c +3 -4
@@ -270,9 +270,8 @@ static s64 perf_event__repipe_auxtrace(const struct perf_tool *tool, inject->have_auxtrace = true;if (!inject->output.is_pipe) { -off_t offset; +off_t offset =perf_data__seek (&inject->output,0 ,SEEK_CUR ); - offset =lseek (inject->output.file.fd,0 ,SEEK_CUR );if (offset ==-1 )return -errno; ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
@@ -2503,12 +2502,12 @@ int cmd_inject(int argc, const char **argv) .output = { .path = "-", .mode = PERF_DATA_MODE_WRITE, - .use_stdio = true, + .file.use_stdio = true, }, };struct perf_data data = { .mode =PERF_DATA_MODE_READ , - .use_stdio = true, + .file.use_stdio = true, };int ret;const char *known_build_ids =NULL ;
tools/perf/builtin-record.c +6 -4
@@ -453,7 +453,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t sizestatic int record__aio_push (struct record *rec,struct mmap *map,off_t *off) {int ret, idx; -int trace_fd = rec->session->data->file.fd; +int trace_fd =perf_data__fd (rec->session->data);struct record_aio aio = { .rec = rec, .size =0 };/*
@@ -1640,7 +1640,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,int rc =0 ;int nr_mmaps;struct mmap **maps; -int trace_fd = rec->data.file.fd; +int trace_fd =perf_data__fd (&rec->data);off_t off =0 ;if (!evlist)
@@ -1847,8 +1847,10 @@ record__finish_output(struct record *rec) rec->session->header.data_size += rec->bytes_written; data->file.size =lseek (perf_data__fd (data),0 ,SEEK_CUR );if (record__threads_enabled (rec)) { -for (i =0 ; i < data->dir.nr; i++) - data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); +for (i =0 ; i < data->dir.nr; i++) { + data->dir.files[i].size = +perf_data_file__seek (&data->dir.files[i],0 ,SEEK_CUR ); + } }/* Buildid scanning disabled or build ID in kernel and synthesized map events. */
tools/perf/tests/topology.c +2 -1
@@ -54,7 +54,8 @@ static int session_write_header(char *path) session->header.data_size +=DATA_SIZE ;TEST_ASSERT_VAL ("failed to write header" , - !perf_session__write_header (session, session->evlist, data.file.fd, true)); + !perf_session__write_header (session, session->evlist, +perf_data__fd (&data), true));evlist__delete (session->evlist);perf_session__delete (session);
tools/perf/util/data.c +64 -37
179 lines not on this page · raw message
tools/perf/util/data.h +44 -8
102 lines not on this page · raw message
tools/perf/util/session.c +1 -1
@@ -2583,7 +2583,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)if (!data->dir.files[i].size)continue ; rd[readers] = (struct reader ) { - .fd = data->dir.files[i].fd, + .fd =perf_data_file__fd (&data->dir.files[i]), .path = data->dir.files[i].path, .data_size = data->dir.files[i].size, .data_offset =0 ,
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
[email protected]
AI reviewSashiko AI review found 2 potential issue(s): - [High] The newly introduced `perf_data_file__seek` API silently truncates 64-bit file offsets on 32-bit platforms. - [Medium] Missed API conversion in…
Sashiko AI review found 2 potential issue(s):
- [High] The newly introduced perf_data_file__seek API silently truncates 64-bit file offsets on 32-bit platforms.
- [Medium] Missed API conversion in record__finish_output bypasses the new stdio abstraction. --
commit f45ea505995a4b5ea83270dc73763efa7e6f535d
Author: Ian Rogers <[email protected]>
perf data: Clean up use_stdio and structures
This commit reorganizes perf_data_file to better abstract use_stdio, adding new accessors like perf_data_file__seek() to ensure stdio buffering is respected when a file pointer is used instead of a file descriptor.
Quoted 4 lines
tools/perf/builtin-record.c +0
-0
[ ... ]
tools/perf/builtin-record.c record__finish_output(struct record *rec) · line 1848
Quoted 3 lines
tools/perf/builtin-record.c +0
-0@@ -1847,8 +1847,10 @@ record__finish_output(struct record *rec) rec->session->header.data_size += rec->bytes_written; data->file.size =lseek (perf_data__fd (data),0 ,SEEK_CUR );
Should this lseek() also be converted to use perf_data__seek()?
If use_stdio is enabled here, perf_data__fd() will extract the raw file descriptor and lseek() will bypass the stdio buffering. This seems to miss the abstraction introduced in this patch.
Quoted 8 lines
tools/perf/builtin-record.c +4
-2if (record__threads_enabled (rec)) { -for (i =0 ; i < data->dir.nr; i++) - data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); +for (i =0 ; i < data->dir.nr; i++) { + data->dir.files[i].size = +perf_data_file__seek (&data->dir.files[i],0 ,SEEK_CUR ); + } }
[ ... ]
Quoted 4 lines
tools/perf/util/data.c +0
-0
[ ... ]
Quoted 7 lines
ssize_tperf_data__write(structperf_data*data,tools/perf/util/data.c +0
-4void *buf, size_t size) { -if (data->use_stdio) { -if (fwrite (buf, size,1 , data->file.fptr) ==1 ) -return size; -return -1 ;
tools/perf/util/data.c void perf_data__close(struct perf_data *data) · line 419
Quoted 10 lines
tools/perf/util/data.c +6
-1- }return perf_data_file__write (&data->file, buf, size); } +off_t perf_data_file__seek (struct perf_data_file *file,off_t offset,int whence) +{ +if (file->use_stdio) { +off_t res =fseek (file->fptr, offset, whence); + +return res <0 ?-1 :ftell (file->fptr);
Does this silently truncate 64-bit file offsets on 32-bit platforms?
Both fseek() and ftell() operate on the long data type, which is 32 bits on 32-bit architectures. Since the offset parameter and return type are off_t (which is 64-bit when _FILE_OFFSET_BITS=64 is used), shouldn't fseeko() and ftello() be used here instead to correctly support large files?
Quoted 3 lines
tools/perf/util/data.c +3
-0+ } +return lseek (file->fd, offset, whence); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerPATCH v4 1/1 perf data: Clean up use_stdio and structures
In reply to Ian Rogersuse_stdio was associated with struct perf_data and not perf_data_file meaning there was implicit use of fd rather than fptr that may not be safe. For example, in perf_data_file__write. Reorganize perf_data_file to better abstract use_stdio, add kernel-doc and more consistently use perf_data__ accessors so that use_stdio is better respected.
---
v2,v3,v4: Sashiko fixes.
--- tools/perf/builtin-inject.c | 7 ++- tools/perf/builtin-record.c | 12 +++-- tools/perf/tests/topology.c | 3 +- tools/perf/util/data.c | 101 +++++++++++++++++++++++------------- tools/perf/util/data.h | 52 ++++++++++++++++--- tools/perf/util/session.c | 2 +- 6 files changed, 121 insertions(+), 56 deletions(-)
tools/perf/builtin-inject.c +3 -4
@@ -270,9 +270,8 @@ static s64 perf_event__repipe_auxtrace(const struct perf_tool *tool, inject->have_auxtrace = true;if (!inject->output.is_pipe) { -off_t offset; +off_t offset =perf_data__seek (&inject->output,0 ,SEEK_CUR ); - offset =lseek (inject->output.file.fd,0 ,SEEK_CUR );if (offset ==-1 )return -errno; ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
@@ -2503,12 +2502,12 @@ int cmd_inject(int argc, const char **argv) .output = { .path = "-", .mode = PERF_DATA_MODE_WRITE, - .use_stdio = true, + .file.use_stdio = true, }, };struct perf_data data = { .mode =PERF_DATA_MODE_READ , - .use_stdio = true, + .file.use_stdio = true, };int ret;const char *known_build_ids =NULL ;
tools/perf/builtin-record.c +7 -5
@@ -453,7 +453,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t sizestatic int record__aio_push (struct record *rec,struct mmap *map,off_t *off) {int ret, idx; -int trace_fd = rec->session->data->file.fd; +int trace_fd =perf_data__fd (rec->session->data);struct record_aio aio = { .rec = rec, .size =0 };/*
@@ -1640,7 +1640,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,int rc =0 ;int nr_mmaps;struct mmap **maps; -int trace_fd = rec->data.file.fd; +int trace_fd =perf_data__fd (&rec->data);off_t off =0 ;if (!evlist)
@@ -1845,10 +1845,12 @@ record__finish_output(struct record *rec) } rec->session->header.data_size += rec->bytes_written; - data->file.size =lseek (perf_data__fd (data),0 ,SEEK_CUR ); + data->file.size =perf_data__seek (data,0 ,SEEK_CUR );if (record__threads_enabled (rec)) { -for (i =0 ; i < data->dir.nr; i++) - data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); +for (i =0 ; i < data->dir.nr; i++) { + data->dir.files[i].size = +perf_data_file__seek (&data->dir.files[i],0 ,SEEK_CUR ); + } }/* Buildid scanning disabled or build ID in kernel and synthesized map events. */
tools/perf/tests/topology.c +2 -1
@@ -54,7 +54,8 @@ static int session_write_header(char *path) session->header.data_size +=DATA_SIZE ;TEST_ASSERT_VAL ("failed to write header" , - !perf_session__write_header (session, session->evlist, data.file.fd, true)); + !perf_session__write_header (session, session->evlist, +perf_data__fd (&data), true));evlist__delete (session->evlist);perf_session__delete (session);
tools/perf/util/data.c +64 -37
179 lines not on this page · raw message
tools/perf/util/data.h +44 -8
102 lines not on this page · raw message
tools/perf/util/session.c +1 -1
@@ -2583,7 +2583,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)if (!data->dir.files[i].size)continue ; rd[readers] = (struct reader ) { - .fd = data->dir.files[i].fd, + .fd =perf_data_file__fd (&data->dir.files[i]), .path = data->dir.files[i].path, .data_size = data->dir.files[i].size, .data_offset =0 ,
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
[email protected]
AI reviewSashiko AI review found 2 potential issue(s): - [Medium] Incorrect error propagation in `perf_data__open_dir` when file open fails. - [Medium] Incomplete hardening in `perf_data__close_dir`…
Sashiko AI review found 2 potential issue(s):
- [Medium] Incorrect error propagation in perf_data__open_dir when file open fails.
- [Medium] Incomplete hardening in perf_data__close_dir introduces a deterministic null-pointer dereference on double-close. --
commit 4ab46c4d5886980da2c8095f639cfaf305ff9f00
Author: Ian Rogers <[email protected]>
perf data: Clean up use_stdio and structures
This commit reorganizes perf_data_file to better abstract the use of stdio. It updates tools to consistently use perf_data__ accessors, preventing implicit file descriptor usage instead of the intended fptr.
Quoted 5 lines
tools/perf/util/data.c +0
-0@@ -20,18 +20,32 @@
[ ... ]
tools/perf/util/data.c line 49
Quoted 5 lines
void
perf_data__close_dir(struct perf_data *data){tools/perf/util/data.c +1
-0close_dir (data->dir.files, data->dir.nr); + data->dir.files =NULL ; }
Does this introduce a potential crash if the directory is closed twice?
By setting data->dir.files = NULL without also setting data->dir.nr = 0, a second call to perf_data__close_dir() would pass a NULL array with a positive count to close_dir().
Inside close_dir(), the loop while (--nr >= 0) would offset and dereference the NULL pointer when accessing &files[nr]. Should data->dir.nr = 0 also be set here?
[ ... ]
Quoted 12 lines
tools/perf/util/data.c +6
-2@@ -132,16 +146,14 @@ int perf_data__open_dir(struct perf_data *data) files = file; file = &files[nr++]; - file->path =strdup (path); -if (!file->path) + *file = (struct perf_data_file ){ + .path =strdup (path), + .fd =open (path,O_RDONLY ), + .size = st.st_size, + .use_stdio = false, + };
tools/perf/util/data.c int perf_data__open_dir(struct perf_data *data) · line 157
Quoted 10 lines
tools/perf/util/data.c +1
-7+if (!file->path || file->fd <0 ) goto out_err; - - ret =open (file->path,O_RDONLY ); -if (ret <0 ) - goto out_err; - - file->fd = ret; - file->size = st.st_size; }
Is it intentional to return -ENOMEM when open() fails here?
Prior to this change, ret was updated with the result of open() before checking for failure. Now, if file->fd < 0 triggers the goto out_err path, ret still holds -ENOMEM from the realloc() step earlier in the loop. This might provide a misleading error code to the caller.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerPATCH v5 1/1 perf data: Clean up use_stdio and structures
In reply to Ian Rogersuse_stdio was associated with struct perf_data and not perf_data_file meaning there was implicit use of fd rather than fptr that may not be safe. For example, in perf_data_file__write. Reorganize perf_data_file to better abstract use_stdio, add kernel-doc and more consistently use perf_data__ accessors so that use_stdio is better respected.
---
v2,v3,v4,v5: Sashiko fixes.
--- tools/perf/builtin-inject.c | 7 ++- tools/perf/builtin-record.c | 12 +++-- tools/perf/tests/topology.c | 3 +- tools/perf/util/data.c | 99 +++++++++++++++++++++++++------------ tools/perf/util/data.h | 52 ++++++++++++++++--- tools/perf/util/session.c | 2 +- 6 files changed, 124 insertions(+), 51 deletions(-)
tools/perf/builtin-inject.c +3 -4
@@ -270,9 +270,8 @@ static s64 perf_event__repipe_auxtrace(const struct perf_tool *tool, inject->have_auxtrace = true;if (!inject->output.is_pipe) { -off_t offset; +off_t offset =perf_data__seek (&inject->output,0 ,SEEK_CUR ); - offset =lseek (inject->output.file.fd,0 ,SEEK_CUR );if (offset ==-1 )return -errno; ret = auxtrace_index__auxtrace_event(&session->auxtrace_index,
@@ -2503,12 +2502,12 @@ int cmd_inject(int argc, const char **argv) .output = { .path = "-", .mode = PERF_DATA_MODE_WRITE, - .use_stdio = true, + .file.use_stdio = true, }, };struct perf_data data = { .mode =PERF_DATA_MODE_READ , - .use_stdio = true, + .file.use_stdio = true, };int ret;const char *known_build_ids =NULL ;
tools/perf/builtin-record.c +7 -5
@@ -453,7 +453,7 @@ static int record__aio_pushfn(struct mmap *map, void *to, void *buf, size_t sizestatic int record__aio_push (struct record *rec,struct mmap *map,off_t *off) {int ret, idx; -int trace_fd = rec->session->data->file.fd; +int trace_fd =perf_data__fd (rec->session->data);struct record_aio aio = { .rec = rec, .size =0 };/*
@@ -1640,7 +1640,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,int rc =0 ;int nr_mmaps;struct mmap **maps; -int trace_fd = rec->data.file.fd; +int trace_fd =perf_data__fd (&rec->data);off_t off =0 ;if (!evlist)
@@ -1845,10 +1845,12 @@ record__finish_output(struct record *rec) } rec->session->header.data_size += rec->bytes_written; - data->file.size =lseek (perf_data__fd (data),0 ,SEEK_CUR ); + data->file.size =perf_data__seek (data,0 ,SEEK_CUR );if (record__threads_enabled (rec)) { -for (i =0 ; i < data->dir.nr; i++) - data->dir.files[i].size =lseek (data->dir.files[i].fd,0 ,SEEK_CUR ); +for (i =0 ; i < data->dir.nr; i++) { + data->dir.files[i].size = +perf_data_file__seek (&data->dir.files[i],0 ,SEEK_CUR ); + } }/* Buildid scanning disabled or build ID in kernel and synthesized map events. */
tools/perf/tests/topology.c +2 -1
@@ -54,7 +54,8 @@ static int session_write_header(char *path) session->header.data_size +=DATA_SIZE ;TEST_ASSERT_VAL ("failed to write header" , - !perf_session__write_header (session, session->evlist, data.file.fd, true)); + !perf_session__write_header (session, session->evlist, +perf_data__fd (&data), true));evlist__delete (session->evlist);perf_session__delete (session);
tools/perf/util/data.c +67 -32
182 lines not on this page · raw message
tools/perf/util/data.h +44 -8
102 lines not on this page · raw message
tools/perf/util/session.c +1 -1
@@ -2583,7 +2583,7 @@ static int __perf_session__process_dir_events(struct perf_session *session)if (!data->dir.files[i].size)continue ; rd[readers] = (struct reader ) { - .fd = data->dir.files[i].fd, + .fd =perf_data_file__fd (&data->dir.files[i]), .path = data->dir.files[i].path, .data_size = data->dir.files[i].size, .data_offset =0 ,
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Quoted 8 lines · Ian Rogers
use_stdiowas associated with structperf_dataand notperf_data_filemeaning there was implicit use of fd rather than fptr that may not be safe. For example, inperf_data_file__write. Reorganizeperf_data_fileto better abstractuse_stdio, add kernel-doc and more consistently useperf_data__accessors so thatuse_stdiois better respected.[...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung