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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Nov 17, 2020 at 6:57 AM Daniel T. Lee <danieltimlee@xxxxxxxxx> 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 <danieltimlee@xxxxxxxxx>
> ---
>  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

> +               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?

>         [ $? -ne 0 ] && exit 1
>  }
>
>  function cleanup {
> -       if [ -d /tmp/cgroupv2/foo ]; then
> -               test_cgrp2_sock -d /tmp/cgroupv2/foo
> -       fi
> +       rm -rf $LINK_PIN
>         ip link del veth0b
>         ip netns delete at_ns0
>         umount /tmp/cgroupv2
> @@ -42,6 +51,7 @@ cleanup 2>/dev/null
>  set -e
>  config_device
>  config_cgroup
> +config_bpffs
>  set +e
>
>  #
> @@ -62,6 +72,9 @@ if [ $? -eq 0 ]; then
>         exit 1
>  fi
>
> +rm -rf $LINK_PIN
> +sleep 1                 # Wait for link detach
> +
>  #
>  # Test 2 - fail ping
>  #
> --
> 2.25.1
>



[Index of Archives]     [Linux Networking Development]     [Fedora Linux Users]     [Linux SCTP]     [DCCP]     [Gimp]     [Yosemite Campsites]

  Powered by Linux