[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPwn2JT6KGPxKD0fGZLfR8EsRHhYcfbvCATWO9WsiH_wqhheFg@mail.gmail.com>
Date: Thu, 1 Oct 2020 19:34:25 +0800
From: Hangbin Liu <liuhangbin@...il.com>
To: Andrii Nakryiko <andrii.nakryiko@...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 Thu, 1 Oct 2020 at 02:30, Andrii Nakryiko <andrii.nakryiko@...il.com> wrote:
> > 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.
Hi Andrii,
Looks I missed something, Would you like to explain why we should not use goto?
And for "guard map creation with the if", do you mean duplicate the
if (map->pin_path && !map->pinned) in if (map->fd >= 0)? like
diff --git a/src/libbpf.c b/src/libbpf.c
index 3df1f4d..705abcb 100644
--- a/src/libbpf.c
+++ b/src/libbpf.c
@@ -4215,6 +4215,15 @@ 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);
+ if (map->pin_path && !map->pinned) {
+ err = bpf_map__pin(map, NULL);
+ if (err) {
+ pr_warn("map '%s': failed to
auto-pin at '%s': %d\n",
+ map->name, map->pin_path, err);
+ zclose(map->fd);
+ goto err_out;
+ }
+ }
continue;
}
(Sorry if the code format got corrupted as I replied in web gmail....)
Thanks
Hangbin
Powered by blists - more mailing lists