OSDN Git Service

bpftool: Fix missing BTF output for json during map dump
authorMartin KaFai Lau <kafai@fb.com>
Wed, 15 Jan 2020 23:00:25 +0000 (15:00 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 15 Jan 2020 23:23:27 +0000 (15:23 -0800)
commit188a486619e6c9d7b8531ba6c4215b31304d293f
tree76c9146803a78148e3a9f31a8b123fec4e95965c
parentd7de72674af53c3839eff091899f18c221dd30d2
bpftool: Fix missing BTF output for json during map dump

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")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Cc: Paul Chaignon <paul.chaignon@orange.com>
Link: https://lore.kernel.org/bpf/20200115230025.1101828-1-kafai@fb.com
tools/bpf/bpftool/map.c