All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hengqi Chen <hengqi.chen@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	yhs@fb.com, john.fastabend@gmail.com, hengqi.chen@gmail.com
Subject: [PATCH bpf-next 1/2] libbpf: Deprecate bpf_{map,program}__{prev,next} APIs
Date: Tue,  7 Sep 2021 00:54:55 +0800	[thread overview]
Message-ID: <20210906165456.325999-1-hengqi.chen@gmail.com> (raw)

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.

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   | 30 ++++++++++++++++++++----------
 tools/lib/bpf/libbpf.map |  4 ++++
 3 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 88d8825fc6f6..8d82853fb4a0 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -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)
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index f177d897c5f7..e6aab4cd263b 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -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);
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index bbc53bb25f68..0c6d510e7747 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -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

             reply	other threads:[~2021-09-06 16:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06 16:54 Hengqi Chen [this message]
2021-09-06 16:54 ` [PATCH bpf-next 2/2] selftests/bpf: Replace bpf_{map,program}__next with bpf_object__next_{map,program} Hengqi Chen
2021-09-09  4:47   ` Andrii Nakryiko
2021-09-09  4:44 ` [PATCH bpf-next 1/2] libbpf: Deprecate bpf_{map,program}__{prev,next} APIs Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210906165456.325999-1-hengqi.chen@gmail.com \
    --to=hengqi.chen@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.