OSDN Git Service

Merge branch 'bpftool: Switch to libbpf's hashmap for referencing BPF objects'
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 26 Oct 2021 00:31:39 +0000 (17:31 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 26 Oct 2021 00:31:39 +0000 (17:31 -0700)
commit9327acd0f9a49394e6567ac79dd55635527e1f56
tree3e31240e3364c28bc0a4cdd1840b0c78018be12d
parent57c8d362cefe5ff4ee9784e15318c0d1c617d408
parentd6699f8e0f834b40db35466f704705ae757be11a
Merge branch 'bpftool: Switch to libbpf's hashmap for referencing BPF objects'

Quentin Monnet says:

====================

When listing BPF objects, bpftool can print a number of properties about
items holding references to these objects. For example, it can show pinned
paths for BPF programs, maps, and links; or programs and maps using a given
BTF object; or the names and PIDs of processes referencing BPF objects. To
collect this information, bpftool uses hash maps (to be clear: the data
structures, inside bpftool - we are not talking of BPF maps). It uses the
implementation available from the kernel, and picks it up from
tools/include/linux/hashtable.h.

This patchset converts bpftool's hash maps to a distinct implementation
instead, the one coming with libbpf. The main motivation for this change is
that it should ease the path towards a potential out-of-tree mirror for
bpftool, like the one libbpf already has. Although it's not perfect to
depend on libbpf's internal components, bpftool is intimately tied with the
library anyway, and this looks better than depending too much on (non-UAPI)
kernel headers.

The first two patches contain preparatory work on the Makefile and on the
initialisation of the hash maps for collecting pinned paths for objects.
Then the transition is split into several steps, one for each kind of
properties for which the collection is backed by hash maps.

v2:
  - Move hashmap cleanup for pinned paths for links from do_detach() to
    do_show().
  - Handle errors on hashmap__append() (in three of the patches).
  - Rename bpftool_hash_fn() and bpftool_equal_fn() as hash_fn_for_key_id()
    and equal_fn_for_key_id(), respectively.
  - Add curly braces for hashmap__for_each_key_entry() { } in
    show_btf_plain() and show_btf_json(), where the flow was difficult to
    read.
====================

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>