* [PATCH bpf-next] libbpf: rename bpf_prog_attach_xattr to bpf_prog_attach_opts
@ 2021-12-30 0:01 Christy Lee
2022-01-05 23:44 ` Andrii Nakryiko
0 siblings, 1 reply; 2+ messages in thread
From: Christy Lee @ 2021-12-30 0:01 UTC (permalink / raw)
To: andrii, acme; +Cc: christyc.y.lee, bpf, kernel-team, ast, Christy Lee
All xattr APIs are being dropped, let's converge to the convention used in
high-level APIs and rename bpf_prog_attach_xattr to bpf_prog_attach_opts.
[0] Closes: https://github.com/libbpf/libbpf/issues/285
Signed-off-by: Christy Lee <christylee@fb.com>
---
tools/lib/bpf/bpf.c | 11 +++++++++--
tools/lib/bpf/bpf.h | 4 ++++
tools/lib/bpf/libbpf.map | 1 +
.../selftests/bpf/prog_tests/cgroup_attach_multi.c | 12 ++++++------
4 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 9b64eed2b003..19741cfcaf11 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -754,10 +754,10 @@ int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type,
.flags = flags,
);
- return bpf_prog_attach_xattr(prog_fd, target_fd, type, &opts);
+ return bpf_prog_attach_opts(prog_fd, target_fd, type, &opts);
}
-int bpf_prog_attach_xattr(int prog_fd, int target_fd,
+int bpf_prog_attach_opts(int prog_fd, int target_fd,
enum bpf_attach_type type,
const struct bpf_prog_attach_opts *opts)
{
@@ -778,6 +778,13 @@ int bpf_prog_attach_xattr(int prog_fd, int target_fd,
return libbpf_err_errno(ret);
}
+int bpf_prog_attach_xattr(int prog_fd, int target_fd,
+ enum bpf_attach_type type,
+ const struct bpf_prog_attach_opts *opts)
+{
+ return bpf_prog_attach_opts(prog_fd, target_fd, type, opts);
+}
+
int bpf_prog_detach(int target_fd, enum bpf_attach_type type)
{
union bpf_attr attr;
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 00619f64a040..5dc9fefe73f3 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -280,6 +280,10 @@ struct bpf_prog_attach_opts {
LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,
enum bpf_attach_type type, unsigned int flags);
+LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int attachable_fd,
+ enum bpf_attach_type type,
+ const struct bpf_prog_attach_opts *opts);
+LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_prog_attach_opts() instead")
LIBBPF_API int bpf_prog_attach_xattr(int prog_fd, int attachable_fd,
enum bpf_attach_type type,
const struct bpf_prog_attach_opts *opts);
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 529783967793..be2bb69d1a12 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -246,6 +246,7 @@ LIBBPF_0.0.8 {
bpf_link__update_program;
bpf_link_create;
bpf_link_update;
+ bpf_prog_attach_opts;
bpf_map__set_initial_value;
bpf_program__attach_cgroup;
bpf_program__attach_lsm;
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c b/tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c
index d3e8f729c623..38b3c47293da 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c
@@ -194,14 +194,14 @@ void serial_test_cgroup_attach_multi(void)
attach_opts.flags = BPF_F_ALLOW_OVERRIDE | BPF_F_REPLACE;
attach_opts.replace_prog_fd = allow_prog[0];
- if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
+ if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
BPF_CGROUP_INET_EGRESS, &attach_opts),
"fail_prog_replace_override", "unexpected success\n"))
goto err;
CHECK_FAIL(errno != EINVAL);
attach_opts.flags = BPF_F_REPLACE;
- if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
+ if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
BPF_CGROUP_INET_EGRESS, &attach_opts),
"fail_prog_replace_no_multi", "unexpected success\n"))
goto err;
@@ -209,7 +209,7 @@ void serial_test_cgroup_attach_multi(void)
attach_opts.flags = BPF_F_ALLOW_MULTI | BPF_F_REPLACE;
attach_opts.replace_prog_fd = -1;
- if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
+ if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
BPF_CGROUP_INET_EGRESS, &attach_opts),
"fail_prog_replace_bad_fd", "unexpected success\n"))
goto err;
@@ -217,7 +217,7 @@ void serial_test_cgroup_attach_multi(void)
/* replacing a program that is not attached to cgroup should fail */
attach_opts.replace_prog_fd = allow_prog[3];
- if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
+ if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
BPF_CGROUP_INET_EGRESS, &attach_opts),
"fail_prog_replace_no_ent", "unexpected success\n"))
goto err;
@@ -225,14 +225,14 @@ void serial_test_cgroup_attach_multi(void)
/* replace 1st from the top program */
attach_opts.replace_prog_fd = allow_prog[0];
- if (CHECK(bpf_prog_attach_xattr(allow_prog[6], cg1,
+ if (CHECK(bpf_prog_attach_opts(allow_prog[6], cg1,
BPF_CGROUP_INET_EGRESS, &attach_opts),
"prog_replace", "errno=%d\n", errno))
goto err;
/* replace program with itself */
attach_opts.replace_prog_fd = allow_prog[6];
- if (CHECK(bpf_prog_attach_xattr(allow_prog[6], cg1,
+ if (CHECK(bpf_prog_attach_opts(allow_prog[6], cg1,
BPF_CGROUP_INET_EGRESS, &attach_opts),
"prog_replace", "errno=%d\n", errno))
goto err;
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next] libbpf: rename bpf_prog_attach_xattr to bpf_prog_attach_opts
2021-12-30 0:01 [PATCH bpf-next] libbpf: rename bpf_prog_attach_xattr to bpf_prog_attach_opts Christy Lee
@ 2022-01-05 23:44 ` Andrii Nakryiko
0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2022-01-05 23:44 UTC (permalink / raw)
To: Christy Lee
Cc: Andrii Nakryiko, Arnaldo Carvalho de Melo, Christy Lee, bpf,
Kernel Team, Alexei Starovoitov
On Wed, Dec 29, 2021 at 4:01 PM Christy Lee <christylee@fb.com> wrote:
>
> All xattr APIs are being dropped, let's converge to the convention used in
> high-level APIs and rename bpf_prog_attach_xattr to bpf_prog_attach_opts.
>
> [0] Closes: https://github.com/libbpf/libbpf/issues/285
nit: please add two spaces in front of [0]
>
> Signed-off-by: Christy Lee <christylee@fb.com>
> ---
> tools/lib/bpf/bpf.c | 11 +++++++++--
> tools/lib/bpf/bpf.h | 4 ++++
> tools/lib/bpf/libbpf.map | 1 +
> .../selftests/bpf/prog_tests/cgroup_attach_multi.c | 12 ++++++------
> 4 files changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 9b64eed2b003..19741cfcaf11 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -754,10 +754,10 @@ int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type,
> .flags = flags,
> );
>
> - return bpf_prog_attach_xattr(prog_fd, target_fd, type, &opts);
> + return bpf_prog_attach_opts(prog_fd, target_fd, type, &opts);
> }
>
> -int bpf_prog_attach_xattr(int prog_fd, int target_fd,
> +int bpf_prog_attach_opts(int prog_fd, int target_fd,
> enum bpf_attach_type type,
> const struct bpf_prog_attach_opts *opts)
> {
> @@ -778,6 +778,13 @@ int bpf_prog_attach_xattr(int prog_fd, int target_fd,
> return libbpf_err_errno(ret);
> }
>
> +int bpf_prog_attach_xattr(int prog_fd, int target_fd,
> + enum bpf_attach_type type,
> + const struct bpf_prog_attach_opts *opts)
> +{
> + return bpf_prog_attach_opts(prog_fd, target_fd, type, opts);
> +}
let's use alias instead
> +
> int bpf_prog_detach(int target_fd, enum bpf_attach_type type)
> {
> union bpf_attr attr;
> diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
> index 00619f64a040..5dc9fefe73f3 100644
> --- a/tools/lib/bpf/bpf.h
> +++ b/tools/lib/bpf/bpf.h
> @@ -280,6 +280,10 @@ struct bpf_prog_attach_opts {
>
> LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,
> enum bpf_attach_type type, unsigned int flags);
> +LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int attachable_fd,
> + enum bpf_attach_type type,
> + const struct bpf_prog_attach_opts *opts);
> +LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_prog_attach_opts() instead")
> LIBBPF_API int bpf_prog_attach_xattr(int prog_fd, int attachable_fd,
> enum bpf_attach_type type,
> const struct bpf_prog_attach_opts *opts);
> diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> index 529783967793..be2bb69d1a12 100644
> --- a/tools/lib/bpf/libbpf.map
> +++ b/tools/lib/bpf/libbpf.map
> @@ -246,6 +246,7 @@ LIBBPF_0.0.8 {
> bpf_link__update_program;
> bpf_link_create;
> bpf_link_update;
> + bpf_prog_attach_opts;
keep the list sorted
> bpf_map__set_initial_value;
> bpf_program__attach_cgroup;
> bpf_program__attach_lsm;
> diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c b/tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c
> index d3e8f729c623..38b3c47293da 100644
> --- a/tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c
> +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c
> @@ -194,14 +194,14 @@ void serial_test_cgroup_attach_multi(void)
>
> attach_opts.flags = BPF_F_ALLOW_OVERRIDE | BPF_F_REPLACE;
> attach_opts.replace_prog_fd = allow_prog[0];
> - if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
> + if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
> BPF_CGROUP_INET_EGRESS, &attach_opts),
> "fail_prog_replace_override", "unexpected success\n"))
> goto err;
> CHECK_FAIL(errno != EINVAL);
>
> attach_opts.flags = BPF_F_REPLACE;
> - if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
> + if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
> BPF_CGROUP_INET_EGRESS, &attach_opts),
> "fail_prog_replace_no_multi", "unexpected success\n"))
> goto err;
> @@ -209,7 +209,7 @@ void serial_test_cgroup_attach_multi(void)
>
> attach_opts.flags = BPF_F_ALLOW_MULTI | BPF_F_REPLACE;
> attach_opts.replace_prog_fd = -1;
> - if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
> + if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
> BPF_CGROUP_INET_EGRESS, &attach_opts),
> "fail_prog_replace_bad_fd", "unexpected success\n"))
> goto err;
> @@ -217,7 +217,7 @@ void serial_test_cgroup_attach_multi(void)
>
> /* replacing a program that is not attached to cgroup should fail */
> attach_opts.replace_prog_fd = allow_prog[3];
> - if (CHECK(!bpf_prog_attach_xattr(allow_prog[6], cg1,
> + if (CHECK(!bpf_prog_attach_opts(allow_prog[6], cg1,
> BPF_CGROUP_INET_EGRESS, &attach_opts),
> "fail_prog_replace_no_ent", "unexpected success\n"))
> goto err;
> @@ -225,14 +225,14 @@ void serial_test_cgroup_attach_multi(void)
>
> /* replace 1st from the top program */
> attach_opts.replace_prog_fd = allow_prog[0];
> - if (CHECK(bpf_prog_attach_xattr(allow_prog[6], cg1,
> + if (CHECK(bpf_prog_attach_opts(allow_prog[6], cg1,
> BPF_CGROUP_INET_EGRESS, &attach_opts),
> "prog_replace", "errno=%d\n", errno))
> goto err;
>
> /* replace program with itself */
> attach_opts.replace_prog_fd = allow_prog[6];
> - if (CHECK(bpf_prog_attach_xattr(allow_prog[6], cg1,
> + if (CHECK(bpf_prog_attach_opts(allow_prog[6], cg1,
> BPF_CGROUP_INET_EGRESS, &attach_opts),
> "prog_replace", "errno=%d\n", errno))
> goto err;
please split out selftests changes into a separate patch, doing this
after libbpf change doesn't break the build nor generates compilation
warnings (because deprecation is deferred), so it's ok to have it in a
separate patch
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-05 23:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-30 0:01 [PATCH bpf-next] libbpf: rename bpf_prog_attach_xattr to bpf_prog_attach_opts Christy Lee
2022-01-05 23:44 ` Andrii Nakryiko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.