mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-31 06:14:39 +01:00
perf tools: Add filename__decompress function
Factor filename__decompress from decompress_kmodule function. It can decompress files with compressions supported in perf - xz and gz, the support needs to be compiled in. It will to be used in following changes to get build id out of compressed elf objects. Signed-off-by: Jiri Olsa <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexey Budankov <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
This commit is contained in:
1 parent
f45edd86b2
commit
7ac22b088a
2 files changed
+21
-12
No files matched your search
+19
-12
@@ -279,18 +279,12 @@ bool dso__needs_decompress(struct dso *dso)
|
||||
dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
|
||||
}
|
||||
|
||||
static int decompress_kmodule(struct dso *dso, const char *name,
|
||||
char *pathname, size_t len)
|
||||
int filename__decompress(const char *name, char *pathname,
|
||||
size_t len, int comp, int *err)
|
||||
{
|
||||
char tmpbuf[] = KMOD_DECOMP_NAME;
|
||||
int fd = -1;
|
||||
|
||||
if (!dso__needs_decompress(dso))
|
||||
return -1;
|
||||
|
||||
if (dso->comp == COMP_ID__NONE)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* We have proper compression id for DSO and yet the file
|
||||
* behind the 'name' can still be plain uncompressed object.
|
||||
@@ -304,17 +298,17 @@ static int decompress_kmodule(struct dso *dso, const char *name,
|
||||
* To keep this transparent, we detect this and return the file
|
||||
* descriptor to the uncompressed file.
|
||||
*/
|
||||
if (!compressions[dso->comp].is_compressed(name))
|
||||
if (!compressions[comp].is_compressed(name))
|
||||
return open(name, O_RDONLY);
|
||||
|
||||
fd = mkstemp(tmpbuf);
|
||||
if (fd < 0) {
|
||||
dso->load_errno = errno;
|
||||
*err = errno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (compressions[dso->comp].decompress(name, fd)) {
|
||||
dso->load_errno = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
|
||||
if (compressions[comp].decompress(name, fd)) {
|
||||
*err = DSO_LOAD_ERRNO__DECOMPRESSION_FAILURE;
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
@@ -328,6 +322,19 @@ static int decompress_kmodule(struct dso *dso, const char *name,
|
||||
return fd;
|
||||
}
|
||||
|
||||
static int decompress_kmodule(struct dso *dso, const char *name,
|
||||
char *pathname, size_t len)
|
||||
{
|
||||
if (!dso__needs_decompress(dso))
|
||||
return -1;
|
||||
|
||||
if (dso->comp == COMP_ID__NONE)
|
||||
return -1;
|
||||
|
||||
return filename__decompress(name, pathname, len, dso->comp,
|
||||
&dso->load_errno);
|
||||
}
|
||||
|
||||
int dso__decompress_kmodule_fd(struct dso *dso, const char *name)
|
||||
{
|
||||
return decompress_kmodule(dso, name, NULL, 0);
|
||||
|
||||
@@ -274,6 +274,8 @@ bool dso__needs_decompress(struct dso *dso);
|
||||
int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
|
||||
int dso__decompress_kmodule_path(struct dso *dso, const char *name,
|
||||
char *pathname, size_t len);
|
||||
int filename__decompress(const char *name, char *pathname,
|
||||
size_t len, int comp, int *err);
|
||||
|
||||
#define KMOD_DECOMP_NAME "/tmp/perf-kmod-XXXXXX"
|
||||
#define KMOD_DECOMP_LEN sizeof(KMOD_DECOMP_NAME)
|
||||
|
||||
Reference in new issue
Block a user