]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Add auto-pinning of maps when loading BPF objects
authorToke Høiland-Jørgensen <toke@redhat.com>
Sat, 2 Nov 2019 11:09:41 +0000 (12:09 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 2 Nov 2019 19:35:07 +0000 (12:35 -0700)
commit9138870c5da74c43a6d3a714c2a5056b8458313c
tree7b6ca6a0a7bef478ad468e1fe5aff12cc10b4d95
parent86445c3969025f2fd124a49637ff4d02685ee356
libbpf: Add auto-pinning of maps when loading BPF objects

This adds support to libbpf for setting map pinning information as part of
the BTF map declaration, to get automatic map pinning (and reuse) on load.
The pinning type currently only supports a single PIN_BY_NAME mode, where
each map will be pinned by its name in a path that can be overridden, but
defaults to /sys/fs/bpf.

Since auto-pinning only does something if any maps actually have a
'pinning' BTF attribute set, we default the new option to enabled, on the
assumption that seamless pinning is what most callers want.

When a map has a pin_path set at load time, libbpf will compare the map
pinned at that location (if any), and if the attributes match, will re-use
that map instead of creating a new one. If no existing map is found, the
newly created map will instead be pinned at the location.

Programs wanting to customise the pinning can override the pinning paths
using bpf_map__set_pin_path() before calling bpf_object__load() (including
setting it to NULL to disable pinning of a particular map).

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/157269298092.394725.3966306029218559681.stgit@toke.dk
tools/lib/bpf/bpf_helpers.h
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h