Re: [PATCH bpf-next 3/9] samples: bpf: refactor test_cgrp2_sock2 program with libbpf

"Daniel T. Lee" <[email protected]>
Newsgroups org.kernel.vger.xdp-newbies,org.kernel.vger.bpf,org.kernel.vger.netdev
Message-ID <CAEKGpzi8suN-ftSiERx4WT2y1vtq+=L=0aBYva8NgYmhkWbNeA@mail.gmail.com>
On Wed, Nov 18, 2020 at 12:02 PM Andrii Nakryiko
<[email protected]> wrote:
>
> On Tue, Nov 17, 2020 at 6:57 AM Daniel T. Lee <[email protected]> wrote:
> >
> > This commit refactors the existing cgroup program with libbpf bpf
> > loader. The original test_cgrp2_sock2 has keeped the bpf program
> > attached to the cgroup hierarchy even after the exit of user program.
> > To implement the same functionality with libbpf, this commit uses the
> > BPF_LINK_PINNING to pin the link attachment even after it is closed.
> >
> > Since this uses LINK instead of ATTACH, detach of bpf program from
> > cgroup with 'test_cgrp2_sock' is not used anymore.
> >
> > The code to mount the bpf was added to the .sh file in case the bpff
> > was not mounted on /sys/fs/bpf. Additionally, to fix the problem that
> > shell script cannot find the binary object from the current path,
> > relative path './' has been added in front of binary.
> >
> > Signed-off-by: Daniel T. Lee <[email protected]>
> > ---
> >  samples/bpf/Makefile            |  2 +-
> >  samples/bpf/test_cgrp2_sock2.c  | 63 ++++++++++++++++++++++++---------
> >  samples/bpf/test_cgrp2_sock2.sh | 21 ++++++++---
> >  3 files changed, 64 insertions(+), 22 deletions(-)
> >
>
> [...]
>
> >
> > -       return EXIT_SUCCESS;
> > +       err = bpf_link__pin(link, link_pin_path);
> > +       if (err < 0) {
> > +               printf("err : %d\n", err);
>
> more meaningful error message would be helpful
>

Thanks for pointing out, I will fix it directly!

> > +               goto cleanup;
> > +       }
> > +
> > +       ret = EXIT_SUCCESS;
> > +
> > +cleanup:
> > +       if (ret != EXIT_SUCCESS)
> > +               bpf_link__destroy(link);
> > +
> > +       bpf_object__close(obj);
> > +       return ret;
> >  }
>
> [...]
>
> >
> >  function attach_bpf {
> > -       test_cgrp2_sock2 /tmp/cgroupv2/foo sock_flags_kern.o $1
> > +       ./test_cgrp2_sock2 /tmp/cgroupv2/foo sock_flags_kern.o $1
>
> Can you please add Fixes: tag for this?
>

Will add it in the next version of patch :)

Thanks for your time and effort for the review.

-- 
Best,
Daniel T. Lee
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.