Skip to content

Commit

Permalink
libbpf: Add bpf_map__pin_path function
Browse files Browse the repository at this point in the history
Add bpf_map__pin_path, so that the inconsistently named
bpf_map__get_pin_path can be deprecated later. This is part of the
effort towards libbpf v1.0: libbpf/libbpf#307

Also, add a selftest for the new function.

Signed-off-by: Evgeniy Litvinenko <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
evgeniy-litvinenko authored and anakryiko committed Jul 23, 2021
1 parent d9e8d14 commit e244d34
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8511,6 +8511,11 @@ const char *bpf_map__get_pin_path(const struct bpf_map *map)
return map->pin_path;
}

const char *bpf_map__pin_path(const struct bpf_map *map)
{
return map->pin_path;
}

bool bpf_map__is_pinned(const struct bpf_map *map)
{
return map->pinned;
Expand Down
1 change: 1 addition & 0 deletions tools/lib/bpf/libbpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ LIBBPF_API bool bpf_map__is_offload_neutral(const struct bpf_map *map);
LIBBPF_API bool bpf_map__is_internal(const struct bpf_map *map);
LIBBPF_API int bpf_map__set_pin_path(struct bpf_map *map, const char *path);
LIBBPF_API const char *bpf_map__get_pin_path(const struct bpf_map *map);
LIBBPF_API const char *bpf_map__pin_path(const struct bpf_map *map);
LIBBPF_API bool bpf_map__is_pinned(const struct bpf_map *map);
LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path);
LIBBPF_API int bpf_map__unpin(struct bpf_map *map, const char *path);
Expand Down
1 change: 1 addition & 0 deletions tools/lib/bpf/libbpf.map
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ LIBBPF_0.4.0 {
LIBBPF_0.5.0 {
global:
bpf_map__initial_value;
bpf_map__pin_path;
bpf_map_lookup_and_delete_elem_flags;
bpf_program__attach_kprobe_opts;
bpf_object__gen_loader;
Expand Down
9 changes: 9 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/pinning.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ void test_pinning(void)
if (CHECK(err, "pin maps", "err %d errno %d\n", err, errno))
goto out;

/* get pinning path */
if (!ASSERT_STREQ(bpf_map__pin_path(map), pinpath, "get pin path"))
goto out;

/* set pinning path of other map and re-pin all */
map = bpf_object__find_map_by_name(obj, "nopinmap");
if (CHECK(!map, "find map", "NULL map"))
Expand All @@ -134,6 +138,11 @@ void test_pinning(void)
if (CHECK(err, "set pin path", "err %d errno %d\n", err, errno))
goto out;

/* get pinning path after set */
if (!ASSERT_STREQ(bpf_map__pin_path(map), custpinpath,
"get pin path after set"))
goto out;

/* should only pin the one unpinned map */
err = bpf_object__pin_maps(obj, NULL);
if (CHECK(err, "pin maps", "err %d errno %d\n", err, errno))
Expand Down

0 comments on commit e244d34

Please sign in to comment.