libbpf: Deprecate bpf_{map,program}__{prev,next} APIs
Subsystems (4)
PATCH 1/2 libbpf: Deprecate bpf_{map,program}__{prev,next} APIs
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. No functionality changes.
--- tools/lib/bpf/libbpf.c | 24 ++++++++++++++++++------ tools/lib/bpf/libbpf.h | 30 ++++++++++++++++++++---------- tools/lib/bpf/libbpf.map | 4 ++++ 3 files changed, 42 insertions(+), 16 deletions(-)
tools/lib/bpf/libbpf.c +18 -6
@@ -7347,7 +7347,7 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path)return 0 ; err_unpin_maps: -while ((map =bpf_map__prev (map, obj))) { +while ((map =bpf_object__prev_map (map, obj))) {if (!map->pin_path)continue ;
@@ -7427,7 +7427,7 @@ int bpf_object__pin_programs(struct bpf_object *obj, const char *path)return 0 ; err_unpin_programs: -while ((prog =bpf_program__prev (prog, obj))) { +while ((prog =bpf_object__prev_program (prog, obj))) {char buf[PATH_MAX ];int len;
@@ -7666,8 +7666,11 @@ __bpf_program__iter(const struct bpf_program *p, const struct bpf_object *obj,return &obj->programs[idx]; } +__attribute__((alias ("bpf_object__next_program" ))) +struct bpf_program *bpf_program__next (struct bpf_program *prev,const struct bpf_object *obj); +struct bpf_program * -bpf_program__next (struct bpf_program *prev,const struct bpf_object *obj) +bpf_object__next_program (struct bpf_program *prev,const struct bpf_object *obj) {struct bpf_program *prog = prev;
@@ -7678,8 +7681,11 @@ bpf_program__next(struct bpf_program *prev, const struct bpf_object *obj)return prog; } +__attribute__((alias ("bpf_object__prev_program" ))) +struct bpf_program *bpf_program__prev (struct bpf_program *next,const struct bpf_object *obj); +struct bpf_program * -bpf_program__prev (struct bpf_program *next,const struct bpf_object *obj) +bpf_object__prev_program (struct bpf_program *next,const struct bpf_object *obj) {struct bpf_program *prog = next;
@@ -8698,8 +8704,11 @@ __bpf_map__iter(const struct bpf_map *m, const struct bpf_object *obj, int i)return &obj->maps[idx]; } +__attribute__((alias ("bpf_object__next_map" ))) +struct bpf_map *bpf_map__next (const struct bpf_map *prev,const struct bpf_object *obj); +struct bpf_map * -bpf_map__next (const struct bpf_map *prev,const struct bpf_object *obj) +bpf_object__next_map (const struct bpf_map *prev,const struct bpf_object *obj) {if (prev ==NULL )return obj->maps;
@@ -8707,8 +8716,11 @@ bpf_map__next(const struct bpf_map *prev, const struct bpf_object *obj)return __bpf_map__iter (prev, obj,1 ); } +__attribute__((alias ("bpf_object__prev_map" ))) +struct bpf_map *bpf_map__prev (const struct bpf_map *next,const struct bpf_object *obj); +struct bpf_map * -bpf_map__prev (const struct bpf_map *next,const struct bpf_object *obj) +bpf_object__prev_map (const struct bpf_map *next,const struct bpf_object *obj) {if (next ==NULL ) {if (!obj->nr_maps)
tools/lib/bpf/libbpf.h +20 -10
@@ -186,16 +186,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, +LIBBPF_API LIBBPF_DEPRECATED("bpf_program__next() is deprecated, 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(struct bpf_program *prog, +const struct bpf_object *obj); -#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(NULL, (obj)); \ + (pos) != NULL; \ + (pos) = bpf_object__next_program((pos), (obj))) -LIBBPF_API struct bpf_program *bpf_program__prev(struct bpf_program *prog, +LIBBPF_API LIBBPF_DEPRECATED("bpf_program__prev() is deprecated, 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(struct bpf_program *prog, +const struct bpf_object *obj);typedef void (*bpf_program_clear_priv_t )(struct bpf_program *,void *);
@@ -495,16 +501,20 @@ 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("bpf_map__next() is deprecated, 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_map *map,const struct bpf_object *obj);#define bpf_object__for_each_map (pos, obj) \ - for ((pos) = bpf_map__next(NULL, (obj)); \ + for ((pos) = bpf_object__next_map(NULL, (obj)); \ (pos) != NULL; \ - (pos) = bpf_map__next((pos), (obj))) + (pos) = bpf_object__next_map((pos), (obj)))#define bpf_map__for_each bpf_object__for_each_map +LIBBPF_API LIBBPF_DEPRECATED("bpf_map__prev() is deprecated, 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_map *map,const struct bpf_object *obj);/* get/set map FD */ LIBBPF_API int bpf_map__fd(const struct bpf_map *map);
tools/lib/bpf/libbpf.map +4 -0
@@ -378,6 +378,10 @@ LIBBPF_0.5.0 { bpf_program__attach_tracepoint_opts; bpf_program__attach_uprobe_opts; bpf_object__gen_loader; + bpf_object__next_map; + bpf_object__next_program; + bpf_object__prev_map; + bpf_object__prev_program; btf__load_from_kernel_by_id; btf__load_from_kernel_by_id_split; btf__load_into_kernel;
--
2.30.2
PATCH 2/2 selftests/bpf: Replace bpf_{map,program}__next with bpf_object__next_{map,program}
Replace deprecated bpf_{map,program}__next APIs with newly added bpf_object__next_{map,program} APIs, so that no compilation warnings emit.
--- tools/testing/selftests/bpf/prog_tests/btf.c | 2 +- tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c | 2 +- tools/testing/selftests/bpf/prog_tests/select_reuseport.c | 2 +- tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/prog_tests/btf.c +1 -1
@@ -4268,7 +4268,7 @@ static void do_test_file(unsigned int test_num)if (CHECK (err,"obj: %d" , err))return ; - prog =bpf_program__next (NULL , obj); + prog =bpf_object__next_program (NULL , obj);if (CHECK (!prog,"Cannot find bpf_prog" )) { err =-1 ; goto done;
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +1 -1
@@ -288,7 +288,7 @@ static void test_fmod_ret_freplace(void)if (CHECK (err,"freplace_obj_load" ,"err %d\n" , err)) goto out; - prog =bpf_program__next (NULL , freplace_obj); + prog =bpf_object__next_program (NULL , freplace_obj); freplace_link =bpf_program__attach_trace (prog);if (!ASSERT_OK_PTR (freplace_link,"freplace_attach_trace" )) goto out;
tools/testing/selftests/bpf/prog_tests/select_reuseport.c +1 -1
@@ -114,7 +114,7 @@ static int prepare_bpf_obj(void) err =bpf_object__load (obj);RET_ERR (err,"load bpf_object" ,"err:%d\n" , err); - prog =bpf_program__next (NULL , obj); + prog =bpf_object__next_program (NULL , obj);RET_ERR (!prog,"get first bpf_program" ,"!prog\n" ); select_by_skb_data_prog =bpf_program__fd (prog); RET_ERR(select_by_skb_data_prog < 0, "get prog fd",
tools/testing/selftests/bpf/prog_tests/tcp_rtt.c +1 -1
@@ -109,7 +109,7 @@ static int run_test(int cgroup_fd, int server_fd)return -1 ; } - map =bpf_map__next (NULL , obj); + map =bpf_object__next_map (NULL , obj); map_fd =bpf_map__fd (map); err =bpf_prog_attach (prog_fd, cgroup_fd,BPF_CGROUP_SOCK_OPS ,0 );
--
2.30.2
Re: [PATCH bpf-next 2/2] selftests/bpf: Replace bpf_{map,program}__next with bpf_object__next_{map,program}
Quoted 7 lines · Hengqi Chen
Replace deprecated bpf_{map,program}__next APIs with newly added bpf_object__next_{map,program} APIs, so that no compilation warnings emit.
Signed-off-by Hengqi Chen <[email protected]>---
LGTM, but the subject for this patch (and a few others you've submitted) is very long. I think the recommendation is to keep them shorter than 78 characters or something like that. Maybe use something like "selftests/bpf: switch to new new bpf_object__next_program APIs"?
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/btf.c | 2 +- tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c | 2 +- tools/testing/selftests/bpf/prog_tests/select_reuseport.c | 2 +- tools/testing/selftests/bpf/prog_tests/tcp_rtt.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
[...]
Quoted 6 lines · Hengqi Chen
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. No functionality changes.
I'm hesitant about using Closes: as if it was a proper Linux tag. Let's stick to using it in a reference:
[0] Closes: ...
Quoted 30 lines
Signed-off-by Hengqi Chen <[email protected]>--- tools/lib/bpf/libbpf.c | 24 ++++++++++++++++++------ tools/lib/bpf/libbpf.h | 30 ++++++++++++++++++++---------- tools/lib/bpf/libbpf.map | 4 ++++ 3 files changed, 42 insertions(+), 16 deletions(-)tools/lib/bpf/libbpf.c +2
-2@@ -7347,7 +7347,7 @@ int bpf_object__pin_maps(struct bpf_object *obj, const char *path)return 0 ; err_unpin_maps: -while ((map =bpf_map__prev (map, obj))) { +while ((map =bpf_object__prev_map (map, obj))) {if (!map->pin_path)continue ;@@ -7427,7 +7427,7 @@ int bpf_object__pin_programs(struct bpf_object *obj, const char *path)return 0 ; err_unpin_programs: -while ((prog =bpf_program__prev (prog, obj))) { +while ((prog =bpf_object__prev_program (prog, obj))) {char buf[PATH_MAX ];int len;
tools/lib/bpf/libbpf.c __bpf_program__iter(const struct bpf_program *p, const struct bpf_object *obj, · line 7673
Quoted 9 lines
tools/lib/bpf/libbpf.c +4
-1@@ -7666,8 +7666,11 @@ __bpf_program__iter(const struct bpf_program *p, const struct bpf_object *obj,return &obj->programs[idx]; } +__attribute__((alias ("bpf_object__next_program" ))) +struct bpf_program *bpf_program__next (struct bpf_program *prev,const struct bpf_object *obj); +struct bpf_program * -bpf_program__next (struct bpf_program *prev,const struct bpf_object *obj) +bpf_object__next_program (struct bpf_program *prev,const struct bpf_object *obj)
I think for bpf_object__next_program it makes more sense to have obj as the first argument (it's a "method" of bpf_object, after all). So you can't have bpf_program__next aliased to bpf_object__next_program, you have to add a small wrapper function. Same for other new APIs.
Quoted 7 lines
tools/lib/bpf/libbpf.c +0
-0{struct bpf_program *prog = prev;@@ -7678,8 +7681,11 @@ bpf_program__next(struct bpf_program *prev, const struct bpf_object *obj)return prog; }
[...]
tools/lib/bpf/libbpf.h LIBBPF_API int libbpf_find_vmlinux_btf_id(const char *name, · line 189
Quoted 10 lines
tools/lib/bpf/libbpf.h +1
-1@@ -186,16 +186,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, +LIBBPF_API LIBBPF_DEPRECATED("bpf_program__next() is deprecated, use bpf_object__next_program() instead")
We shouldn't deprecate API until the replacement API was already released as part of an official libbpf release. I suggest to wait until the LIBBPF_DEPRECATE_SINCE ([0]) patch lands first, and then using that here to deprecate those APIs starting from 0.7 (because we are now developing 0.6 libbpf).
[0] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 5 lines
tools/lib/bpf/libbpf.h +3
-0+struct bpf_program *bpf_program__next (struct bpf_program *prog,const struct bpf_object *obj); +LIBBPF_API struct bpf_program *bpf_object__next_program(struct bpf_program *prog, +const struct bpf_object *obj);
[...]
Quoted 7 lines
/* get/set map FD */
LIBBPF_APIintbpf_map__fd(const struct bpf_map *map);tools/lib/bpf/libbpf.map +0
-0
tools/lib/bpf/libbpf.map LIBBPF_0.5.0 { · line 384
Quoted 7 lines
tools/lib/bpf/libbpf.map +4
-0@@ -378,6 +378,10 @@ LIBBPF_0.5.0 { bpf_program__attach_tracepoint_opts; bpf_program__attach_uprobe_opts; bpf_object__gen_loader; + bpf_object__next_map; + bpf_object__next_program; + bpf_object__prev_map; + bpf_object__prev_program;
For next revision, please add the LIBBPF_0.6.0 section, libbpf 0.5 was just released today, so we are now moving into the v0.6 development cycle. Thanks!
Quoted 5 lines
tools/lib/bpf/libbpf.map +0
-1btf__load_from_kernel_by_id; btf__load_from_kernel_by_id_split; btf__load_into_kernel; --2.30.2