"bpftool map dump" treats only ENOENT from bpf_map_get_next_key() as the end of the map. Map types that can't be iterated (local storage, ringbuf, bloom filter, arena, queue, stack) fail on the first key, and bpftool prints an empty dump, "[]" or "Found 0 elements", with only a non-zero exit status.
Patch 1 adds a helper that prints ENOTSUPP (524), which the kernel returns from some BPF commands, as "Operation not supported" instead of "Unknown error 524", and uses it for map create, map element operations, map freeze and prog run. Patch 2 asks for the first key before printing anything and fails with the map type and the error. Patch 3 adds a test_progs case on a socket storage map, and on a queue map without BTF for the plain output path. The new test fails without patches 1-2 and passes with them; the other bpftool_* selftests pass. v5 was tested on x86_64 under a bpf-next kernel (d2141481a764e). The ENOTSUPP message was also checked by hand for map getnext, lookup and dump on ringbuf and socket storage maps, map create of an LRU hash without preallocation, and prog run on a kprobe program; map delete, pop and freeze use the same helper but were not checked by hand. Changes in v5 (patches 1-2 of v4 are now patches 2-3): - new patch 1: helper for ENOTSUPP, used in map dump and the other places where bpftool prints the result of a command that can return it (Daniel) - patch 2 (map dump) uses the helper; kept Quentin's Acked-by as the change is only the error string - selftests: check the full error text for socket storage - rebase on current bpf-next Changes in v4: - selftests: socket storage always has BTF, so the "Found" check could never fail there; check the count on a queue map without BTF instead, and fix the comment on create_sk_storage_map() (bpf-ci) - selftests: split into sk_storage and queue subtests, new subject - rebase on current bpf-next, patch 1 unchanged Changes in v3: - shorter comment on the probe (Quentin) - selftests: unlink the pin on every exit path, so a killed run doesn't leave a stale pin that fails every later run with EEXIST (Sashiko) - collect Acked-by on patch 1 Changes in v2: - probe the first key before any output instead of printing a hint for ENOTSUPP only, so every non-iterable type gets an error and stdout gets no "[]" (Alexei) - drop the Fixes tag and use a neutral example map (Alexei) - selftests: check that JSON output is only the error object and plain stdout has no elements or count; clear the output buffer before each run (Sashiko) - multi-line comment style (bpf-ci) v4: https://lore.kernel.org/bpf/[email protected]/ v3: https://lore.kernel.org/bpf/[email protected]/ v2: https://lore.kernel.org/bpf/[email protected]/ v1: https://lore.kernel.org/bpf/[email protected]/ Maxim Skokov (3): bpftool: Print ENOTSUPP as "Operation not supported" bpftool: Fail map dump for maps that can't be iterated selftests/bpf: Test bpftool map dump on maps that can't be iterated tools/bpf/bpftool/common.c | 11 ++ tools/bpf/bpftool/main.h | 1 + tools/bpf/bpftool/map.c | 40 ++++-- tools/bpf/bpftool/prog.c | 2 +- .../bpf/prog_tests/bpftool_map_dump.c | 133 ++++++++++++++++++ 5 files changed, 175 insertions(+), 12 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/bpftool_map_dump.c base-commit: d2141481a764efdfaac70965ea28e8925f6a6b80 -- 2.47.3
