Skip to contentSkip to conversation

bpftool: Mount bpffs when pinmaps path not under the bpffs

PATCH Applied Tao Chen 3 participants 3 messages Jul 2, 2024

Subsystems (2)
lore
Share & tools
lore

Tao Chen

author
#0 lore raw

PATCH 1/1 bpftool: Mount bpffs when pinmaps path not under the bpffs

As qmonnet said [1], map pinning will fail if the pinmaps path not under the bpffs, like:
libbpf: specified path /home/ubuntu/test/sock_ops_map is not on BPF FS
Error: failed to pin all maps
[1]: https://github.com/libbpf/bpftool/issues/146

Fixes 3767a94b3253 ("bpftool: add pinmaps argument to the load/loadall")
---
 tools/bpf/bpftool/prog.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/bpf/bpftool/prog.c +4 -0
index 1a501cf09e78..40ea743d139f 100644
@@ -1813,6 +1813,10 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
 	}
 
 	if (pinmaps) {
+		err = create_and_mount_bpffs_dir(pinmaps);
+		if (err)
+			goto err_unpin;
+
 		err = bpf_object__pin_maps(obj, pinmaps);
 		if (err) {
 			p_err("failed to pin all maps");
Signature · 1 line
2.34.1
maintainer Tested-by Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Tao Chen

As qmonnet said [1], map pinning will fail if the pinmaps path not under the bpffs, like:
libbpf: specified path /home/ubuntu/test/sock_ops_map is not on BPF FS
Error: failed to pin all maps
[1]: https://github.com/libbpf/bpftool/issues/146

Fixes 3767a94b3253 ("bpftool: add pinmaps argument to the load/loadall")

The patch looks good, thank you!

#2 lore raw
In reply to Tao Chen
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 10 lines · On Tue, 2 Jul 2024 21:11:50 +0800 you wrote:

As qmonnet said [1], map pinning will fail if the pinmaps path not under the bpffs, like:
libbpf: specified path /home/ubuntu/test/sock_ops_map is not on BPF FS
Error: failed to pin all maps
[1]: https://github.com/libbpf/bpftool/issues/146

Fixes 3767a94b3253 ("bpftool: add pinmaps argument to the load/loadall")

[...]

Here is the summary with links:
- [bpf-next] bpftool: Mount bpffs when pinmaps path not under the bpffs

    https://git.kernel.org/bpf/bpf-next/c/da5f8fd1f0d3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html