aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2018-08-17 05:48:09 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-08-20 07:54:59 -0400
commitc9a8a6131fb68f6eabec34fd855e69b4855155e4 (patch)
tree3da5dd231fc0fcaf1b31610f884230a97c10387a /tools/perf
parentdde755a90e98a1c57f6a92d1a79bc5554024065c (diff)
perf tools: Move the temp file processing into decompress_kmodule
We will add a compression check in the following patch and it makes it easier if the file processing is done in a single place. It also makes the current code simpler. The decompress_kmodule function now returns the fd of the uncompressed file and the file name in the pathname arg, if it's provided. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20180817094813.15086-10-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/dso.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 54bfe1f4762f..cbeecf683333 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -250,8 +250,10 @@ bool dso__needs_decompress(struct dso *dso)
250 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP; 250 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
251} 251}
252 252
253static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf) 253static int decompress_kmodule(struct dso *dso, const char *name,
254 char *pathname, size_t len)
254{ 255{
256 char tmpbuf[] = KMOD_DECOMP_NAME;
255 int fd = -1; 257 int fd = -1;
256 258
257 if (!dso__needs_decompress(dso)) 259 if (!dso__needs_decompress(dso))
@@ -272,34 +274,27 @@ static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf)
272 fd = -1; 274 fd = -1;
273 } 275 }
274 276
277 if (!pathname || (fd < 0))
278 unlink(tmpbuf);
279
280 if (pathname && (fd >= 0))
281 strncpy(pathname, tmpbuf, len);
282
275 return fd; 283 return fd;
276} 284}
277 285
278int dso__decompress_kmodule_fd(struct dso *dso, const char *name) 286int dso__decompress_kmodule_fd(struct dso *dso, const char *name)
279{ 287{
280 char tmpbuf[] = KMOD_DECOMP_NAME; 288 return decompress_kmodule(dso, name, NULL, 0);
281 int fd;
282
283 fd = decompress_kmodule(dso, name, tmpbuf);
284 unlink(tmpbuf);
285 return fd;
286} 289}
287 290
288int dso__decompress_kmodule_path(struct dso *dso, const char *name, 291int dso__decompress_kmodule_path(struct dso *dso, const char *name,
289 char *pathname, size_t len) 292 char *pathname, size_t len)
290{ 293{
291 char tmpbuf[] = KMOD_DECOMP_NAME; 294 int fd = decompress_kmodule(dso, name, pathname, len);
292 int fd;
293
294 fd = decompress_kmodule(dso, name, tmpbuf);
295 if (fd < 0) {
296 unlink(tmpbuf);
297 return -1;
298 }
299 295
300 strncpy(pathname, tmpbuf, len);
301 close(fd); 296 close(fd);
302 return 0; 297 return fd >= 0 ? 0 : -1;
303} 298}
304 299
305/* 300/*