Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2889679ima; Sun, 3 Feb 2019 08:50:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN4EEOoei2vl4oHv+gtPQU8+rHeWLRUtSN3rj10OB0pWbCWiEvUoOCcddn2Xku5QdVsYeO+c X-Received: by 2002:a17:902:9305:: with SMTP id bc5mr47592221plb.86.1549212622750; Sun, 03 Feb 2019 08:50:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549212622; cv=none; d=google.com; s=arc-20160816; b=uqncwjql9Bn0YaNSJ5cA3izeaqT24YBYomYtcenPmGFEf1/O4CiOSVm+rt7nn0CKjK vWvnf1ghTyhVI/KwZvxYf+tNz6bUoxiJF3m3aOpUSLtb4bJf5eZP8pr2Ek+bzXT/eAvs UFS+3dMXjbXIPQe9dzhanuIAlV062N8ZfsCMj6PvQ6AzvyWgAjWYTAEWeIVTjqaBjWmw NBsfOVB2ElDEIz3mZ3t1sSI1wZCS5EmWVU+H5t88E3vl1//LtYEt9rWHyvqCiVcscZI7 IEJOX/8bztIaF/DLWLkRVzHjGOj7R850HHm4x74lPDVqjUvocZJhaByTqNtNQV8Hmd/i d3Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=gwmyX8+rwPWaoEZetClfzXiestKXhVyC1sVntp31ewQ=; b=ZAACa1+dxvuwqTAJ+zBlwmb1M4Flq/ysMFC3yl8e34BZj7RcHIavbR2CD1KQ9kg22K 0kH80QY/oYBbEkLA6HKaaheqnSKN8CSXjH69L66RxcVrFKVaE0aDEtbXMO5Ec0lssQ3E Uig3DqmuQlVvc3YZtz8kIoKzpSJU9iiQd2nopWFWTSpocs7Z7VQ7c6XF1ebrWrRknBwk r7ot3LhWX1uQeNPwqtXdxtM9gFQ8pNUpAOmcMR7B2NMPU+2225dsRNVz+6Ew4GIu0T1m eX0XL84COYEkU4F+ofBFzCXZdPfythOmlf9CXAnGTAS01aHo45WH1RbVD8dX6Tfq+QI3 knBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f95si14682838plb.60.2019.02.03.08.50.07; Sun, 03 Feb 2019 08:50:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728770AbfBCPbZ (ORCPT + 99 others); Sun, 3 Feb 2019 10:31:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46300 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728376AbfBCPao (ORCPT ); Sun, 3 Feb 2019 10:30:44 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id CD9A3356E7; Sun, 3 Feb 2019 15:30:43 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-46.brq.redhat.com [10.40.204.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C2D65C23D; Sun, 3 Feb 2019 15:30:41 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Adrian Hunter , Andi Kleen , Stephane Eranian , Alexey Budankov Subject: [PATCH 07/14] perf data: Add perf_data__open_dir_data function Date: Sun, 3 Feb 2019 16:30:11 +0100 Message-Id: <20190203153018.9650-8-jolsa@kernel.org> In-Reply-To: <20190203153018.9650-1-jolsa@kernel.org> References: <20190203153018.9650-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 03 Feb 2019 15:30:44 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding perf_data__open_dir_data to open files inside struct perf_data path directory: static int perf_data__open_dir(struct perf_data *data); Link: http://lkml.kernel.org/n/tip-sv97z5mh9j273mz2cthzaq4n@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/util/data.c | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index ff1d9e5bd68d..7c37b67fbc3c 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "data.h" #include "util.h" @@ -59,6 +61,64 @@ int perf_data__create_dir(struct perf_data *data, int nr) return ret; } +__maybe_unused +static int perf_data__open_dir(struct perf_data *data) +{ + struct perf_data_file *files = NULL; + struct dirent *dent; + int ret = -1; + DIR *dir; + int nr = 0; + + dir = opendir(data->path); + if (!dir) + return -EINVAL; + + while ((dent = readdir(dir)) != NULL) { + struct perf_data_file *file; + char path[PATH_MAX]; + struct stat st; + + snprintf(path, sizeof(path), "%s/%s", data->path, dent->d_name); + if (stat(path, &st)) + continue; + + if (!S_ISREG(st.st_mode) || strncmp(dent->d_name, "data", 4)) + continue; + + ret = -ENOMEM; + + file = realloc(files, (nr + 1) * sizeof(*files)); + if (!file) + goto out_err; + + files = file; + file = &files[nr++]; + + file->path = strdup(path); + if (!file->path) + goto out_err; + + ret = open(file->path, O_RDONLY); + if (ret < 0) + goto out_err; + + file->fd = ret; + file->size = st.st_size; + } + + if (!files) + return -EINVAL; + + data->dir.files = files; + data->dir.nr = nr; + return 0; + +out_err: + free_dir(files, nr); + return ret; +} + static bool check_pipe(struct perf_data *data) { struct stat st; -- 2.17.2