diff mbox series

[bpf-next,1/2,v2] libbpf: Deprecate bpf_{map,program}__{prev,next} APIs since v0.7

Message ID 20211003165844.4054931-2-hengqi.chen@gmail.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series libbpf: Deprecate bpf_{map,program}__{prev,next} APIs since v0.7 | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 4 maintainers not CCed: kafai@fb.com kpsingh@kernel.org songliubraving@fb.com netdev@vger.kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 10 this patch: 10
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 82 exceeds 80 columns WARNING: line length of 87 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary

Commit Message

Hengqi Chen Oct. 3, 2021, 4:58 p.m. UTC
Deprecate bpf_{map,program}__{prev,next} APIs. Replace them with
a new set of APIs named bpf_object__{prev,next}_{program,map} which
follow the libbpf API naming convention.[0] No functionality changes.

  Closes: https://github.com/libbpf/libbpf/issues/296

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 tools/lib/bpf/libbpf.c   | 24 ++++++++++++++++++++++++
 tools/lib/bpf/libbpf.h   | 35 +++++++++++++++++++++++------------
 tools/lib/bpf/libbpf.map |  4 ++++
 3 files changed, 51 insertions(+), 12 deletions(-)

--
2.25.1

Comments

Song Liu Oct. 5, 2021, 10:22 p.m. UTC | #1
On Sun, Oct 3, 2021 at 10:00 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>
> Deprecate bpf_{map,program}__{prev,next} APIs. Replace them with
> a new set of APIs named bpf_object__{prev,next}_{program,map} which
> follow the libbpf API naming convention.[0] No functionality changes.
>
>   Closes: https://github.com/libbpf/libbpf/issues/296
^^^ I guess we need "[0]" here?

>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---

Other than the nitpick above

Acked-by: Song Liu <songliubraving@fb.com>
Andrii Nakryiko Oct. 6, 2021, 6:07 p.m. UTC | #2
On Tue, Oct 5, 2021 at 3:22 PM Song Liu <song@kernel.org> wrote:
>
> On Sun, Oct 3, 2021 at 10:00 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
> >
> > Deprecate bpf_{map,program}__{prev,next} APIs. Replace them with
> > a new set of APIs named bpf_object__{prev,next}_{program,map} which
> > follow the libbpf API naming convention.[0] No functionality changes.
> >
> >   Closes: https://github.com/libbpf/libbpf/issues/296
> ^^^ I guess we need "[0]" here?
>
> >
> > Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> > ---
>
> Other than the nitpick above

Fixed that up while applying. There were also 4 more uses of
bpf_program__next and bpf_map__next in bpftool and samples/bpf, I've
fixed them up as well to not come back to this again. Hengqi, for
future deprecations, please do grep for the entire Linux source code,
not just selftests, there are a bunch of other tools and parts of the
kernel that use libbpf APIs.

Applied to bpf-next, thanks.

>
> Acked-by: Song Liu <songliubraving@fb.com>
Hengqi Chen Oct. 7, 2021, 4:01 a.m. UTC | #3
On 10/7/21 2:07 AM, Andrii Nakryiko wrote:
> On Tue, Oct 5, 2021 at 3:22 PM Song Liu <song@kernel.org> wrote:
>>
>> On Sun, Oct 3, 2021 at 10:00 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>>>
>>> Deprecate bpf_{map,program}__{prev,next} APIs. Replace them with
>>> a new set of APIs named bpf_object__{prev,next}_{program,map} which
>>> follow the libbpf API naming convention.[0] No functionality changes.
>>>
>>>   Closes: https://github.com/libbpf/libbpf/issues/296
>> ^^^ I guess we need "[0]" here?
>>
>>>
>>> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
>>> ---
>>
>> Other than the nitpick above
> 
> Fixed that up while applying. There were also 4 more uses of
> bpf_program__next and bpf_map__next in bpftool and samples/bpf, I've
> fixed them up as well to not come back to this again. Hengqi, for
> future deprecations, please do grep for the entire Linux source code,
> not just selftests, there are a bunch of other tools and parts of the
> kernel that use libbpf APIs.
> 

Thanks. Will keep this in mind. :)

> Applied to bpf-next, thanks.
> 
>>
>> Acked-by: Song Liu <songliubraving@fb.com>
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e23f1b6b9402..ecd5284c705d 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7798,6 +7798,12 @@  __bpf_program__iter(const struct bpf_program *p, const struct bpf_object *obj,

 struct bpf_program *
 bpf_program__next(struct bpf_program *prev, const struct bpf_object *obj)
+{
+	return bpf_object__next_program(obj, prev);
+}
+
+struct bpf_program *
+bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prev)
 {
 	struct bpf_program *prog = prev;

@@ -7810,6 +7816,12 @@  bpf_program__next(struct bpf_program *prev, const struct bpf_object *obj)

 struct bpf_program *
 bpf_program__prev(struct bpf_program *next, const struct bpf_object *obj)
+{
+	return bpf_object__prev_program(obj, next);
+}
+
+struct bpf_program *
+bpf_object__prev_program(const struct bpf_object *obj, struct bpf_program *next)
 {
 	struct bpf_program *prog = next;

@@ -8742,6 +8754,12 @@  __bpf_map__iter(const struct bpf_map *m, const struct bpf_object *obj, int i)

 struct bpf_map *
 bpf_map__next(const struct bpf_map *prev, const struct bpf_object *obj)
+{
+	return bpf_object__next_map(obj, prev);
+}
+
+struct bpf_map *
+bpf_object__next_map(const struct bpf_object *obj, const struct bpf_map *prev)
 {
 	if (prev == NULL)
 		return obj->maps;
@@ -8751,6 +8769,12 @@  bpf_map__next(const struct bpf_map *prev, const struct bpf_object *obj)

 struct bpf_map *
 bpf_map__prev(const struct bpf_map *next, const struct bpf_object *obj)
+{
+	return bpf_object__prev_map(obj, next);
+}
+
+struct bpf_map *
+bpf_object__prev_map(const struct bpf_object *obj, const struct bpf_map *next)
 {
 	if (next == NULL) {
 		if (!obj->nr_maps)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index e35490c54eb3..8f5144bfa321 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -189,16 +189,22 @@  LIBBPF_API int libbpf_find_vmlinux_btf_id(const char *name,

 /* Accessors of bpf_program */
 struct bpf_program;
-LIBBPF_API struct bpf_program *bpf_program__next(struct bpf_program *prog,
-						 const struct bpf_object *obj);
+LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_object__next_program() instead")
+struct bpf_program *bpf_program__next(struct bpf_program *prog,
+				      const struct bpf_object *obj);
+LIBBPF_API struct bpf_program *
+bpf_object__next_program(const struct bpf_object *obj, struct bpf_program *prog);

-#define bpf_object__for_each_program(pos, obj)		\
-	for ((pos) = bpf_program__next(NULL, (obj));	\
-	     (pos) != NULL;				\
-	     (pos) = bpf_program__next((pos), (obj)))
+#define bpf_object__for_each_program(pos, obj)			\
+	for ((pos) = bpf_object__next_program((obj), NULL);	\
+	     (pos) != NULL;					\
+	     (pos) = bpf_object__next_program((obj), (pos)))

-LIBBPF_API struct bpf_program *bpf_program__prev(struct bpf_program *prog,
-						 const struct bpf_object *obj);
+LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_object__prev_program() instead")
+struct bpf_program *bpf_program__prev(struct bpf_program *prog,
+				      const struct bpf_object *obj);
+LIBBPF_API struct bpf_program *
+bpf_object__prev_program(const struct bpf_object *obj, struct bpf_program *prog);

 typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, void *);

@@ -502,16 +508,21 @@  bpf_object__find_map_fd_by_name(const struct bpf_object *obj, const char *name);
 LIBBPF_API struct bpf_map *
 bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset);

+LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_object__next_map() instead")
+struct bpf_map *bpf_map__next(const struct bpf_map *map, const struct bpf_object *obj);
 LIBBPF_API struct bpf_map *
-bpf_map__next(const struct bpf_map *map, const struct bpf_object *obj);
+bpf_object__next_map(const struct bpf_object *obj, const struct bpf_map *map);
+
 #define bpf_object__for_each_map(pos, obj)		\
-	for ((pos) = bpf_map__next(NULL, (obj));	\
+	for ((pos) = bpf_object__next_map((obj), NULL);	\
 	     (pos) != NULL;				\
-	     (pos) = bpf_map__next((pos), (obj)))
+	     (pos) = bpf_object__next_map((obj), (pos)))
 #define bpf_map__for_each bpf_object__for_each_map

+LIBBPF_API LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_object__prev_map() instead")
+struct bpf_map *bpf_map__prev(const struct bpf_map *map, const struct bpf_object *obj);
 LIBBPF_API struct bpf_map *
-bpf_map__prev(const struct bpf_map *map, const struct bpf_object *obj);
+bpf_object__prev_map(const struct bpf_object *obj, const struct bpf_map *map);

 /**
  * @brief **bpf_map__fd()** gets the file descriptor of the passed
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 9e649cf9e771..b9f711ca475f 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -389,5 +389,9 @@  LIBBPF_0.5.0 {

 LIBBPF_0.6.0 {
 	global:
+		bpf_object__next_map;
+		bpf_object__next_program;
+		bpf_object__prev_map;
+		bpf_object__prev_program;
 		btf__add_tag;
 } LIBBPF_0.5.0;