bpftool: Stop using bpf_map__def() API

libbpf bpf_map__def() API is being deprecated, replace bpftool's
usage with the appropriate getters and setters

Signed-off-by: Christy Lee <christylee@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220108004218.355761-3-christylee@fb.com
This commit is contained in:
Christy Lee 2022-01-07 16:42:15 -08:00 committed by Andrii Nakryiko
parent 76acfce664
commit 3c28919f06
2 changed files with 7 additions and 9 deletions

View File

@ -227,7 +227,7 @@ static int codegen_datasecs(struct bpf_object *obj, const char *obj_name)
/* only generate definitions for memory-mapped internal maps */ /* only generate definitions for memory-mapped internal maps */
if (!bpf_map__is_internal(map)) if (!bpf_map__is_internal(map))
continue; continue;
if (!(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE)) if (!(bpf_map__map_flags(map) & BPF_F_MMAPABLE))
continue; continue;
if (!get_map_ident(map, map_ident, sizeof(map_ident))) if (!get_map_ident(map, map_ident, sizeof(map_ident)))
@ -468,7 +468,7 @@ static void codegen_destroy(struct bpf_object *obj, const char *obj_name)
if (!get_map_ident(map, ident, sizeof(ident))) if (!get_map_ident(map, ident, sizeof(ident)))
continue; continue;
if (bpf_map__is_internal(map) && if (bpf_map__is_internal(map) &&
(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE)) (bpf_map__map_flags(map) & BPF_F_MMAPABLE))
printf("\tmunmap(skel->%1$s, %2$zd);\n", printf("\tmunmap(skel->%1$s, %2$zd);\n",
ident, bpf_map_mmap_sz(map)); ident, bpf_map_mmap_sz(map));
codegen("\ codegen("\
@ -536,7 +536,7 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
continue; continue;
if (!bpf_map__is_internal(map) || if (!bpf_map__is_internal(map) ||
!(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE)) !(bpf_map__map_flags(map) & BPF_F_MMAPABLE))
continue; continue;
codegen("\ codegen("\
@ -600,10 +600,10 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
continue; continue;
if (!bpf_map__is_internal(map) || if (!bpf_map__is_internal(map) ||
!(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE)) !(bpf_map__map_flags(map) & BPF_F_MMAPABLE))
continue; continue;
if (bpf_map__def(map)->map_flags & BPF_F_RDONLY_PROG) if (bpf_map__map_flags(map) & BPF_F_RDONLY_PROG)
mmap_flags = "PROT_READ"; mmap_flags = "PROT_READ";
else else
mmap_flags = "PROT_READ | PROT_WRITE"; mmap_flags = "PROT_READ | PROT_WRITE";
@ -961,7 +961,7 @@ static int do_skeleton(int argc, char **argv)
i, bpf_map__name(map), i, ident); i, bpf_map__name(map), i, ident);
/* memory-mapped internal maps */ /* memory-mapped internal maps */
if (bpf_map__is_internal(map) && if (bpf_map__is_internal(map) &&
(bpf_map__def(map)->map_flags & BPF_F_MMAPABLE)) { (bpf_map__map_flags(map) & BPF_F_MMAPABLE)) {
printf("\ts->maps[%zu].mmaped = (void **)&obj->%s;\n", printf("\ts->maps[%zu].mmaped = (void **)&obj->%s;\n",
i, ident); i, ident);
} }

View File

@ -480,7 +480,6 @@ static int do_unregister(int argc, char **argv)
static int do_register(int argc, char **argv) static int do_register(int argc, char **argv)
{ {
LIBBPF_OPTS(bpf_object_open_opts, open_opts); LIBBPF_OPTS(bpf_object_open_opts, open_opts);
const struct bpf_map_def *def;
struct bpf_map_info info = {}; struct bpf_map_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
int nr_errs = 0, nr_maps = 0; int nr_errs = 0, nr_maps = 0;
@ -510,8 +509,7 @@ static int do_register(int argc, char **argv)
} }
bpf_object__for_each_map(map, obj) { bpf_object__for_each_map(map, obj) {
def = bpf_map__def(map); if (bpf_map__type(map) != BPF_MAP_TYPE_STRUCT_OPS)
if (def->type != BPF_MAP_TYPE_STRUCT_OPS)
continue; continue;
link = bpf_map__attach_struct_ops(map); link = bpf_map__attach_struct_ops(map);