diff mbox series

[bpf-next,3/3] bpftool: Fix pretty print dump for maps without BTF loaded

Message ID 20220204225823.339548-3-jolsa@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next,1/3] libbpf: Add names for auxiliary maps | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter warning Series does not have a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: hengqi.chen@gmail.com; 3 maintainers not CCed: quentin@isovalent.com kpsingh@kernel.org hengqi.chen@gmail.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: From:/Signed-off-by: email address mismatch: 'From: Jiri Olsa <jolsa@redhat.com>' != 'Signed-off-by: Jiri Olsa <jolsa@kernel.org>'
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary

Commit Message

Jiri Olsa Feb. 4, 2022, 10:58 p.m. UTC
The commit e5043894b21f ("bpftool: Use libbpf_get_error() to check
error") forced map dump with pretty print enabled to has BTF loaded,
which is not necessarily needed.

Keeping the libbpf_get_error call, but setting errno to 0 because
get_map_kv_btf does nothing for this case.

This fixes test_offload.py for me, which failed because of the
pretty print fails with:

   Test map dump...
   Traceback (most recent call last):
     File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 1251, in <module>
       _, entries = bpftool("map dump id %d" % (m["id"]))
     File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 169, in bpftool
       return tool("bpftool", args, {"json":"-p"}, JSON=JSON, ns=ns,
     File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 155, in tool
       ret, stdout = cmd(ns + name + " " + params + args,
     File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 109, in cmd
       return cmd_result(proc, include_stderr=include_stderr, fail=fail)
     File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 131, in cmd_result
       raise Exception("Command failed: %s\n%s" % (proc.args, stderr))
   Exception: Command failed: bpftool -p map dump id 4325

Fixes: e5043894b21f ("bpftool: Use libbpf_get_error() to check error")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/bpf/bpftool/map.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andrii Nakryiko Feb. 4, 2022, 11:08 p.m. UTC | #1
On Fri, Feb 4, 2022 at 2:58 PM Jiri Olsa <jolsa@redhat.com> wrote:
>
> The commit e5043894b21f ("bpftool: Use libbpf_get_error() to check
> error") forced map dump with pretty print enabled to has BTF loaded,
> which is not necessarily needed.
>
> Keeping the libbpf_get_error call, but setting errno to 0 because
> get_map_kv_btf does nothing for this case.
>
> This fixes test_offload.py for me, which failed because of the
> pretty print fails with:
>
>    Test map dump...
>    Traceback (most recent call last):
>      File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 1251, in <module>
>        _, entries = bpftool("map dump id %d" % (m["id"]))
>      File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 169, in bpftool
>        return tool("bpftool", args, {"json":"-p"}, JSON=JSON, ns=ns,
>      File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 155, in tool
>        ret, stdout = cmd(ns + name + " " + params + args,
>      File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 109, in cmd
>        return cmd_result(proc, include_stderr=include_stderr, fail=fail)
>      File "/root/bpf-next/tools/testing/selftests/bpf/./test_offload.py", line 131, in cmd_result
>        raise Exception("Command failed: %s\n%s" % (proc.args, stderr))
>    Exception: Command failed: bpftool -p map dump id 4325
>
> Fixes: e5043894b21f ("bpftool: Use libbpf_get_error() to check error")
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/bpf/bpftool/map.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index c66a3c979b7a..2ccf85042e75 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -862,6 +862,7 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
>         prev_key = NULL;
>
>         if (wtr) {
> +               errno = 0;

I don't think that's right. errno can be modified by something inside
get_map_kv_btf() so this is unreliable approach. It's better to change
get_map_kv_btf() to return an error explicitly and a btf pointer
separate from error. Because btf == NULL isn't necessarily due to an
error anymore.

>                 btf = get_map_kv_btf(info);
>                 err = libbpf_get_error(btf);
>                 if (err) {
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index c66a3c979b7a..2ccf85042e75 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -862,6 +862,7 @@  map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
 	prev_key = NULL;
 
 	if (wtr) {
+		errno = 0;
 		btf = get_map_kv_btf(info);
 		err = libbpf_get_error(btf);
 		if (err) {