]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
perf data: Fail check_backup in case of error
authorJiri Olsa <jolsa@kernel.org>
Sun, 24 Feb 2019 19:06:43 +0000 (20:06 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 25 Feb 2019 13:37:01 +0000 (10:37 -0300)
And display the error message from removing the old data file:

  $ perf record ls
  Can't remove old data: Permission denied (perf.data.old)
  Perf session creation failed.

  $ perf record ls
  Can't remove old data: Unknown file found (perf.data.old)
  Perf session creation failed.

Not sure how to make fail the rename (after we successfully remove the
destination file/dir) to show the message, anyway let's have it there.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20190224190656.30163-8-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/data.c

index bbf9a299615e1febfb5f61597f4161889702a813..d008c39730121d66542618360552999fa1c5e05b 100644 (file)
@@ -41,12 +41,27 @@ static int check_backup(struct perf_data *data)
                return 0;
 
        if (!stat(data->path, &st) && st.st_size) {
-               /* TODO check errors properly */
                char oldname[PATH_MAX];
+               int ret;
+
                snprintf(oldname, sizeof(oldname), "%s.old",
                         data->path);
-               rm_rf_perf_data(oldname);
-               rename(data->path, oldname);
+
+               ret = rm_rf_perf_data(oldname);
+               if (ret) {
+                       pr_err("Can't remove old data: %s (%s)\n",
+                              ret == -2 ?
+                              "Unknown file found" : strerror(errno),
+                              oldname);
+                       return -1;
+               }
+
+               if (rename(data->path, oldname)) {
+                       pr_err("Can't move data: %s (%s to %s)\n",
+                              strerror(errno),
+                              data->path, oldname);
+                       return -1;
+               }
        }
 
        return 0;