Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3535213pxb; Mon, 9 Nov 2020 13:57:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmsRyjNjgA4UKMYw8xZMslYBHiwZUaHapRoXjBqmXm1M7IQk5bRiABM5gP8s+5vL/tbFF4 X-Received: by 2002:a17:906:1e45:: with SMTP id i5mr16713782ejj.203.1604959024643; Mon, 09 Nov 2020 13:57:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604959024; cv=none; d=google.com; s=arc-20160816; b=Ik+xpbAARjMQp9GUGzhirhfmvduQjPywqh75S5jn6WvrkSU9+a6B8DRS68xZClv/Li UrUmXjhRHIKwigHZTJozSPXHR78ZwyC/cZ7605TGTi26J/bL3si8NHLmLWKppzMJY3sJ fnRRvJN6M/m9ttsiNbuT2acg4pnXSNLenSM6fQiGwMJSn4GUlt9VGl7Ecow2hLXPXvHX kwqCWmu3Z69hx8LLyYuLE/5rQK6XJsCGGJpFT+uE7/Z+rtTIziqvnO1lCEdzfqvKdkzt HV4saP4woe4LY1oUrtY5Q4SCAwD71Q+EWhDBW2Pr+iLJlfaWQMNfuNco8Ldq3gXeEbVQ C2qw== 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=Ni7gKwv5DPMbEZBk4ny15t/u86IP99QMspRvwsEezDDTWBpFpOYr1RIO/hEayu0Fah Ka0J4wLrd2EcJ0Lxz8yrp3+m2jX2zvVzVLYBI0juNIGWdqCwSfz1dJ+qn64d0caCbRXZ Ej9saZBoBGv+JUmMQZHWQQVssEj0BoYgTOWSj5ohKKAcMvh119GUmQ4OhvVTDdCWunpk /WY9KIEYIcCUs0MANqgaaY2O22YT5t5lC8ipEcNNzFu1VtmrnVqYIUBZefUczvdzgpWR 8LlzxnimYpiButsw07U2sJS1ob8zFD0dMqEtZ+VICYN+fWL357xH/MqwDYtybHX14wPM +gBg== 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 v10si8387188ejy.467.2020.11.09.13.56.41; Mon, 09 Nov 2020 13:57:04 -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 S1731356AbgKIVy7 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 9 Nov 2020 16:54:59 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:43704 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731346AbgKIVy6 (ORCPT ); Mon, 9 Nov 2020 16:54:58 -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-370-FBIvx6ahNqudb5091bWo6A-1; Mon, 09 Nov 2020 16:54:51 -0500 X-MC-Unique: FBIvx6ahNqudb5091bWo6A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ABED55F9E1; Mon, 9 Nov 2020 21:54:48 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B35F6EF46; Mon, 9 Nov 2020 21:54:45 +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: Mon, 9 Nov 2020 22:53:58 +0100 Message-Id: <20201109215415.400153-8-jolsa@kernel.org> In-Reply-To: <20201109215415.400153-1-jolsa@kernel.org> References: <20201109215415.400153-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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