Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
c9a8a613 dde755a9

+12 -17
+12 -17
tools/perf/util/dso.c
··· 250 250 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP; 251 251 } 252 252 253 - static int decompress_kmodule(struct dso *dso, const char *name, char *tmpbuf) 253 + static int decompress_kmodule(struct dso *dso, const char *name, 254 + char *pathname, size_t len) 254 255 { 256 + char tmpbuf[] = KMOD_DECOMP_NAME; 255 257 int fd = -1; 256 258 257 259 if (!dso__needs_decompress(dso)) ··· 274 272 fd = -1; 275 273 } 276 274 275 + if (!pathname || (fd < 0)) 276 + unlink(tmpbuf); 277 + 278 + if (pathname && (fd >= 0)) 279 + strncpy(pathname, tmpbuf, len); 280 + 277 281 return fd; 278 282 } 279 283 280 284 int dso__decompress_kmodule_fd(struct dso *dso, const char *name) 281 285 { 282 - char tmpbuf[] = KMOD_DECOMP_NAME; 283 - int fd; 284 - 285 - fd = decompress_kmodule(dso, name, tmpbuf); 286 - unlink(tmpbuf); 287 - return fd; 286 + return decompress_kmodule(dso, name, NULL, 0); 288 287 } 289 288 290 289 int dso__decompress_kmodule_path(struct dso *dso, const char *name, 291 290 char *pathname, size_t len) 292 291 { 293 - char tmpbuf[] = KMOD_DECOMP_NAME; 294 - int fd; 292 + int fd = decompress_kmodule(dso, name, pathname, len); 295 293 296 - fd = decompress_kmodule(dso, name, tmpbuf); 297 - if (fd < 0) { 298 - unlink(tmpbuf); 299 - return -1; 300 - } 301 - 302 - strncpy(pathname, tmpbuf, len); 303 294 close(fd); 304 - return 0; 295 + return fd >= 0 ? 0 : -1; 305 296 } 306 297 307 298 /*