perf data: Adding error message if perf_data__create_dir fails
PATCH 1/1 perf data: Adding error message if perf_data__create_dir fails
There is no notification about data directory creation failure. Add it.
--- tools/perf/builtin-record.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +3 -1
@@ -1186,8 +1186,10 @@ static int record__mmap_evlist(struct record *rec,if (record__threads_enabled (rec)) { ret =perf_data__create_dir (&rec->data, evlist->core.nr_mmaps); -if (ret) +if (ret) { +pr_err ("Failed to create data directory: %s\n" ,strerror (errno));return ret; + }for (i =0 ; i < evlist->core.nr_mmaps; i++) {if (evlist->mmap) evlist->mmap[i].file = &rec->data.dir.files[i];
Signature · 1 line
2.19.0
PATCH 1/1 perf data: Fix double free in perf_session__delete
When perf_data__create_dir fails, it calls close_dir, but perf_session__delete also calls close_dir and since dir.version and dir.nr was initialized by perf_data__create_dir, a double free occurs. This patch moves the initialization of dir.version and dir.nr after successful initialization of dir.files, that prevents double freeing. This behavior is already implemented in perf_data__open_dir.
--- tools/perf/util/data.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/util/data.c +3 -4
@@ -44,10 +44,6 @@ int perf_data__create_dir(struct perf_data *data, int nr)if (!files)return -ENOMEM ; - data->dir.version =PERF_DIR_VERSION ; - data->dir.files = files; - data->dir.nr = nr; -for (i =0 ; i < nr; i++) {struct perf_data_file *file = &files[i];
@@ -62,6 +58,9 @@ int perf_data__create_dir(struct perf_data *data, int nr) file->fd = ret; } + data->dir.version =PERF_DIR_VERSION ; + data->dir.files = files; + data->dir.nr = nr;return 0 ; out_err:
Signature · 1 line
2.19.0
Re: [PATCH urgent] perf data: Fix double free in perf_session__delete
Quoted 9 lines · Alexey Bayduraev
When
perf_data__create_dirfails, it callsclose_dir, butperf_session__deletealso callsclose_dirand since dir.version and dir.nr was initialized byperf_data__create_dir, a double free occurs. This patch moves the initialization of dir.version and dir.nr after successful initialization of dir.files, that prevents double freeing. This behavior is already implemented inperf_data__open_dir.Fixes 145520631130bd64 ("perf data: Add perf_data__(create_dir|close_dir) functions")Signed-off-by Alexey Bayduraev <[email protected]>
thanks,
jirka
Quoted 32 lines
--- tools/perf/util/data.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)tools/perf/util/data.c +3
-4@@ -44,10 +44,6 @@ int perf_data__create_dir(struct perf_data *data, int nr)if (!files)return -ENOMEM ; - data->dir.version =PERF_DIR_VERSION ; - data->dir.files = files; - data->dir.nr = nr; -for (i =0 ; i < nr; i++) {struct perf_data_file *file = &files[i];@@ -62,6 +58,9 @@ int perf_data__create_dir(struct perf_data *data, int nr) file->fd = ret; } + data->dir.version =PERF_DIR_VERSION ; + data->dir.files = files; + data->dir.nr = nr;return 0 ; out_err:Signature · 1 line
2.19.0
Quoted 12 lines · Alexey Bayduraev
There is no notification about data directory creation failure. Add it.
Signed-off-by Alexey Bayduraev <[email protected]>--- tools/perf/builtin-record.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/perf/builtin-record.c +0
-0
tools/perf/builtin-record.c static int record__mmap_evlist(struct record *rec, · line 1190
Quoted 6 lines
tools/perf/builtin-record.c +2
-1@@ -1186,8 +1186,10 @@ static int record__mmap_evlist(struct record *rec,if (record__threads_enabled (rec)) { ret =perf_data__create_dir (&rec->data, evlist->core.nr_mmaps); -if (ret) +if (ret) { +pr_err ("Failed to create data directory: %s\n" ,strerror (errno));
errno will be misleading in here, because perf_data__create_dir calls other syscalls on error path
jirka
Quoted 8 lines
tools/perf/builtin-record.c +1
-0return ret; + }for (i =0 ; i < evlist->core.nr_mmaps; i++) {if (evlist->mmap) evlist->mmap[i].file = &rec->data.dir.files[i];Signature · 1 line
2.19.0
Quoted 14 lines · Jiri Olsa
Quoted 13 lines · Alexey Bayduraev
There is no notification about data directory creation failure. Add it.
Signed-off-by Alexey Bayduraev <[email protected]>--- tools/perf/builtin-record.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/perf/builtin-record.c +0
-0@@ -1186,8 +1186,10 @@ static int record__mmap_evlist(struct record *rec,
Quoted 8 lines
tools/perf/builtin-record.c static int record__mmap_evlist(struct record *rec, · line 1190
Quoted 5 lines
tools/perf/builtin-record.c +2
-1if (record__threads_enabled (rec)) { ret =perf_data__create_dir (&rec->data, evlist->core.nr_mmaps); -if (ret) +if (ret) { +pr_err ("Failed to create data directory: %s\n" ,strerror (errno));errno will be misleading in here, because
perf_data__create_dircalls other syscalls on error path
Mostly I want to output something like:
Failed to create data dir: Too many open files
This will trigger the user to increase the open files limit. Would it be better to place such message to perf_data__create_dir after open() syscall?
Regards,
Alexey
Quoted 11 lines
jirka
Quoted 8 lines
tools/perf/builtin-record.c +1
-0return ret; + }for (i =0 ; i < evlist->core.nr_mmaps; i++) {if (evlist->mmap) evlist->mmap[i].file = &rec->data.dir.files[i];Signature · 1 line
2.19.0
Quoted 24 lines · Alexey V
Quoted 14 lines · Jiri Olsa
Quoted 13 lines · Alexey Bayduraev
There is no notification about data directory creation failure. Add it.
Signed-off-by Alexey Bayduraev <[email protected]>--- tools/perf/builtin-record.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/perf/builtin-record.c +0
-0@@ -1186,8 +1186,10 @@ static int record__mmap_evlist(struct record *rec,Quoted 8 lines
tools/perf/builtin-record.c static int record__mmap_evlist(struct record *rec, · line 1190
Quoted 5 lines
tools/perf/builtin-record.c +2
-1if (record__threads_enabled (rec)) { ret =perf_data__create_dir (&rec->data, evlist->core.nr_mmaps); -if (ret) +if (ret) { +pr_err ("Failed to create data directory: %s\n" ,strerror (errno));errno will be misleading in here, because
perf_data__create_dircalls other syscalls on error path
Quoted 7 lines
Mostly I want to output something like:
Failed to create data dir: Too many open files
This will trigger the user to increase the open files limit. Would it be better to place such message to
perf_data__create_dirafteropen()syscall?
how about something like below (with your change)
jirka
---
tools/perf/util/data.c +3 -1
@@ -52,8 +52,10 @@ int perf_data__create_dir(struct perf_data *data, int nr) goto out_err; ret =open (file->path,O_RDWR |O_CREAT |O_TRUNC ,S_IRUSR |S_IWUSR ); -if (ret <0 ) +if (ret <0 ) { + ret = -errno; goto out_err; + } file->fd = ret; }
Quoted 27 lines · Jiri Olsa
Quoted 26 lines · Alexey V
Quoted 14 lines · Jiri Olsa
Quoted 13 lines · Alexey Bayduraev
There is no notification about data directory creation failure. Add it.
Signed-off-by Alexey Bayduraev <[email protected]>--- tools/perf/builtin-record.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/perf/builtin-record.c +0
-0@@ -1186,8 +1186,10 @@ static int record__mmap_evlist(struct record *rec,Quoted 8 lines
tools/perf/builtin-record.c static int record__mmap_evlist(struct record *rec, · line 1190
Quoted 5 lines
tools/perf/builtin-record.c +2
-1if (record__threads_enabled (rec)) { ret =perf_data__create_dir (&rec->data, evlist->core.nr_mmaps); -if (ret) +if (ret) { +pr_err ("Failed to create data directory: %s\n" ,strerror (errno));errno will be misleading in here, because
perf_data__create_dircalls other syscalls on error pathMostly I want to output something like:
Quoted 7 lines
Quoted 5 lines
Failed to create data dir: Too many open files
This will trigger the user to increase the open files limit. Would it be better to place such message to
perf_data__create_dirafteropen()syscall?how about something like below (with your change)
Looks better, I will apply this to my patch.
Thanks,
Alexey
Quoted 21 lines
jirka
---
tools/perf/util/data.c +3
-1@@ -52,8 +52,10 @@ int perf_data__create_dir(struct perf_data *data, int nr) goto out_err; ret =open (file->path,O_RDWR |O_CREAT |O_TRUNC ,S_IRUSR |S_IWUSR ); -if (ret <0 ) +if (ret <0 ) { + ret = -errno; goto out_err; + } file->fd = ret; }
Quoted 31 lines · Alexey V
Quoted 29 lines · Jiri Olsa
Quoted 28 lines · Alexey V
Quoted 14 lines · Jiri Olsa
Quoted 13 lines · Alexey Bayduraev
There is no notification about data directory creation failure. Add it.
Signed-off-by Alexey Bayduraev <[email protected]>--- tools/perf/builtin-record.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/perf/builtin-record.c +0
-0@@ -1186,8 +1186,10 @@ static int record__mmap_evlist(struct record *rec,Quoted 8 lines
tools/perf/builtin-record.c static int record__mmap_evlist(struct record *rec, · line 1190
Quoted 5 lines
tools/perf/builtin-record.c +2
-1if (record__threads_enabled (rec)) { ret =perf_data__create_dir (&rec->data, evlist->core.nr_mmaps); -if (ret) +if (ret) { +pr_err ("Failed to create data directory: %s\n" ,strerror (errno));errno will be misleading in here, because
perf_data__create_dircalls other syscalls on error pathMostly I want to output something like:
Failed to create data dir: Too many open files
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
This will trigger the user to increase the open files limit. Would it be better to place such message to
perf_data__create_dirafteropen()syscall?how about something like below (with your change)
Looks better, I will apply this to my patch.
Thanks a lot, I'll check when you post it.
Thanks for splitting that original patch, it was the correct thing to do in the first place, and now one of the patches got reviews I even missed :-)
- Arnaldo
Quoted 25 lines
Thanks,
AlexeyQuoted 21 lines
jirka
---
tools/perf/util/data.c +3
-1@@ -52,8 +52,10 @@ int perf_data__create_dir(struct perf_data *data, int nr) goto out_err; ret =open (file->path,O_RDWR |O_CREAT |O_TRUNC ,S_IRUSR |S_IWUSR ); -if (ret <0 ) +if (ret <0 ) { + ret = -errno; goto out_err; + } file->fd = ret; }