mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next 1/2] bpftool: skel: Introduce NAME__open_and_load_opts()
       [not found] <cover.1749109589.git.rongtao@cestc.cn>
@ 2025-06-05  7:51 ` Rong Tao
  2025-06-05 16:45   ` Andrii Nakryiko
  2025-06-05  7:51 ` [PATCH bpf-next 2/2] " Rong Tao
  1 sibling, 1 reply; 3+ messages in thread
From: Rong Tao @ 2025-06-05  7:51 UTC (permalink / raw)
  To: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, open list:BPF [TOOLING] (bpftool),
	open list
  Cc: rongtao, rtoax

From: Rong Tao <rongtao@cestc.cn>

Introduce functions that support opts input parameters, Obviously, it is
more convenient to use. for example, skel with name=tc will include the
following functions:

    static inline struct tc_bpf *
    tc_bpf__open_and_load_opts(const struct bpf_object_open_opts *opts)

Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
 tools/bpf/bpftool/gen.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 67a60114368f..1487e61c6970 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -1371,6 +1371,7 @@ static int do_skeleton(int argc, char **argv)
 		#ifdef __cplusplus					    \n\
 			static inline struct %1$s *open(const struct bpf_object_open_opts *opts = nullptr);\n\
 			static inline struct %1$s *open_and_load();	    \n\
+			static inline struct %1$s *open_and_load_opts(const struct bpf_object_open_opts *opts = nullptr);    \n\
 			static inline int load(struct %1$s *skel);	    \n\
 			static inline int attach(struct %1$s *skel);	    \n\
 			static inline void detach(struct %1$s *skel);	    \n\
@@ -1438,12 +1439,12 @@ static int do_skeleton(int argc, char **argv)
 		}							    \n\
 									    \n\
 		static inline struct %1$s *				    \n\
-		%1$s__open_and_load(void)				    \n\
+		%1$s__open_and_load_opts(const struct bpf_object_open_opts *opts)\n\
 		{							    \n\
 			struct %1$s *obj;				    \n\
 			int err;					    \n\
 									    \n\
-			obj = %1$s__open();				    \n\
+			obj = %1$s__open_opts(opts);			    \n\
 			if (!obj)					    \n\
 				return NULL;				    \n\
 			err = %1$s__load(obj);				    \n\
@@ -1455,6 +1456,12 @@ static int do_skeleton(int argc, char **argv)
 			return obj;					    \n\
 		}							    \n\
 									    \n\
+		static inline struct %1$s *				    \n\
+		%1$s__open_and_load(void)				    \n\
+		{							    \n\
+			return %1$s__open_and_load_opts(NULL);		    \n\
+		}							    \n\
+									    \n\
 		static inline int					    \n\
 		%1$s__attach(struct %1$s *obj)				    \n\
 		{							    \n\
@@ -1530,7 +1537,11 @@ static int do_skeleton(int argc, char **argv)
 									    \n\
 		#ifdef __cplusplus					    \n\
 		struct %1$s *%1$s::open(const struct bpf_object_open_opts *opts) { return %1$s__open_opts(opts); }\n\
-		struct %1$s *%1$s::open_and_load() { return %1$s__open_and_load(); }	\n\
+		struct %1$s *%1$s::open_and_load() { return %1$s__open_and_load(); }\n\
+		struct %1$s *%1$s::open_and_load_opts(const struct bpf_object_open_opts *opts)\n\
+		{							    \n\
+			return %1$s__open_and_load_opts(opts);		    \n\
+		}							    \n\
 		int %1$s::load(struct %1$s *skel) { return %1$s__load(skel); }		\n\
 		int %1$s::attach(struct %1$s *skel) { return %1$s__attach(skel); }	\n\
 		void %1$s::detach(struct %1$s *skel) { %1$s__detach(skel); }		\n\
-- 
2.49.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH bpf-next 2/2] bpftool: skel: Introduce NAME__open_and_load_opts()
       [not found] <cover.1749109589.git.rongtao@cestc.cn>
  2025-06-05  7:51 ` [PATCH bpf-next 1/2] bpftool: skel: Introduce NAME__open_and_load_opts() Rong Tao
@ 2025-06-05  7:51 ` Rong Tao
  1 sibling, 0 replies; 3+ messages in thread
From: Rong Tao @ 2025-06-05  7:51 UTC (permalink / raw)
  To: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, Andrew Kreimer, Rong Tao, Lin Yikai,
	open list:BPF [TOOLING] (bpftool),
	open list
  Cc: rtoax

From: Rong Tao <rongtao@cestc.cn>

Update Documentation for skel NAME__open_and_load_opts()

Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
 tools/bpf/bpftool/Documentation/bpftool-gen.rst | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/bpf/bpftool/Documentation/bpftool-gen.rst b/tools/bpf/bpftool/Documentation/bpftool-gen.rst
index ca860fd97d8d..4dc2a624090e 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-gen.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-gen.rst
@@ -107,8 +107,10 @@ bpftool gen skeleton *FILE*
       global data maps. It corresponds to libbpf's **bpf_object__load**\ ()
       API.
 
-    - **example__open_and_load** combines **example__open** and
-      **example__load** invocations in one commonly used operation.
+    - **example__open_and_load** and **example__open_and_load_opts**.
+      Combines **example__open** and **example__load** invocations in one
+      commonly used operation. **_opts** variants accepts extra
+      **bpf_object_open_opts** options.
 
     - **example__attach** and **example__detach**.
       This pair of functions allow to attach and detach, correspondingly,
@@ -336,6 +338,9 @@ files into the final BPF ELF object file *example.bpf.o*.
                 const struct bpf_object_open_opts *opts);
   static inline struct example *example__open();
   static inline int example__load(struct example *obj);
+  static inline struct example *example__open();
+  static inline struct example *example__open_and_load_opts(
+                const struct bpf_object_open_opts *opts);
   static inline struct example *example__open_and_load();
   static inline int example__attach(struct example *obj);
   static inline void example__detach(struct example *obj);
-- 
2.49.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next 1/2] bpftool: skel: Introduce NAME__open_and_load_opts()
  2025-06-05  7:51 ` [PATCH bpf-next 1/2] bpftool: skel: Introduce NAME__open_and_load_opts() Rong Tao
@ 2025-06-05 16:45   ` Andrii Nakryiko
  0 siblings, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2025-06-05 16:45 UTC (permalink / raw)
  To: Rong Tao
  Cc: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa, open list:BPF [TOOLING] (bpftool),
	open list, rongtao

On Thu, Jun 5, 2025 at 12:57 AM Rong Tao <rtoax@foxmail.com> wrote:
>
> From: Rong Tao <rongtao@cestc.cn>
>
> Introduce functions that support opts input parameters, Obviously, it is
> more convenient to use. for example, skel with name=tc will include the

No, I don't see the need to add one extra variant just to add a bit
more convenience. If you need opts at open, then just do open_opts,
followed by load.

If we take this convenience to its logical conclusion, we'd need to
add open_and_load_and_attach() and open_and_load_and_attach_opts().
And yes, that would save a few lines of code here and there, but I
don't think we should do it.

pw-bot: cr

> following functions:
>
>     static inline struct tc_bpf *
>     tc_bpf__open_and_load_opts(const struct bpf_object_open_opts *opts)
>
> Signed-off-by: Rong Tao <rongtao@cestc.cn>
> ---
>  tools/bpf/bpftool/gen.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>

[...]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-06-05 16:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1749109589.git.rongtao@cestc.cn>
2025-06-05  7:51 ` [PATCH bpf-next 1/2] bpftool: skel: Introduce NAME__open_and_load_opts() Rong Tao
2025-06-05 16:45   ` Andrii Nakryiko
2025-06-05  7:51 ` [PATCH bpf-next 2/2] " Rong Tao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®