Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp5058955ima; Tue, 5 Feb 2019 05:50:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IaBMwdSh+AgWxL6T5eUW/3EhiWEicHmfIA4dn25DKu4QJTP7AMEowupKCTIGKqjmP+I3T4P X-Received: by 2002:a17:902:1005:: with SMTP id b5mr5250023pla.310.1549374653256; Tue, 05 Feb 2019 05:50:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549374653; cv=none; d=google.com; s=arc-20160816; b=PTgcuBJLYZ9aOx6TJAiT7u/qGPu2+0wprw+FNhbrV1YMSnBOSRF0sv5QoCBJNJ8wLZ V7InPTzBPBQ81UceHLbv2Tty6nEtXd9JEI5NEsP7nsud8NB0YTnGI0SXdIOvYw9DO/Ts EiPm4fgzk3+vZhdpA3dZXIDrmVt/4BPSgXZyullTfjsRAwAEBhZHYa4x3HKaqwpKFNFR jyY1JkaWu7HkDNcvuIFjw9XuGJMgaMOHN3EzuazGjP4n0+s4dYa2AOaWowc1TCJ1fA+J WsBOJBvxj4Gx/LooVSPmSQ3o9CrSI8+wwNr3U2aFh/k/UEe4Lh0qdXq5d6gyiyFq/9iD 0TrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gDJFp0/gPaEpePgOgs9d3AOjWnQGMfozsAhEipVarkw=; b=NbShLXCwCHr5R0jR/Nm+xzJYH8EearOVVUu3FYf4DIUZrmwa0sB3eG0MBPRm90uhJ/ fk7qD0UawsZPjuLaN/k85FnooNRwHaNHhcEOAwD/eIZPTzat1GRc2xtofGza8UVXQ/aG /I3eX90cb0md7g/j2NRRuY4tG2tvdhAlFTXvu1r9uAEJFB1Bk+lWJ/hJQKpODcWcxykn 3ilR8CRuScCZY13tXmSamXE4ZBzgoTVC0dCmhU6H2O8CNKTqnGX9rgnTFhS1g6Xvz7em F28TTGGv3RTixNw+jh86IuSPPWAAWgiVSOZC4fHOCC26/BxgdlRj2oBagkqXcVT7WJ9w EU2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="K/xoAzW0"; 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=pass (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 i16si3018031pgk.445.2019.02.05.05.50.37; Tue, 05 Feb 2019 05:50:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b="K/xoAzW0"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728749AbfBENqL (ORCPT + 99 others); Tue, 5 Feb 2019 08:46:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:39276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbfBENqK (ORCPT ); Tue, 5 Feb 2019 08:46:10 -0500 Received: from quaco.ghostprotocols.net (unknown [190.15.121.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA7D0207E0; Tue, 5 Feb 2019 13:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549374369; bh=k1JRpngOz9Ss7nCNY5SI3MaUgEolS/vCDe+V0rmX4lE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=K/xoAzW0g4oKH2/gS0buuDFn6xKhnnG8MpyOLZkfO2lA+kpdBiHnLctRwEbeIXpyW 3y4t7sLZG3IDoqNwbMRFZIBK9X43bM5H30GSFPIcKmNZsNYVS+uWqqWf8wlJbGZK2z mETWpln2i5TJzGkGvzeErjRqpYfp0WhhYSSb3kA0= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 474A84034F; Tue, 5 Feb 2019 10:46:07 -0300 (-03) Date: Tue, 5 Feb 2019 10:46:07 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Adrian Hunter , Andi Kleen , Stephane Eranian , Alexey Budankov Subject: Re: [PATCH 06/14] perf data: Add perf_data__(create_dir|free_dir) functions Message-ID: <20190205134607.GA10613@kernel.org> References: <20190203153018.9650-1-jolsa@kernel.org> <20190203153018.9650-7-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190203153018.9650-7-jolsa@kernel.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sun, Feb 03, 2019 at 04:30:10PM +0100, Jiri Olsa escreveu: > Adding perf_data__create_dir to create nr files inside > struct perf_data path directory: > int perf_data__create_dir(struct perf_data *data, int nr); > > and function to free that data: > void perf_data__free_dir(struct perf_data *data); Can you please rename this to perf_data__remove_dir(), I think it is more appropriate, just like that rm_rf() thing. - Arnaldo > Link: http://lkml.kernel.org/n/tip-kl4s1f13cg6wycrg367p85qm@git.kernel.org > Signed-off-by: Jiri Olsa > --- > tools/perf/util/data.c | 47 ++++++++++++++++++++++++++++++++++++++++++ > tools/perf/util/data.h | 8 +++++++ > 2 files changed, 55 insertions(+) > > diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c > index 0a3051cc0ea0..ff1d9e5bd68d 100644 > --- a/tools/perf/util/data.c > +++ b/tools/perf/util/data.c > @@ -7,11 +7,58 @@ > #include > #include > #include > +#include > > #include "data.h" > #include "util.h" > #include "debug.h" > > +static void free_dir(struct perf_data_file *files, int nr) > +{ > + while (--nr >= 1) { > + close(files[nr].fd); > + free(files[nr].path); > + } > + free(files); > +} > + > +void perf_data__free_dir(struct perf_data *data) > +{ > + free_dir(data->dir.files, data->dir.nr); > +} > + > +int perf_data__create_dir(struct perf_data *data, int nr) > +{ > + struct perf_data_file *files = NULL; > + int i, ret = -1; > + > + files = malloc(nr * sizeof(*files)); > + if (!files) > + return -ENOMEM; > + > + data->dir.files = files; > + data->dir.nr = nr; > + > + for (i = 0; i < nr; i++) { > + struct perf_data_file *file = &files[i]; > + > + if (asprintf(&file->path, "%s/data.%d", data->path, i) < 0) > + goto out_err; > + > + ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); > + if (ret < 0) > + goto out_err; > + > + file->fd = ret; > + } > + > + return 0; > + > +out_err: > + free_dir(files, i); > + return ret; > +} > + > static bool check_pipe(struct perf_data *data) > { > struct stat st; > diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h > index 2bce28117ccf..3b4115dc777f 100644 > --- a/tools/perf/util/data.h > +++ b/tools/perf/util/data.h > @@ -21,6 +21,11 @@ struct perf_data { > bool is_pipe; > bool force; > enum perf_data_mode mode; > + > + struct { > + struct perf_data_file *files; > + int nr; > + } dir; > }; > > static inline bool perf_data__is_read(struct perf_data *data) > @@ -64,4 +69,7 @@ ssize_t perf_data_file__write(struct perf_data_file *file, > int perf_data__switch(struct perf_data *data, > const char *postfix, > size_t pos, bool at_exit); > + > +int perf_data__create_dir(struct perf_data *data, int nr); > +void perf_data__free_dir(struct perf_data *data); > #endif /* __PERF_DATA_H */ > -- > 2.17.2 -- - Arnaldo