From 65e7c963267f128df155f496a50933cea7dfa5b8 Mon Sep 17 00:00:00 2001 From: Alexey Bayduraev Date: Tue, 22 Feb 2022 12:14:17 +0300 Subject: [PATCH] perf data: Adding error message if perf_data__create_dir() fails Add proper return codes for all cases of data directory creation failure and add error message output based on these codes. Signed-off-by: Alexey Bayduraev Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Antonov Cc: Alexander Shishkin Cc: Alexei Budankov Cc: Ingo Molnar Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20220222091417.11020-1-alexey.v.bayduraev@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 4 +++- tools/perf/util/data.c | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 0bc6529814b2..0b4abed555d8 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -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(-ret)); return ret; + } for (i = 0; i < evlist->core.nr_mmaps; i++) { if (evlist->mmap) evlist->mmap[i].file = &rec->data.dir.files[i]; diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index f5d260b1df4d..dc5d82ea1c30 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -52,12 +52,16 @@ int perf_data__create_dir(struct perf_data *data, int nr) struct perf_data_file *file = &files[i]; ret = asprintf(&file->path, "%s/data.%d", data->path, i); - if (ret < 0) + if (ret < 0) { + ret = -ENOMEM; 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; }