Commit b3278099 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Andrii Nakryiko

libbpf: Add bpf_map__inner_map API

The API gives access to inner map for map in map types (array or
hash of map). It will be used to dynamically set max_entries in it.
Signed-off-by: default avatarYauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210408061310.95877-7-yauheni.kaliuta@redhat.com
parent 23a65766
...@@ -2194,6 +2194,7 @@ static int parse_btf_map_def(struct bpf_object *obj, ...@@ -2194,6 +2194,7 @@ static int parse_btf_map_def(struct bpf_object *obj,
map->inner_map = calloc(1, sizeof(*map->inner_map)); map->inner_map = calloc(1, sizeof(*map->inner_map));
if (!map->inner_map) if (!map->inner_map)
return -ENOMEM; return -ENOMEM;
map->inner_map->fd = -1;
map->inner_map->sec_idx = obj->efile.btf_maps_shndx; map->inner_map->sec_idx = obj->efile.btf_maps_shndx;
map->inner_map->name = malloc(strlen(map->name) + map->inner_map->name = malloc(strlen(map->name) +
sizeof(".inner") + 1); sizeof(".inner") + 1);
...@@ -3845,6 +3846,14 @@ __u32 bpf_map__max_entries(const struct bpf_map *map) ...@@ -3845,6 +3846,14 @@ __u32 bpf_map__max_entries(const struct bpf_map *map)
return map->def.max_entries; return map->def.max_entries;
} }
struct bpf_map *bpf_map__inner_map(struct bpf_map *map)
{
if (!bpf_map_type__is_map_in_map(map->def.type))
return NULL;
return map->inner_map;
}
int bpf_map__set_max_entries(struct bpf_map *map, __u32 max_entries) int bpf_map__set_max_entries(struct bpf_map *map, __u32 max_entries)
{ {
if (map->fd >= 0) if (map->fd >= 0)
...@@ -9476,6 +9485,7 @@ int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd) ...@@ -9476,6 +9485,7 @@ int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd)
pr_warn("error: inner_map_fd already specified\n"); pr_warn("error: inner_map_fd already specified\n");
return -EINVAL; return -EINVAL;
} }
zfree(&map->inner_map);
map->inner_map_fd = fd; map->inner_map_fd = fd;
return 0; return 0;
} }
......
...@@ -480,6 +480,7 @@ LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path); ...@@ -480,6 +480,7 @@ 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); LIBBPF_API int bpf_map__unpin(struct bpf_map *map, const char *path);
LIBBPF_API int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd); LIBBPF_API int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd);
LIBBPF_API struct bpf_map *bpf_map__inner_map(struct bpf_map *map);
LIBBPF_API long libbpf_get_error(const void *ptr); LIBBPF_API long libbpf_get_error(const void *ptr);
......
...@@ -359,5 +359,6 @@ LIBBPF_0.4.0 { ...@@ -359,5 +359,6 @@ LIBBPF_0.4.0 {
bpf_linker__finalize; bpf_linker__finalize;
bpf_linker__free; bpf_linker__free;
bpf_linker__new; bpf_linker__new;
bpf_map__inner_map;
bpf_object__set_kversion; bpf_object__set_kversion;
} LIBBPF_0.3.0; } LIBBPF_0.3.0;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment