[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzbrcKLKvgKY+nSxV22T2nHgucmB2N01bEQiXS+g7npQfw@mail.gmail.com>
Date: Tue, 14 Jan 2020 17:34:33 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Martin KaFai Lau <kafai@...com>
Cc: bpf <bpf@...r.kernel.org>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
David Miller <davem@...emloft.net>,
Kernel Team <kernel-team@...com>,
Networking <netdev@...r.kernel.org>,
Paul Chaignon <paul.chaignon@...nge.com>
Subject: Re: [PATCH bpf-next 2/5] bpftool: Fix missing BTF output for json
during map dump
On Tue, Jan 14, 2020 at 2:45 PM Martin KaFai Lau <kafai@...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@...nge.com>
> Signed-off-by: Martin KaFai Lau <kafai@...com>
> ---
just one nit below
Acked-by: Andrii Nakryiko <andriin@...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;
> + }
[...]
Powered by blists - more mailing lists