Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp686799pxu; Thu, 26 Nov 2020 09:04:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxE7MbuC/xa8gQaaQZOIi5916iXZlqpuj4yYUZdmwR8ZmASUH9ouMhjgv7BOf726wFAnFl1 X-Received: by 2002:a17:906:13d0:: with SMTP id g16mr3469632ejc.327.1606410275915; Thu, 26 Nov 2020 09:04:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606410275; cv=none; d=google.com; s=arc-20160816; b=U2Kp0rSzuF1f7Pqa1ATbbKVvIsm0oVuiNWjVY8mYmpUF84lwHplsUC1/dIN05v5PIO yOCcpZLhQ3VV/5annpsMzuzKFU7k+emt2Q3tFXfTO6KxZN9hH4Npj6XSPzWyh0fFF2ld 7Q04LqmNaIy/yMeKkyR6rrzgaLKxGqJtlheqlvvqh15Jd5WFup9Js50rKPXmD+AV+I1B AIfeV9oZ1IbuLNu+B2/02wHJXUgcWUleveIskiZ97O82fWM98+cKWWEejfFDDkeicCo2 5QMgNJb5g4YP3+n4Y+PQ/xN14fmmbF/zA42xVym2ucY1hX3jpcK6yrgwXFJIRMswV1pF Qt6A== 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=Ljn32EKlPyd4bsLwrANTusrfTKUoMPUe1cIyJqffPQyaCcXMToiJQc15FI8hyTtbSd MZyMtnNfmFU0iRmzVWz3d8LZhbxghWdsvALcm3Eeq/H0vtclbw0Pghz2xEpVSzB9r3f9 PsgP1XBmbL2RTTXplpPHgbGi0eX18I8TJXIgPjje4NeGFGjANOC+72svgz/USkrroPZG XNCWKLqrcrFTbQLrFtRkoSZg/BIehVu1a5lBLsIxRl1MOjArusm/mYuhn9oxUtE3RqOV LfQeVjunFeTgYUSjuWTowEUO0/DDqeV+WlzwiYvAQ1lsa5Uo/m1X6RNO3kmioZFC9EBx j7jQ== 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 dk20si3362690ejb.123.2020.11.26.09.04.08; Thu, 26 Nov 2020 09:04:35 -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 S2391302AbgKZRBR convert rfc822-to-8bit (ORCPT + 99 others); Thu, 26 Nov 2020 12:01:17 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:48444 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403995AbgKZRBR (ORCPT ); Thu, 26 Nov 2020 12:01:17 -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-420-frgBxfloPauFbIvfB3AHMw-1; Thu, 26 Nov 2020 12:01:09 -0500 X-MC-Unique: frgBxfloPauFbIvfB3AHMw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E2AA190D342; Thu, 26 Nov 2020 17:01:07 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03BA860BFA; Thu, 26 Nov 2020 17:01:02 +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 08/25] perf tools: Add filename__decompress function Date: Thu, 26 Nov 2020 18:00:09 +0100 Message-Id: <20201126170026.2619053-9-jolsa@kernel.org> In-Reply-To: <20201126170026.2619053-1-jolsa@kernel.org> References: <20201126170026.2619053-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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