perf data: Adding error message if perf_data__create_dir() fails
authorAlexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Tue, 22 Feb 2022 09:14:17 +0000 (12:14 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 23 Feb 2022 00:15:56 +0000 (21:15 -0300)
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>
tools/perf/builtin-record.c
tools/perf/util/data.c

index 0bc6529..0b4abed 100644 (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];
index f5d260b..dc5d82e 100644 (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;
        }