Skip to content

libbpf: Textual representation of enums

Daniel Müller bpf 4 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest12 patches 1 replyApplied 12/12
  2. v312 patches 7 repliesSuperseded
  3. v212 patches 1 replySuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v112 patches11 repliesSuperseded

Changes in v4 from the cover letter

- use full string comparison for newly added attach types
- switched away from erroneously used kdoc-style comments
- removed unused prog_types variable and containing section from test_bpftool_synctypes.py
- adjusted wording in documentation of get_types_from_array function
- split various test_bpftool_synctypes.py changes into commits where they are required to eliminate temporary failures of this test

Patches in v4 All 12 applied

#Subject and filesSizeRepliesApplied
1/12libbpf: Introduce libbpf_bpf_prog_type_strtools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h tools/lib/bpf/libbpf.map+55 -00 repliesApplied
2/12selftests/bpf: Add test for libbpf_bpf_prog_type_strtools/testing/selftests/bpf/prog_tests/libbpf_str.c+57 -00 repliesApplied
3/12bpftool: Use libbpf_bpf_prog_type_strtools/bpf/bpftool/feature.c tools/bpf/bpftool/link.c tools/bpf/bpftool/main.h +3 more+65 -920 repliesApplied
4/12libbpf: Introduce libbpf_bpf_map_type_strtools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h tools/lib/bpf/libbpf.map+52 -00 repliesApplied
5/12selftests/bpf: Add test for libbpf_bpf_map_type_strtools/testing/selftests/bpf/prog_tests/libbpf_str.c+55 -10 repliesApplied
6/12bpftool: Use libbpf_bpf_map_type_strtools/bpf/bpftool/feature.c tools/bpf/bpftool/main.h tools/bpf/bpftool/map.c +1 more+71 -790 repliesApplied
7/12libbpf: Introduce libbpf_bpf_attach_type_strtools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h tools/lib/bpf/libbpf.map+64 -00 repliesApplied
8/12selftests/bpf: Add test for libbpf_bpf_attach_type_strtools/testing/selftests/bpf/prog_tests/libbpf_str.c+48 -00 repliesApplied
9/12bpftool: Use libbpf_bpf_attach_type_strtools/bpf/bpftool/Documentation/bpftool-cgroup.rst tools/bpf/bpftool/Documentation/bpftool-prog.rst tools/bpf/bpftool/bash-completion/bpftool +6 more+183 -1501 replyApplied
10/12libbpf: Introduce libbpf_bpf_link_type_strtools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h tools/lib/bpf/libbpf.map+31 -00 repliesApplied
11/12selftests/bpf: Add test for libbpf_bpf_link_type_strtools/testing/selftests/bpf/prog_tests/libbpf_str.c+48 -00 repliesApplied
12/12bpftool: Use libbpf_bpf_link_type_strtools/bpf/bpftool/link.c+10 -170 repliesApplied

Reviews trailers per patch

All 12 patches have a Reviewed-by or Acked-by.

PatchQuentin MonnetYonghong Song
1/12A-b A-b
2/12A-b A-b
3/12A-b A-b
4/12A-b A-b
5/12A-b A-b
6/12A-b
7/12A-b A-b
8/12A-b A-b
9/12A-b
10/12A-b A-b
11/12A-b A-b
12/12A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH bpf-next v4 00/12] libbpf: Textual representation of enums

This patch set introduces the means for querying a textual representation of the following BPF related enum types:
- enum bpf_map_type
- enum bpf_prog_type
- enum bpf_attach_type
- enum bpf_link_type

To make that possible, we introduce a new public function for each of the types:
libbpf_bpf_<type>_type_str.

Having a way to query a textual representation has been asked for in the past (by systemd, among others). Such representations can generally be useful in tracing and logging contexts, among others. At this point, at least one client, bpftool, maintains such a mapping manually, which is prone to get out of date as new enum variants are introduced. libbpf is arguably best situated to keep this list complete and up-to-date. This patch series adds BTF based tests to ensure that exhaustiveness is upheld moving forward.

The libbpf provided textual representation can be inferred from the corresponding enum variant name by removing the prefix and lowercasing the remainder. E.g., BPF_PROG_TYPE_SOCKET_FILTER -> socket_filter. Unfortunately, bpftool does not use such a programmatic approach for some of the bpf_attach_type variants. We decided in favor of changing its behavior to work with libbpf representations. However, for user inputs, specifically, we do maintain support for the traditionally used names around (please see patch "bpftool: Use libbpf_bpf_attach_type_str").

The patch series is structured as follows:
- for each enumeration type in {bpf_prog_type, bpf_map_type, bpf_attach_type, bpf_link_type}:
- we first introduce the corresponding public libbpf API function
- we then add BTF based self-tests
- we lastly adjust bpftool to use the libbpf provided functionality

---
Changelog:
v3 -> v4:
- use full string comparison for newly added attach types
- switched away from erroneously used kdoc-style comments
- removed unused prog_types variable and containing section from test_bpftool_synctypes.py
- adjusted wording in documentation of get_types_from_array function
- split various test_bpftool_synctypes.py changes into commits where they are required to eliminate temporary failures of this test

v2 -> v3:
- use LIBBPF_1.0.0 section in libbpf.map for newly added exports

v1 -> v2:
- adjusted bpftool to work with algorithmically determined attach types as libbpf now uses (just removed prefix from enum name and lowercased the rest)
- adjusted tests, man page, and completion script to work with the new names
- renamed bpf_attach_type_str -> bpf_attach_type_input_str
- for input: added special cases that accept the traditionally used strings as well
- changed 'char const *' -> 'const char *'

Daniel Müller (12):
libbpf: Introduce libbpf_bpf_prog_type_str selftests/bpf: Add test for libbpf_bpf_prog_type_str
bpftool: Use libbpf_bpf_prog_type_str
libbpf: Introduce libbpf_bpf_map_type_str selftests/bpf: Add test for libbpf_bpf_map_type_str
bpftool: Use libbpf_bpf_map_type_str
libbpf: Introduce libbpf_bpf_attach_type_str selftests/bpf: Add test for libbpf_bpf_attach_type_str
bpftool: Use libbpf_bpf_attach_type_str
libbpf: Introduce libbpf_bpf_link_type_str selftests/bpf: Add test for libbpf_bpf_link_type_str
bpftool: Use libbpf_bpf_link_type_str

 .../bpftool/Documentation/bpftool-cgroup.rst  |  16 +-
 .../bpftool/Documentation/bpftool-prog.rst    |   5 +-
 tools/bpf/bpftool/bash-completion/bpftool     |  18 +-
 tools/bpf/bpftool/cgroup.c                    |  53 +++--
 tools/bpf/bpftool/common.c                    |  82 +++----
 tools/bpf/bpftool/feature.c                   |  87 +++++---
 tools/bpf/bpftool/link.c                      |  61 +++---
 tools/bpf/bpftool/main.h                      |  20 +-
 tools/bpf/bpftool/map.c                       |  82 +++----
 tools/bpf/bpftool/prog.c                      |  77 +++----
 tools/lib/bpf/libbpf.c                        | 160 ++++++++++++++
 tools/lib/bpf/libbpf.h                        |  36 +++
 tools/lib/bpf/libbpf.map                      |   6 +
 .../selftests/bpf/prog_tests/libbpf_str.c     | 207 ++++++++++++++++++
 .../selftests/bpf/test_bpftool_synctypes.py   | 166 ++++++--------
 15 files changed, 738 insertions(+), 338 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/libbpf_str.c
Signature · 1 line
2.30.2