BPF List
 help / color / mirror / Atom feed
From: Quentin Monnet <quentin.monnet@netronome.com>
To: Paul Chaignon <paul.chaignon@orange.com>, bpf@vger.kernel.org
Cc: paul.chaignon@gmail.com, netdev@vger.kernel.org,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>, Andrii Nakryiko <andriin@fb.com>
Subject: Re: [PATCH bpf-next 3/3] bpftool: match maps by name
Date: Tue, 10 Dec 2019 17:29:50 +0000	[thread overview]
Message-ID: <61747303-6cd5-e2e7-749f-13068085ed9c@netronome.com> (raw)
In-Reply-To: <06aad9217a37b0582407cab11469125e645f5084.1575991886.git.paul.chaignon@orange.com>

2019-12-10 17:06 UTC+0100 ~ Paul Chaignon <paul.chaignon@orange.com>
> This patch implements lookup by name for maps and changes the behavior of
> lookups by tag to be consistent with prog subcommands.  Similarly to
> program subcommands, the show and dump commands will return all maps with
> the given name (or tag), whereas other commands will error out if several
> maps have the same name (resp. tag).
> 
> When a map has BTF info, it is dumped in JSON with available BTF info.
> This patch requires that all matched maps have BTF info before switching
> the output format to JSON.
> 
> Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
> ---
>  .../bpf/bpftool/Documentation/bpftool-map.rst |  10 +-
>  tools/bpf/bpftool/bash-completion/bpftool     | 131 ++++++-
>  tools/bpf/bpftool/main.h                      |   2 +-
>  tools/bpf/bpftool/map.c                       | 366 +++++++++++++++---
>  4 files changed, 432 insertions(+), 77 deletions(-)
> 

> diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
> index 05b5be4a6ef9..21c676a1eeb1 100644
> --- a/tools/bpf/bpftool/bash-completion/bpftool
> +++ b/tools/bpf/bpftool/bash-completion/bpftool

Nice work on the completion, thanks!

> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index de61d73b9030..f0e0be08ba21 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c

[...]

> @@ -654,14 +771,42 @@ static int do_show(int argc, char **argv)
>  		build_pinned_obj_table(&map_table, BPF_OBJ_MAP);
>  
>  	if (argc == 2) {
> -		fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
> -		if (fd < 0)
> +		fds = malloc(sizeof(int));
> +		if (!fds) {
> +			p_err("mem alloc failed");
>  			return -1;
> +		}
> +		nb_fds = map_parse_fds(&argc, &argv, fds);
> +		if (nb_fds < 1)
> +			goto err_free;
> +
> +		if (json_output && nb_fds > 1)
> +			jsonw_start_array(json_wtr);	/* root array */
> +		for (i = 0; i < nb_fds; i++) {
> +			err = bpf_obj_get_info_by_fd(fds[i], &info, &len);
> +			if (err) {
> +				p_err("can't get map info: %s",
> +				      strerror(errno));
> +				for (; i < nb_fds; i++)
> +					close(fds[i]);
> +				goto err_free;

Same remarks as on patch 1, we may want to keep listing the maps even if
we get a failure for one of them?

> +			}
>  
> -		if (json_output)
> -			return show_map_close_json(fd, &info);
> -		else
> -			return show_map_close_plain(fd, &info);
> +			if (json_output)
> +				show_map_close_json(fds[i], &info);
> +			else
> +				show_map_close_plain(fds[i], &info);
> +
> +			close(fds[i]);
> +		}
> +		if (json_output && nb_fds > 1)
> +			jsonw_end_array(json_wtr);	/* root array */
> +
> +		return 0;
> +
> +err_free:
> +		free(fds);
> +		return -1;
>  	}
>  
>  	if (argc)

The rest of the code looks good to me, thanks a lot for working on this!
Quentin

      reply	other threads:[~2019-12-10 17:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 16:05 [PATCH bpf-next 0/3] bpftool: match programs and maps by names Paul Chaignon
2019-12-10 16:06 ` [PATCH bpf-next 1/3] bpftool: match several programs with same tag Paul Chaignon
2019-12-10 17:29   ` Quentin Monnet
2019-12-13 18:10     ` Paul Chaignon
2019-12-10 20:36   ` Jakub Kicinski
2019-12-13 12:39     ` Paul Chaignon
2019-12-10 16:06 ` [PATCH bpf-next 2/3] bpftool: match programs by name Paul Chaignon
2019-12-10 17:29   ` Quentin Monnet
2019-12-10 21:04   ` Jakub Kicinski
2019-12-13 12:40     ` Paul Chaignon
2019-12-13 17:56       ` Jakub Kicinski
2019-12-10 16:06 ` [PATCH bpf-next 3/3] bpftool: match maps " Paul Chaignon
2019-12-10 17:29   ` Quentin Monnet [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=61747303-6cd5-e2e7-749f-13068085ed9c@netronome.com \
    --to=quentin.monnet@netronome.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=paul.chaignon@gmail.com \
    --cc=paul.chaignon@orange.com \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox