From: Maciej Fijalkowski <maciejromanfijalkowski@gmail•com>
To: Daniel Borkmann <daniel@iogearbox•net>
Cc: ast@kernel•org, netdev@vger•kernel.org,
jakub.kicinski@netronome•com, brouer@redhat•com
Subject: Re: [PATCH bpf-next v2 1/8] libbpf: Add a helper for retrieving a map fd for a given name
Date: Wed, 23 Jan 2019 15:03:50 +0100 [thread overview]
Message-ID: <20190123150350.00004569@gmail.com> (raw)
In-Reply-To: <3597b94e-f4f2-473e-b7be-e7493f287d98@iogearbox.net>
On Wed, 23 Jan 2019 11:54:41 +0100
Daniel Borkmann <daniel@iogearbox•net> wrote:
> On 01/21/2019 10:10 AM, Maciej Fijalkowski wrote:
> > XDP samples are mostly cooperating with eBPF maps through their file
> > descriptors. In case of a eBPF program that contains multiple maps it
> > might be tiresome to iterate through them and call bpf_map__fd for each
> > one. Add a helper mostly based on bpf_object__find_map_by_name, but
> > instead of returning the struct bpf_map pointer, return map fd.
> >
> > Bump libbpf ABI version to 0.0.2.
> >
> > Suggested-by: Jakub Kicinski <jakub.kicinski@netronome•com>
> > Signed-off-by: Maciej Fijalkowski <maciejromanfijalkowski@gmail•com>
> > Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome•com>
> > ---
> > tools/lib/bpf/libbpf.c | 12 ++++++++++++
> > tools/lib/bpf/libbpf.h | 3 +++
> > tools/lib/bpf/libbpf.map | 4 ++++
> > 3 files changed, 19 insertions(+)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 169e347c76f6..dc838bea403f 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -2840,6 +2840,18 @@ bpf_object__find_map_by_name(struct bpf_object *obj, const char *name)
> > return NULL;
> > }
>
> Application could just do: bpf_map__fd(bpf_object__find_map_by_name(...)) or
> bpf_object__find_map_by_name(...)->fd as both are exposed via library, though
> I guess it may be okay to have a helper for it as it feels this might be needed
> in many cases.
>
> > +int
> > +bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name)
> > +{
> > + struct bpf_map *pos;
> > +
> > + bpf_map__for_each(pos, obj) {
> > + if (pos->name && !strcmp(pos->name, name))
> > + return bpf_map__fd(pos);
> > + }
> > + return -ENOENT;
>
> Can we instead just do:
>
> int
> bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name)
> {
> return bpf_map__fd(bpf_object__find_map_by_name(obj, name));
> }
>
Yes of course, I will send v3 once we figure out what's the best way to supply
the prog section name for xdp_redirect_cpu.
> > +}
> > +
> > struct bpf_map *
> > bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
> > {
> > diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> > index 5f68d7b75215..7f10d36abdde 100644
> > --- a/tools/lib/bpf/libbpf.h
> > +++ b/tools/lib/bpf/libbpf.h
> > @@ -264,6 +264,9 @@ struct bpf_map;
> > LIBBPF_API struct bpf_map *
> > bpf_object__find_map_by_name(struct bpf_object *obj, const char *name);
> >
> > +LIBBPF_API int
> > +bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name);
> > +
> > /*
> > * Get bpf_map through the offset of corresponding struct bpf_map_def
> > * in the BPF object file.
> > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> > index cd02cd4e2cc3..7c59e4f64082 100644
> > --- a/tools/lib/bpf/libbpf.map
> > +++ b/tools/lib/bpf/libbpf.map
> > @@ -124,3 +124,7 @@ LIBBPF_0.0.1 {
> > local:
> > *;
> > };
> > +LIBBPF_0.0.2 {
> > + global:
> > + bpf_object__find_map_fd_by_name;
> > +} LIBBPF_0.0.1;
> >
>
next prev parent reply other threads:[~2019-01-23 14:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-21 9:10 [PATCH bpf-next v2 0/8] xdp: Avoid unloading xdp prog not attached by sample Maciej Fijalkowski
2019-01-21 9:10 ` [PATCH bpf-next v2 1/8] libbpf: Add a helper for retrieving a map fd for a given name Maciej Fijalkowski
2019-01-23 10:54 ` Daniel Borkmann
2019-01-23 14:03 ` Maciej Fijalkowski [this message]
2019-01-21 9:10 ` [PATCH bpf-next v2 2/8] libbpf: Add a helper for retrieving a prog via index Maciej Fijalkowski
2019-01-23 10:41 ` Daniel Borkmann
2019-01-23 13:41 ` Maciej Fijalkowski
2019-01-23 14:11 ` Daniel Borkmann
2019-01-23 14:24 ` Jesper Dangaard Brouer
2019-01-24 11:56 ` Daniel Borkmann
2019-01-24 12:09 ` Jesper Dangaard Brouer
2019-01-24 18:27 ` Maciej Fijałkowski
2019-01-24 18:59 ` Jakub Kicinski
2019-01-21 9:10 ` [PATCH bpf-next v2 3/8] samples/bpf: xdp_redirect_cpu have not need for read_trace_pipe Maciej Fijalkowski
2019-01-21 9:10 ` [PATCH bpf-next v2 4/8] samples: bpf: Convert XDP samples to libbpf usage Maciej Fijalkowski
2019-01-21 9:10 ` [PATCH bpf-next v2 5/8] samples: bpf: Extend RLIMIT_MEMLOCK for xdp_{sample_pkts, router_ipv4} Maciej Fijalkowski
2019-01-21 9:10 ` [PATCH bpf-next v2 6/8] samples: bpf: Add a "force" flag to XDP samples Maciej Fijalkowski
2019-01-21 9:10 ` [PATCH bpf-next v2 7/8] libbpf: Add a support for getting xdp prog id on ifindex Maciej Fijalkowski
2019-01-21 9:10 ` [PATCH bpf-next v2 8/8] samples: bpf: Check the prog id before exiting Maciej Fijalkowski
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=20190123150350.00004569@gmail.com \
--to=maciejromanfijalkowski@gmail$(echo .)com \
--cc=ast@kernel$(echo .)org \
--cc=brouer@redhat$(echo .)com \
--cc=daniel@iogearbox$(echo .)net \
--cc=jakub.kicinski@netronome$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox