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 <alexey.v.bayduraev@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220222091417.11020-1-alexey.v.bayduraev@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Alexey Bayduraev 2022-02-22 12:14:17 +03:00 committed by Arnaldo Carvalho de Melo
parent 859f7e4554
commit 65e7c96326
2 changed files with 9 additions and 3 deletions

View File

@ -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];

View File

@ -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;
}