Skip to contentSkip to conversation

libbpf: rename bpf_prog_attach_xattr to bpf_prog_attach_opts

PATCH Superseded Christy Lee 1 participant 3 messages Jan 6, 2022

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover libbpf: rename bpf_prog_attach_xattr to bpf_prog_attach_opts

All xattr APIs are being dropped, mark bpf_prog_attach_opts() as deprecated and rename to bpf_prog_attach_xattr(). Replace all usages of the deprecated function with the new function name.

[0] Closes: https://github.com/libbpf/libbpf/issues/285

Changelog:
----------
v1 -> v2:
https://lore.kernel.org/all/[email protected]/

* Used alias instead of returning original function
* Split out selftests to a different commit

Christy Lee (2):
libbpf: rename bpf_prog_attach_xattr() to bpf_prog_attach_opts() selftests/bpf: change bpf_prog_attach_xattr() to
bpf_prog_attach_opts()

 tools/lib/bpf/bpf.c                                  |  9 +++++++--
 tools/lib/bpf/bpf.h                                  |  4 ++++
 tools/lib/bpf/libbpf.map                             |  1 +
 .../selftests/bpf/prog_tests/cgroup_attach_multi.c   | 12 ++++++------
 4 files changed, 18 insertions(+), 8 deletions(-)

--
2.30.2

#1 lore raw

PATCH v2 1/2 libbpf: rename bpf_prog_attach_xattr() to bpf_prog_attach_opts()

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.

---
 tools/lib/bpf/bpf.c      | 9 +++++++--
 tools/lib/bpf/bpf.h      | 4 ++++
 tools/lib/bpf/libbpf.map | 1 +
 3 files changed, 12 insertions(+), 2 deletions(-)
tools/lib/bpf/bpf.c +7 -2
index 9b64eed2b003..f0b3f6cc317b 100644
@@ -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,11 @@ int bpf_prog_attach_xattr(int prog_fd, int target_fd,
 	return libbpf_err_errno(ret);
 }
 
+__alias("bpf_prog_attach_opts")
+int bpf_prog_attach_xattr(int prog_fd, int target_fd,
+			  enum bpf_attach_type type,
+			  const struct bpf_prog_attach_opts *opts);
+
 int bpf_prog_detach(int target_fd, enum bpf_attach_type type)
 {
 	union bpf_attr attr;
tools/lib/bpf/bpf.h +4 -0
index 00619f64a040..5dc9fefe73f3 100644
@@ -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);
tools/lib/bpf/libbpf.map +1 -0
index 529783967793..8262cfca2240 100644
@@ -247,6 +247,7 @@ LIBBPF_0.0.8 {
 		bpf_link_create;
 		bpf_link_update;
 		bpf_map__set_initial_value;
+		bpf_prog_attach_opts;
 		bpf_program__attach_cgroup;
 		bpf_program__attach_lsm;
 		bpf_program__is_lsm;
Signature · 1 line
2.30.2
#2 lore raw

PATCH v2 2/2 selftests/bpf: change bpf_prog_attach_xattr() to bpf_prog_attach_opts()

In reply to Christy Lee

bpf_prog_attach_opts() is being deprecated and renamed to bpf_prog_attach_xattr(). Change all selftests/bpf's uage to the new name.

---
 .../selftests/bpf/prog_tests/cgroup_attach_multi.c   | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/prog_tests/cgroup_attach_multi.c +6 -6
index d3e8f729c623..38b3c47293da 100644
@@ -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;
Signature · 1 line
2.30.2