[PATCH bpf-next] bpftool: Mount bpffs when pinmaps path not under the bpffs

Tao Chen posted 1 patch 1 year, 5 months ago
tools/bpf/bpftool/prog.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH bpf-next] bpftool: Mount bpffs when pinmaps path not under the bpffs
Posted by Tao Chen 1 year, 5 months ago
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")
Signed-off-by: Tao Chen <chen.dylane@gmail.com>
---
 tools/bpf/bpftool/prog.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 1a501cf09e78..40ea743d139f 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -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");
-- 
2.34.1
Re: [PATCH bpf-next] bpftool: Mount bpffs when pinmaps path not under the bpffs
Posted by Quentin Monnet 1 year, 5 months ago
On 02/07/2024 14:11, Tao Chen 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")
> Signed-off-by: Tao Chen <chen.dylane@gmail.com>

The patch looks good, thank you!

Tested-by: Quentin Monnet <qmo@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>