lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190205134607.GA10613@kernel.org>
Date:   Tue, 5 Feb 2019 10:46:07 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Jiri Olsa <jolsa@...nel.org>
Cc:     lkml <linux-kernel@...r.kernel.org>,
        Ingo Molnar <mingo@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@...llo.nl>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Andi Kleen <ak@...ux.intel.com>,
        Stephane Eranian <eranian@...gle.com>,
        Alexey Budankov <alexey.budankov@...ux.intel.com>
Subject: Re: [PATCH 06/14] perf data: Add perf_data__(create_dir|free_dir)
 functions

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 <jolsa@...nel.org>
> ---
>  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 <fcntl.h>
>  #include <unistd.h>
>  #include <string.h>
> +#include <asm/bug.h>
>  
>  #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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ