BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [RFC PATCH bpf-next 2/5] libbpf: Refactor bpf_program_attach_fd()
Date: Sat, 9 Mar 2024 10:43:44 -0800	[thread overview]
Message-ID: <447531b4-a2a1-4921-b00d-871f522f1477@linux.dev> (raw)
In-Reply-To: <CAEf4Bza0sbBXRmFQDN82cE0=v7xiRqx5tcHG-tu+MwaLNqzn+w@mail.gmail.com>


On 3/8/24 5:02 PM, Andrii Nakryiko wrote:
> On Tue, Mar 5, 2024 at 12:22 PM Yonghong Song <yonghong.song@linux.dev> wrote:
>> Refactor function bpf_program_attach_fd() to provide a helper function
>> which has attach_type as one of input parameters. This will make later
>> libbpf change easier to understand.
>>
>> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
>> ---
>>   tools/lib/bpf/libbpf.c | 18 +++++++++++++-----
>>   1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 6c2979f1b471..97b573516675 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -12151,11 +12151,10 @@ static int attach_lsm(const struct bpf_program *prog, long cookie, struct bpf_li
>>   }
>>
>>   static struct bpf_link *
>> -bpf_program_attach_fd(const struct bpf_program *prog,
>> -                     int target_fd, const char *target_name,
>> -                     const struct bpf_link_create_opts *opts)
>> +__bpf_program_attach_fd(const struct bpf_program *prog, int target_fd,
> I hope we won't need this patch at all (see my comment on later
> patch), but if we do need to do this refactoring then a) let's not
> used underscore-prefixed names, this is not a common practice in
> libbpf code base and b) I think we can just update all callers of
> bpf_program_attach_fd() to pass attach_type directly, there are just 6
> of them.

I thought about this 'update all callers of bpf_program_attach_fd
' but did not do that since it needs to update all callers. But since
you suggest this I certainly can do this.

>
>> +                       enum bpf_attach_type attach_type, const char *target_name,
>> +                       const struct bpf_link_create_opts *opts)
>>   {
>> -       enum bpf_attach_type attach_type;
>>          char errmsg[STRERR_BUFSIZE];
>>          struct bpf_link *link;
>>          int prog_fd, link_fd;
>> @@ -12171,7 +12170,6 @@ bpf_program_attach_fd(const struct bpf_program *prog,
>>                  return libbpf_err_ptr(-ENOMEM);
>>          link->detach = &bpf_link__detach_fd;
>>
>> -       attach_type = bpf_program__expected_attach_type(prog);
>>          link_fd = bpf_link_create(prog_fd, target_fd, attach_type, opts);
>>          if (link_fd < 0) {
>>                  link_fd = -errno;
>> @@ -12185,6 +12183,16 @@ bpf_program_attach_fd(const struct bpf_program *prog,
>>          return link;
>>   }
>>
>> +static struct bpf_link *
>> +bpf_program_attach_fd(const struct bpf_program *prog,
>> +                     int target_fd, const char *target_name,
>> +                     const struct bpf_link_create_opts *opts)
>> +{
>> +       return __bpf_program_attach_fd(prog, target_fd,
>> +                                      bpf_program__expected_attach_type(prog),
>> +                                      target_name, opts);
>> +}
>> +
>>   struct bpf_link *
>>   bpf_program__attach_cgroup(const struct bpf_program *prog, int cgroup_fd)
>>   {
>> --
>> 2.43.0
>>

  reply	other threads:[~2024-03-09 18:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05 20:21 [RFC PATCH bpf-next 0/5] Add bpf_link support for sk_msg prog Yonghong Song
2024-03-05 20:22 ` [RFC PATCH bpf-next 1/5] bpf: Add link " Yonghong Song
2024-03-09  0:59   ` Andrii Nakryiko
2024-03-09 18:41     ` Yonghong Song
2024-03-10 19:23     ` Jakub Sitnicki
2024-03-11 21:58       ` Yonghong Song
2024-03-11  8:30   ` Jiri Olsa
2024-03-11 22:07     ` Yonghong Song
2024-03-05 20:22 ` [RFC PATCH bpf-next 2/5] libbpf: Refactor bpf_program_attach_fd() Yonghong Song
2024-03-09  1:02   ` Andrii Nakryiko
2024-03-09 18:43     ` Yonghong Song [this message]
2024-03-05 20:22 ` [RFC PATCH bpf-next 3/5] libbpf: Add link support for BPF_PROG_TYPE_SK_MSG Yonghong Song
2024-03-09  1:01   ` Andrii Nakryiko
2024-03-09 18:49     ` Yonghong Song
2024-03-05 20:22 ` [RFC PATCH bpf-next 4/5] bpftool: Add link dump support for BPF_LINK_TYPE_SK_MSG Yonghong Song
2024-03-08 16:07   ` Jakub Sitnicki
2024-03-11 21:54     ` Yonghong Song
2024-03-05 20:22 ` [RFC PATCH bpf-next 5/5] selftests/bpf: Add some tests with new bpf_program__attach_sk_msg() API Yonghong Song
2024-03-06 19:19 ` [RFC PATCH bpf-next 0/5] Add bpf_link support for sk_msg prog John Fastabend
2024-03-07 22:47   ` Yonghong Song
2024-03-07 13:01 ` Jakub Sitnicki
2024-03-11 21:53   ` Yonghong Song
2024-03-10 19:52 ` Jakub Sitnicki

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=447531b4-a2a1-4921-b00d-871f522f1477@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    /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