On Tue, Jan 14, 2020 at 05:34:33PM -0800, Andrii Nakryiko wrote: > On Tue, Jan 14, 2020 at 2:45 PM Martin KaFai Lau <kafai@xxxxxx> 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@xxxxxxxxxx> > > Signed-off-by: Martin KaFai Lau <kafai@xxxxxx> > > --- > > just one nit below > > Acked-by: Andrii Nakryiko <andriin@xxxxxx> > > > 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? There is other logic under the same "if (wtr)". Thus, it is better to leave it as is. and this indentation will be gone in patch 5. > > > > + err = btf__get_from_id(info->btf_id, &btf); > > + if (err || !btf) { > > + err = err ? : -ESRCH; > > + p_err("failed to get btf"); > > + goto exit_free; > > + } > > [...]