bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: Andrii Nakryiko <andriin@fb.com>, bpf <bpf@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v2 bpf-next 2/3] libbpf: add bpf_object__open_{file,mem} w/ extensible opts
Date: Fri, 4 Oct 2019 08:29:11 -0700	[thread overview]
Message-ID: <CAEf4BzYvtZmi4p2xZUS0Obx-tcH2xV0=68EfeKLziAxsZW=XTQ@mail.gmail.com> (raw)
In-Reply-To: <87bluxow1a.fsf@toke.dk>

On Thu, Oct 3, 2019 at 11:38 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> Andrii Nakryiko <andriin@fb.com> writes:
>
> > Add new set of bpf_object__open APIs using new approach to optional
> > parameters extensibility allowing simpler ABI compatibility approach.
> >
> > This patch demonstrates an approach to implementing libbpf APIs that
> > makes it easy to extend existing APIs with extra optional parameters in
> > such a way, that ABI compatibility is preserved without having to do
> > symbol versioning and generating lots of boilerplate code to handle it.
> > To facilitate succinct code for working with options, add OPTS_VALID,
> > OPTS_HAS, and OPTS_GET macros that hide all the NULL, size, and zero
> > checks.
> >
> > Additionally, newly added libbpf APIs are encouraged to follow similar
> > pattern of having all mandatory parameters as formal function parameters
> > and always have optional (NULL-able) xxx_opts struct, which should
> > always have real struct size as a first field and the rest would be
> > optional parameters added over time, which tune the behavior of existing
> > API, if specified by user.
> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> >  tools/lib/bpf/libbpf.c          | 51 ++++++++++++++++++++++++++++-----
> >  tools/lib/bpf/libbpf.h          | 36 +++++++++++++++++++++--
> >  tools/lib/bpf/libbpf.map        |  3 ++
> >  tools/lib/bpf/libbpf_internal.h | 32 +++++++++++++++++++++
> >  4 files changed, 112 insertions(+), 10 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 056769ce4fd0..503fba903e99 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -3620,16 +3620,33 @@ struct bpf_object *bpf_object__open(const char *path)
> >       return bpf_object__open_xattr(&attr);
> >  }
> >
> > -struct bpf_object *bpf_object__open_buffer(void *obj_buf,
> > -                                        size_t obj_buf_sz,
> > -                                        const char *name)
> > +struct bpf_object *
> > +bpf_object__open_file(const char *path, struct bpf_object_open_opts *opts)
> > +{
> > +     if (!OPTS_VALID(opts, bpf_object_open_opts))
> > +             return ERR_PTR(-EINVAL);
> > +     if (!path)
> > +             return ERR_PTR(-EINVAL);
> > +
> > +     pr_debug("loading %s\n", path);
> > +
> > +     return __bpf_object__open(path, NULL, 0, 0);
> > +}
>
> This is not doing anything with opts...

oh, my bad, was concentrating on bpf_object__open_mem too much. Good
thing v3 is necessary anyway..

>
> [...]
>
> > +struct bpf_object_open_opts {
> > +     /* size of this struct, for forward/backward compatiblity */
> > +     size_t sz;
> > +     /* object name override, if provided:
> > +      * - for object open from file, this will override setting object
> > +      *   name from file path's base name;
>
> ... but this says it should be, no?
>
> -Toke
>

  reply	other threads:[~2019-10-04 15:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-04  5:32 [PATCH v2 bpf-next 0/3] Add new-style bpf_object__open APIs Andrii Nakryiko
2019-10-04  5:32 ` [PATCH v2 bpf-next 1/3] libbpf: stop enforcing kern_version, populate it for users Andrii Nakryiko
2019-10-04  5:32 ` [PATCH v2 bpf-next 2/3] libbpf: add bpf_object__open_{file,mem} w/ extensible opts Andrii Nakryiko
2019-10-04  6:38   ` Toke Høiland-Jørgensen
2019-10-04 15:29     ` Andrii Nakryiko [this message]
2019-10-04  5:32 ` [PATCH v2 bpf-next 3/3] selftests/bpf: switch tests to new bpf_object__open_{file,mem}() APIs 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='CAEf4BzYvtZmi4p2xZUS0Obx-tcH2xV0=68EfeKLziAxsZW=XTQ@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=toke@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).