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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 4, 2022 at 2:58 PM Jiri Olsa <jolsa@xxxxxxxxxx> 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@xxxxxxxxxx>
> ---
>  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
>



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux