Message ID | 20210331164504.320614-7-yauheni.kaliuta@redhat.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | bpf/selftests: page size fixes | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for bpf-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | warning | 8 maintainers not CCed: netdev@vger.kernel.org yhs@fb.com kpsingh@kernel.org daniel@iogearbox.net kafai@fb.com ast@kernel.org john.fastabend@gmail.com songliubraving@fb.com |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | fail | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | fail | ERROR: code indent should use tabs where possible WARNING: please, no spaces at the start of a line |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
On Wed, Mar 31, 2021 at 9:45 AM Yauheni Kaliuta <yauheni.kaliuta@redhat.com> wrote: > > From: Andrii Nakryiko <andrii.nakryiko@gmail.com> > > 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: Yauheni Kaliuta <yauheni.kaliuta@redhat.com> > --- > tools/lib/bpf/libbpf.c | 10 ++++++++++ > tools/lib/bpf/libbpf.h | 1 + > tools/lib/bpf/libbpf.map | 1 + > 3 files changed, 12 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 7aad78dbb4b4..b48dc380059d 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -2194,6 +2194,7 @@ static int parse_btf_map_def(struct bpf_object *obj, > map->inner_map = calloc(1, sizeof(*map->inner_map)); > if (!map->inner_map) > return -ENOMEM; > + map->inner_map->fd = -1; > map->inner_map->sec_idx = obj->efile.btf_maps_shndx; > map->inner_map->name = malloc(strlen(map->name) + > sizeof(".inner") + 1); > @@ -3845,6 +3846,14 @@ __u32 bpf_map__max_entries(const struct bpf_map *map) > 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) > { > if (map->fd >= 0) > @@ -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"); > return -EINVAL; > } > + zfree(&map->inner_map); > map->inner_map_fd = fd; > return 0; > } > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h > index f500621d28e5..bec4e6a6e31d 100644 > --- a/tools/lib/bpf/libbpf.h > +++ b/tools/lib/bpf/libbpf.h > @@ -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__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); > > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > index f5990f7208ce..eeb6d5ebd1cc 100644 > --- a/tools/lib/bpf/libbpf.map > +++ b/tools/lib/bpf/libbpf.map > @@ -360,4 +360,5 @@ LIBBPF_0.4.0 { > bpf_linker__free; > bpf_linker__new; > bpf_object__set_kversion; > + bpf_map__inner_map; please keep the list sorted alphabetically > } LIBBPF_0.3.0; > -- > 2.31.1 >
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7aad78dbb4b4..b48dc380059d 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2194,6 +2194,7 @@ static int parse_btf_map_def(struct bpf_object *obj, map->inner_map = calloc(1, sizeof(*map->inner_map)); if (!map->inner_map) return -ENOMEM; + map->inner_map->fd = -1; map->inner_map->sec_idx = obj->efile.btf_maps_shndx; map->inner_map->name = malloc(strlen(map->name) + sizeof(".inner") + 1); @@ -3845,6 +3846,14 @@ __u32 bpf_map__max_entries(const struct bpf_map *map) 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) { if (map->fd >= 0) @@ -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"); return -EINVAL; } + zfree(&map->inner_map); map->inner_map_fd = fd; return 0; } diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index f500621d28e5..bec4e6a6e31d 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -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__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); diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index f5990f7208ce..eeb6d5ebd1cc 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -360,4 +360,5 @@ LIBBPF_0.4.0 { bpf_linker__free; bpf_linker__new; bpf_object__set_kversion; + bpf_map__inner_map; } LIBBPF_0.3.0;