All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Cc: "Hangbin Liu" <liuhangbin@gmail.com>, bpf <bpf@vger.kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"Andrii Nakryiko" <andriin@fb.com>,
	Networking <netdev@vger.kernel.org>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>
Subject: Re: [PATCH libbpf] libbpf: check if pin_path was set even map fd exist
Date: Fri, 2 Oct 2020 11:13:41 -0700	[thread overview]
Message-ID: <CAEf4BzZBCYSdYxpAJ_gv0jRpuvTObpobQVccoqmsYVybgmfbxg@mail.gmail.com> (raw)
In-Reply-To: <20201002114936.GA20275@ranger.igk.intel.com>

On Fri, Oct 2, 2020 at 4:56 AM Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> On Fri, Oct 02, 2020 at 03:57:50PM +0800, Hangbin Liu wrote:
> > Say a user reuse map fd after creating a map manually and set the
> > pin_path, then load the object via libbpf.
> >
> > In libbpf bpf_object__create_maps(), bpf_object__reuse_map() will
> > return 0 if there is no pinned map in map->pin_path. Then after
> > checking if map fd exist, we should also check if pin_path was set
> > and do bpf_map__pin() instead of continue the loop.
> >
> > Fix it by creating map if fd not exist and continue checking pin_path
> > after that.
> >
> > Suggested-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
> > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> > ---
> >  tools/lib/bpf/libbpf.c | 75 +++++++++++++++++++++---------------------
> >  1 file changed, 37 insertions(+), 38 deletions(-)
> >

[...]

> > +
> > +                     if (map->init_slots_sz) {
>
> Couldn't we flatten the code by inverting the logic here and using goto?

I explicitly asked Hangbin to not use goto to alter control flow here,
I'd like to keep goto within libbpf mostly for error handling.

>
>         if (!map->init_slot_sz) {
>                 pr_debug("map '%s': skipping creation (preset fd=%d)\n",
>                          map->name, map->fd);
>                 goto map_pin;
>         }
>
>         (...)
> map_pin:
>         if (map->pin_path && !map->pinned) {
>
> If I'm reading this right.
>

[...]

> > --
> > 2.25.4
> >

  reply	other threads:[~2020-10-02 18:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02  7:57 [PATCH libbpf] libbpf: check if pin_path was set even map fd exist Hangbin Liu
2020-10-02 11:49 ` Maciej Fijalkowski
2020-10-02 18:13   ` Andrii Nakryiko [this message]
2020-10-02 18:11 ` Andrii Nakryiko
2020-10-03  8:55 ` [PATCHv2 bpf 0/3] Fix pining maps after reuse map fd Hangbin Liu
2020-10-03  8:55   ` [PATCHv2 bpf 1/3] libbpf: close map fd if init map slots failed Hangbin Liu
2020-10-05 21:21     ` Andrii Nakryiko
2020-10-03  8:55   ` [PATCHv2 bpf 2/3] libbpf: check if pin_path was set even map fd exist Hangbin Liu
2020-10-05 21:22     ` Andrii Nakryiko
2020-10-03  8:55   ` [PATCHv2 bpf 3/3] selftest/bpf: test pinning map with reused map fd Hangbin Liu
2020-10-05 21:28     ` Andrii Nakryiko
2020-10-06  2:13   ` [PATCHv3 bpf 0/3] Fix pining maps after reuse " Hangbin Liu
2020-10-06  2:13     ` [PATCHv3 bpf 1/3] libbpf: close map fd if init map slots failed Hangbin Liu
2020-10-06  2:13     ` [PATCHv3 bpf 2/3] libbpf: check if pin_path was set even map fd exist Hangbin Liu
2020-10-06  2:13     ` [PATCHv3 bpf 3/3] selftest/bpf: test pinning map with reused map fd Hangbin Liu
2020-10-06  3:26       ` Andrii Nakryiko
2020-10-06 18:40     ` [PATCHv3 bpf 0/3] Fix pining maps after reuse " patchwork-bot+bpf

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=CAEf4BzZBCYSdYxpAJ_gv0jRpuvTObpobQVccoqmsYVybgmfbxg@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=liuhangbin@gmail.com \
    --cc=maciej.fijalkowski@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --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.