Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4934645ima; Tue, 5 Feb 2019 03:53:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IY0++8REfr+xI2cqi++P7ayJ46TqZaGfLk0/YhWuLSGpbDmGtb1zDK02lNFc2f9t8Mld8ip X-Received: by 2002:a17:902:9a9:: with SMTP id 38mr4699980pln.204.1549367627155; Tue, 05 Feb 2019 03:53:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549367627; cv=none; d=google.com; s=arc-20160816; b=lVVuL/fZyxF6t9W+lPny2r0uOoqacjrK1IEG7NW8SS075uZjnxRXDX3zPwwiW+yXu0 tkkjgQthltojuul/iwEJaZdB/HhH73POx/fz6cMUoqRHtPg+9161XtLnYQ41k4aYoyAB TJWPYD6qcaITe5HmAWFTSJ7Yhex72v3bnQkya5lGukWx9OeEmbSZW8xgwXhMYhnIfJUp EmHobOiBAk0gVXm3FtDlml2RMouXD8c6eYqO26R3uHxpd8tckMywO26p7MWAAtOHTMsA C2viYcSLiBZjHyokA28Lulez+tOOTZJxm64QWTkCS4kFdUHTPkfX2FYg4px2aEqfvJ+C AA4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=Jd09EBZe8E+7Olxse5wx2/woJ3UOLL/ehPoxW52I/b8=; b=FDRPgK1maCKxOVrbHIk9v+ljKtYBp/z4Kzbw290IiWCS82sJ5YM3vZwlUk5dsUs8XF LaZaRbyvpEQKLN2GIOpKE7hNN34LW/4O67Z/ouYBdJWEx+kSOITV3V0l4rhKZArfGZ6k DPAaALOCf3G4buX4jca4ZMDy9teOSxeV6fRSnfoaWZSaj7E87+Et7Co6yPZCnbOBQzve dKexRSd9iYtJcXQytWIy3X1s/bEcfDcwFNKeXs7vb24Jd/5b2iyPfaagCJZ/XexgBDCs YKvcwPx/01cWvKLZ0zSnV5cMhAzXdMDH+aw8kpi5yh+Pg42sOdAJN+SsUsw4rCVAO91k gyJA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si1895617pll.437.2019.02.05.03.53.30; Tue, 05 Feb 2019 03:53:47 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728733AbfBELxD (ORCPT + 99 others); Tue, 5 Feb 2019 06:53:03 -0500 Received: from mga06.intel.com ([134.134.136.31]:8970 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbfBELxD (ORCPT ); Tue, 5 Feb 2019 06:53:03 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2019 03:53:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,563,1539673200"; d="scan'208";a="316450896" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 05 Feb 2019 03:53:01 -0800 Received: from [10.125.252.139] (abudanko-mobl.ccr.corp.intel.com [10.125.252.139]) by linux.intel.com (Postfix) with ESMTP id 5D9CC580487; Tue, 5 Feb 2019 03:52:59 -0800 (PST) Subject: Re: [PATCH 06/14] perf data: Add perf_data__(create_dir|free_dir) functions To: Jiri Olsa , Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Adrian Hunter , Andi Kleen , Stephane Eranian References: <20190203153018.9650-1-jolsa@kernel.org> <20190203153018.9650-7-jolsa@kernel.org> From: Alexey Budankov Organization: Intel Corp. Message-ID: <19a2d4fd-11b4-dc80-2d0a-c4bccd95736c@linux.intel.com> Date: Tue, 5 Feb 2019 14:52:58 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <20190203153018.9650-7-jolsa@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03.02.2019 18:30, Jiri Olsa wrote: > 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); > > 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); It implements closing of created files and frees corresponding memory. However it doesn't delete the files what looks like the proper rollback from perf_data__create_dir() in case of some open() failure. > +} > + > +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); It looks like this is more unlink(dir) than close_files_in_dir(). Alexey > + 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 */ >