bpftool: Register struct_ops with a link.
PATCH v3 1/2 bpftool: Register struct_ops with a link.
You can include an optional path after specifying the object name for the 'struct_ops register' subcommand.
Since the commit 226bc6ae6405 ("Merge branch 'Transit between BPF TCP congestion controls.'") has been accepted, it is now possible to create a link for a struct_ops. This can be done by defining a struct_ops in SEC(".struct_ops.link") to make libbpf returns a real link. If we don't pin the links before leaving bpftool, they will disappear. To instruct bpftool to pin the links in a directory with the names of the maps, we need to provide the path of that directory.
--- tools/bpf/bpftool/common.c | 14 +++++++ tools/bpf/bpftool/main.h | 3 ++ tools/bpf/bpftool/prog.c | 13 ------- tools/bpf/bpftool/struct_ops.c | 70 ++++++++++++++++++++++++++++------ 4 files changed, 75 insertions(+), 25 deletions(-)
tools/bpf/bpftool/common.c +14 -0
@@ -1091,3 +1091,17 @@ const char *bpf_attach_type_input_str(enum bpf_attach_type t)default :return libbpf_bpf_attach_type_str (t); } } + +int pathname_concat (char *buf,int buf_sz,const char *path, +const char *name) +{ +int len; + + len =snprintf (buf, buf_sz,"%s/%s" , path, name); +if (len <0 ) +return -EINVAL ; +if (len >= buf_sz) +return -ENAMETOOLONG ; + +return 0 ; +}
tools/bpf/bpftool/main.h +3 -0
@@ -262,4 +262,7 @@ static inline bool hashmap__empty(struct hashmap *map) return map ? hashmap__size(map) == 0 : true; } +int pathname_concat (char *buf,int buf_sz,const char *path, +const char *name); +#endif
tools/bpf/bpftool/prog.c +0 -13
@@ -1472,19 +1472,6 @@ auto_attach_program(struct bpf_program *prog, const char *path)return err; } -static int pathname_concat (char *buf,size_t buf_sz,const char *path,const char *name) -{ -int len; - - len =snprintf (buf, buf_sz,"%s/%s" , path, name); -if (len <0 ) -return -EINVAL ; -if ((size_t )len >= buf_sz) -return -ENAMETOOLONG ; - -return 0 ; -} -static int auto_attach_programs (struct bpf_object *obj,const char *path) {
tools/bpf/bpftool/struct_ops.c +58 -12
107 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 2/2 bpftool: Update doc to explain struct_ops register subcommand.
The "struct_ops register" subcommand now allows for an optional *LINK_DIR* to be included. This specifies the directory path where bpftool will pin struct_ops links with the same name as their corresponding map names.
--- .../bpf/bpftool/Documentation/bpftool-struct_ops.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-struct_ops.rst +8 -4
@@ -26,7 +26,7 @@ STRUCT_OPS COMMANDS | **bpftool** **struct_ops { show | list }** [*STRUCT_OPS_MAP*] | **bpftool** **struct_ops dump** [*STRUCT_OPS_MAP*] -| **bpftool** **struct_ops register** *OBJ* +| **bpftool** **struct_ops register** *OBJ* [*LINK_DIR*] | **bpftool** **struct_ops unregister** *STRUCT_OPS_MAP* | **bpftool** **struct_ops help** |
@@ -51,10 +51,14 @@ DESCRIPTION for the given struct_ops. Otherwise, it dumps all struct_ops currently existing in the system. - **bpftool struct_ops register** *OBJ* + **bpftool struct_ops register** *OBJ* [*LINK_DIR*] Register bpf struct_ops from *OBJ*. All struct_ops under - the ELF section ".struct_ops" will be registered to - its kernel subsystem. + the ELF section ".struct_ops" and ".struct_ops.link" will + be registered to its kernel subsystem. For each + struct_ops in the ".struct_ops.link" section, a link + will be created. You can give *LINK_DIR* to provide a + directory path where these links will be pinned with the + same name as their corresponding map name. **bpftool struct_ops unregister** *STRUCT_OPS_MAP* Unregister the *STRUCT_OPS_MAP* from the kernel subsystem.
Signature · 1 line
2.34.1
Re: [PATCH bpf-next v3 2/2] bpftool: Update doc to explain struct_ops register subcommand.
Quoted 6 lines · Kui-Feng Lee
The "
struct_opsregister" subcommand now allows for an optional *LINK_DIR* to be included. This specifies the directory path where bpftool will pinstruct_opslinks with the same name as their corresponding map names.Signed-off-by Kui-Feng Lee <[email protected]>
Thank you!
Quoted 12 lines · Kui-Feng Lee
You can include an optional path after specifying the object name for the '
struct_opsregister' subcommand.Since the commit
226bc6ae6405("Merge branch 'Transit between BPF TCP congestion controls.'") has been accepted, it is now possible to create a link for astruct_ops. This can be done by defining astruct_opsinSEC(".struct_ops.link")to make libbpf returns a real link. If we don't pin the links before leaving bpftool, they will disappear. To instruct bpftool to pin the links in a directory with the names of the maps, we need to provide the path of that directory.
Quoted 1 line
Signed-off-by Kui-Feng Lee <[email protected]>
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Wed, 19 Apr 2023 17:28:21 -0700 you wrote:
You can include an optional path after specifying the object name for the '
struct_opsregister' subcommand.Since the commit
226bc6ae6405("Merge branch 'Transit between BPF TCP congestion controls.'") has been accepted, it is now possible to create a link for astruct_ops. This can be done by defining astruct_opsinSEC(".struct_ops.link")to make libbpf returns a real link. If we don't pin the links before leaving bpftool, they will disappear. To instruct bpftool to pin the links in a directory with the names of the maps, we need to provide the path of that directory.
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next,v3,1/2] bpftool: Register struct_ops with a link.
https://git.kernel.org/bpf/bpf-next/c/0232b7889786 - [bpf-next,v3,2/2] bpftool: Update doc to explain struct_ops register subcommand. https://git.kernel.org/bpf/bpf-next/c/45cea721ea36
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html