[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzYVVUq=eNwb4Z1JkVmRc4i+nxC4zWxbv2qGQAs-2cxkhw@mail.gmail.com>
Date: Wed, 30 Sep 2020 11:30:25 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Hangbin Liu <liuhangbin@...il.com>
Cc: bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>,
Toke Høiland-Jørgensen <toke@...hat.com>,
Jiri Benc <jbenc@...hat.com>,
Jesper Dangaard Brouer <brouer@...hat.com>,
Daniel Borkmann <daniel@...earbox.net>,
Alexei Starovoitov <ast@...nel.org>,
Stephen Hemminger <stephen@...workplumber.org>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>
Subject: Re: [PATCH bpf-next] libbpf: export bpf_object__reuse_map() to libbpf api
On Tue, Sep 29, 2020 at 7:34 PM Hangbin Liu <liuhangbin@...il.com> 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
Powered by blists - more mailing lists