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

perf tools: Add is_compressed callback to compressions array

Add is_compressed callback to the compressions array, that returns 0 if
the file is compressed or != 0 if not.

The new callback is used to recognize the situation when we have a
'compressed' object, like:

/lib/modules/.../drivers/net/ethernet/intel/igb/igb.ko.xz

but we need to read its debug data from debuginfo files, which might not
be compressed, like:

/root/.debug/.build-id/d6/...c4b301f/debug

So even for a 'compressed' object we read debug data from a plain
uncompressed object. To keep this transparent, we detect this in
decompress_kmodule() and return the file descriptor to the uncompressed
file.

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-11-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
8b42b7e5 c9a8a613

+33 -3
+2
tools/perf/util/compress.h
··· 4 4 5 5 #ifdef HAVE_ZLIB_SUPPORT 6 6 int gzip_decompress_to_file(const char *input, int output_fd); 7 + bool gzip_is_compressed(const char *input); 7 8 #endif 8 9 9 10 #ifdef HAVE_LZMA_SUPPORT 10 11 int lzma_decompress_to_file(const char *input, int output_fd); 12 + bool lzma_is_compressed(const char *input); 11 13 #endif 12 14 13 15 #endif /* PERF_COMPRESS_H */
+20 -3
tools/perf/util/dso.c
··· 196 196 static const struct { 197 197 const char *fmt; 198 198 int (*decompress)(const char *input, int output); 199 + bool (*is_compressed)(const char *input); 199 200 } compressions[] = { 200 201 [COMP_ID__NONE] = { .fmt = NULL, }, 201 202 #ifdef HAVE_ZLIB_SUPPORT 202 - { "gz", gzip_decompress_to_file }, 203 + { "gz", gzip_decompress_to_file, gzip_is_compressed }, 203 204 #endif 204 205 #ifdef HAVE_LZMA_SUPPORT 205 - { "xz", lzma_decompress_to_file }, 206 + { "xz", lzma_decompress_to_file, lzma_is_compressed }, 206 207 #endif 207 - { NULL, NULL }, 208 + { NULL, NULL, NULL }, 208 209 }; 209 210 210 211 static int is_supported_compression(const char *ext) ··· 262 261 263 262 if (dso->comp == COMP_ID__NONE) 264 263 return -1; 264 + 265 + /* 266 + * We have proper compression id for DSO and yet the file 267 + * behind the 'name' can still be plain uncompressed object. 268 + * 269 + * The reason is behind the logic we open the DSO object files, 270 + * when we try all possible 'debug' objects until we find the 271 + * data. So even if the DSO is represented by 'krava.xz' module, 272 + * we can end up here opening ~/.debug/....23432432/debug' file 273 + * which is not compressed. 274 + * 275 + * To keep this transparent, we detect this and return the file 276 + * descriptor to the uncompressed file. 277 + */ 278 + if (!compressions[dso->comp].is_compressed(name)) 279 + return open(name, O_RDONLY); 265 280 266 281 fd = mkstemp(tmpbuf); 267 282 if (fd < 0) {
+5
tools/perf/util/lzma.c
··· 99 99 fclose(infile); 100 100 return err; 101 101 } 102 + 103 + bool lzma_is_compressed(const char *input __maybe_unused) 104 + { 105 + return true; 106 + }
+6
tools/perf/util/zlib.c
··· 5 5 #include <sys/stat.h> 6 6 #include <sys/mman.h> 7 7 #include <zlib.h> 8 + #include <linux/compiler.h> 8 9 9 10 #include "util/compress.h" 10 11 #include "util/util.h" ··· 79 78 close(input_fd); 80 79 81 80 return ret == Z_STREAM_END ? 0 : -1; 81 + } 82 + 83 + bool gzip_is_compressed(const char *input __maybe_unused) 84 + { 85 + return true; 82 86 }