On Tue, Sep 29, 2020 at 7:34 PM Hangbin Liu <liuhangbin@xxxxxxxxx> wrote: > > On Tue, Sep 29, 2020 at 04:03:45PM -0700, Andrii Nakryiko wrote: > > > bpf_map__set_pin_path() > > > bpf_create_map_in_map() <- create inner or outer map > > > bpf_map__reuse_fd(map, inner/outer_fd) > > > bpf_object__load(obj) > > > - bpf_object__load_xattr() > > > - bpf_object__create_maps() > > > - if (map->fd >= 0) > > > continue <- this will skip pinning map > > > > so maybe that's the part that needs to be fixed?.. > > Hmm...maybe, let me see > > > > > I'm still not sure. And to be honest your examples are still a bit too > > succinct for me to follow where the problem is exactly. Can you please > > elaborate a bit more? > > Let's take iproute2 legacy map for example, if it's a map-in-map type with > pin path defined. In user space we could do like: > > if (bpf_obj_get(pathname) < 0) { > bpf_create_map_in_map(); > bpf_map__reuse_fd(map, map_fd); > } > bpf_map__set_pin_path(map, pathname); > bpf_object__load(obj) > > So in libbpf we need > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 32dc444224d8..5412aa7169db 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -4215,7 +4215,7 @@ bpf_object__create_maps(struct bpf_object *obj) > if (map->fd >= 0) { > pr_debug("map '%s': skipping creation (preset fd=%d)\n", > map->name, map->fd); > - continue; > + goto check_pin_path; > } > > err = bpf_object__create_map(obj, map); > @@ -4258,6 +4258,7 @@ bpf_object__create_maps(struct bpf_object *obj) > map->init_slots_sz = 0; > } > > +check_pin_path: > if (map->pin_path && !map->pinned) { > err = bpf_map__pin(map, NULL); > if (err) { > > > Do you think if this change be better? Yes, of course. Just don't do it through use of goto. Guard map creation with that if instead. > > Thanks > Hangbin