From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
David Miller <davem@davemloft.net>,
Kernel Team <kernel-team@fb.com>,
Networking <netdev@vger.kernel.org>,
Paul Chaignon <paul.chaignon@orange.com>
Subject: Re: [PATCH bpf-next 2/5] bpftool: Fix missing BTF output for json during map dump
Date: Tue, 14 Jan 2020 17:34:33 -0800 [thread overview]
Message-ID: <CAEf4BzbrcKLKvgKY+nSxV22T2nHgucmB2N01bEQiXS+g7npQfw@mail.gmail.com> (raw)
In-Reply-To: <20200114224406.3027562-1-kafai@fb.com>
On Tue, Jan 14, 2020 at 2:45 PM Martin KaFai Lau <kafai@fb.com> wrote:
>
> The btf availability check is only done for plain text output.
> It causes the whole BTF output went missing when json_output
> is used.
>
> This patch simplifies the logic a little by avoiding passing "int btf" to
> map_dump().
>
> For plain text output, the btf_wtr is only created when the map has
> BTF (i.e. info->btf_id != 0). The nullness of "json_writer_t *wtr"
> in map_dump() alone can decide if dumping BTF output is needed.
> As long as wtr is not NULL, map_dump() will print out the BTF-described
> data whenever a map has BTF available (i.e. info->btf_id != 0)
> regardless of json or plain-text output.
>
> In do_dump(), the "int btf" is also renamed to "int do_plain_btf".
>
> Fixes: 99f9863a0c45 ("bpftool: Match maps by name")
> Cc: Paul Chaignon <paul.chaignon@orange.com>
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>
> ---
just one nit below
Acked-by: Andrii Nakryiko <andriin@fb.com>
> tools/bpf/bpftool/map.c | 42 ++++++++++++++++++++---------------------
> 1 file changed, 20 insertions(+), 22 deletions(-)
>
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index e00e9e19d6b7..45c1eda6512c 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -933,7 +933,7 @@ static int maps_have_btf(int *fds, int nb_fds)
>
> static int
> map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
> - bool enable_btf, bool show_header)
> + bool show_header)
> {
> void *key, *value, *prev_key;
> unsigned int num_elems = 0;
> @@ -950,18 +950,16 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
>
> prev_key = NULL;
>
> - if (enable_btf) {
> - err = btf__get_from_id(info->btf_id, &btf);
> - if (err || !btf) {
> - /* enable_btf is true only if we've already checked
> - * that all maps have BTF information.
> - */
> - p_err("failed to get btf");
> - goto exit_free;
> + if (wtr) {
> + if (info->btf_id) {
combine into if (wtr && info->btf_id) and reduce nestedness?
> + err = btf__get_from_id(info->btf_id, &btf);
> + if (err || !btf) {
> + err = err ? : -ESRCH;
> + p_err("failed to get btf");
> + goto exit_free;
> + }
[...]
next prev parent reply other threads:[~2020-01-15 1:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-14 22:43 [PATCH bpf-next 0/5] bpftool: Support dumping a map with btf_vmlinux_value_type_id Martin KaFai Lau
2020-01-14 22:44 ` [PATCH bpf-next 1/5] bpftool: Fix a leak of btf object Martin KaFai Lau
2020-01-15 1:10 ` Andrii Nakryiko
2020-01-15 5:46 ` Martin Lau
2020-01-15 6:40 ` Andrii Nakryiko
2020-01-16 8:00 ` Paul Chaignon
2020-01-14 22:44 ` [PATCH bpf-next 2/5] bpftool: Fix missing BTF output for json during map dump Martin KaFai Lau
2020-01-15 1:34 ` Andrii Nakryiko [this message]
2020-01-15 5:54 ` Martin Lau
2020-01-15 6:36 ` Andrii Nakryiko
2020-01-14 22:44 ` [PATCH bpf-next 3/5] libbpf: Expose bpf_find_kernel_btf to libbpf_internal.h Martin KaFai Lau
2020-01-15 1:43 ` Andrii Nakryiko
2020-01-15 5:56 ` Martin Lau
2020-01-14 22:44 ` [PATCH bpf-next 4/5] bpftool: Add struct_ops map name Martin KaFai Lau
2020-01-15 1:45 ` Andrii Nakryiko
2020-01-14 22:44 ` [PATCH bpf-next 5/5] bpftool: Support dumping a map with btf_vmlinux_value_type_id Martin KaFai Lau
2020-01-15 1:49 ` Andrii Nakryiko
2020-01-15 6:04 ` Martin Lau
2020-01-15 6:39 ` Andrii Nakryiko
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=CAEf4BzbrcKLKvgKY+nSxV22T2nHgucmB2N01bEQiXS+g7npQfw@mail.gmail.com \
--to=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=paul.chaignon@orange.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;
as well as URLs for NNTP newsgroup(s).