All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hangbin Liu <liuhangbin@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Networking <netdev@vger.kernel.org>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Jiri Benc" <jbenc@redhat.com>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>
Subject: Re: [PATCH bpf-next] libbpf: export bpf_object__reuse_map() to libbpf api
Date: Thu, 1 Oct 2020 19:34:25 +0800	[thread overview]
Message-ID: <CAPwn2JT6KGPxKD0fGZLfR8EsRHhYcfbvCATWO9WsiH_wqhheFg@mail.gmail.com> (raw)
In-Reply-To: <CAEf4BzYVVUq=eNwb4Z1JkVmRc4i+nxC4zWxbv2qGQAs-2cxkhw@mail.gmail.com>

On Thu, 1 Oct 2020 at 02:30, Andrii Nakryiko <andrii.nakryiko@gmail.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

  reply	other threads:[~2020-10-01 11:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29  3:18 [PATCH bpf-next] libbpf: export bpf_object__reuse_map() to libbpf api Hangbin Liu
2020-09-29  3:30 ` Andrii Nakryiko
2020-09-29  9:42   ` Hangbin Liu
2020-09-29 23:03     ` Andrii Nakryiko
2020-09-30  2:34       ` Hangbin Liu
2020-09-30 18:30         ` Andrii Nakryiko
2020-10-01 11:34           ` Hangbin Liu [this message]
2020-10-01 18:17             ` Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPwn2JT6KGPxKD0fGZLfR8EsRHhYcfbvCATWO9WsiH_wqhheFg@mail.gmail.com \
    --to=liuhangbin@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=jbenc@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=stephen@networkplumber.org \
    --cc=toke@redhat.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.