Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3768138pxb; Tue, 17 Nov 2020 03:05:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWIgc/+FKq7cj1Z8u7jC4+mfxIoCtjLC+8vxtfI+MltqR7psfQbVMB86yvuwhnrPvvKoq6 X-Received: by 2002:a05:6402:b8e:: with SMTP id cf14mr19265050edb.86.1605611138029; Tue, 17 Nov 2020 03:05:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605611138; cv=none; d=google.com; s=arc-20160816; b=bnKtIlQQVlgcU1puVTDTmXjA6Eur2LAGxQZ9ZYaTQSmFlLqXZb8po/EyGSeDdCwzjR GYs+71/drM3G+bMY8ghDxoarWUpuMn6yB0DcyACbgN0lRiAQR1ObJBIBsd7ZU6TQc+fL ySav6w+Vrn0KamBXeCxvlBWCpRaiRXPuJ6uBF+432yqSWmvuSCssyPcLUGliTqn40r1o G9QN/h4Y55TTRLnx/M5Sh89LPqttkpF7Q1trEpCQwFUpltcLEGMt/QOQdzsc3A4NsqRz HwRP5cCTRytHEp1F6eHf6I934HDi2alEEhAOJhe/Iw6LUBFBsJEM4EcJzBRyldlTNU0I VGZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UTxmLApfOI4hEZmP7QtbuM3TSQDIwE8rp06oztV4eQY=; b=yBtGtz3paFY55K2kmZlM/NMontIeAH3i6xQDlaEdpO4fegLhU+GiAZrkSRkQ2ewoZu KxnwZLSIP5wcvsqYaOV2z3+DQ+CRQjTB5+rF16gFt6rLILD1ChNBY5YVJl3p4iNA3Lnu UePWC2frYqNVh5LU9Y89gEkECYNSh8ALRGBBupjdm/j6PJOis0k7HP1Cdpa3SqQM0pfo En2s81uOyJmfluINwvplGk+amlZY+OWLBrTSWhNnlzk9/tNdbvR6+fG4UeOZXjVGWa0i bngycx/N/HGwLGtrMj0v8qkki4GYmsPyDR8Oh4ly9XqDw2bEsjo1pCohHA0qR1A2PuvM 9I7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m1si1381064ejj.517.2020.11.17.03.05.15; Tue, 17 Nov 2020 03:05:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728296AbgKQLBg convert rfc822-to-8bit (ORCPT + 99 others); Tue, 17 Nov 2020 06:01:36 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:52016 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727162AbgKQLBg (ORCPT ); Tue, 17 Nov 2020 06:01:36 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-87-1K72BBnjNKONLWYVBjS1-Q-1; Tue, 17 Nov 2020 06:01:29 -0500 X-MC-Unique: 1K72BBnjNKONLWYVBjS1-Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03EF3108E1AC; Tue, 17 Nov 2020 11:01:27 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id D90915C1CF; Tue, 17 Nov 2020 11:01:23 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Song Liu , Ian Rogers , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter Subject: [PATCH 07/24] perf tools: Add filename__decompress function Date: Tue, 17 Nov 2020 12:00:36 +0100 Message-Id: <20201117110053.1303113-8-jolsa@kernel.org> In-Reply-To: <20201117110053.1303113-1-jolsa@kernel.org> References: <20201117110053.1303113-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jolsa@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- tools/perf/util/dso.c | 31 +++++++++++++++++++------------ tools/perf/util/dso.h | 2 ++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 89b5fd2b5de3..d786cf6b0cfa 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -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); diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index d8cb4f5680a4..cd2fe64a3c5d 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -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) -- 2.26.2