bpftool: Support bpffs mountpoint as pin path for prog loadall
PATCH v2 1/1 bpftool: Support bpffs mountpoint as pin path for prog loadall
Currently, when using prog loadall, if the pin path is a bpffs mountpoint, bpffs will be repeatedly mounted to the parent directory of the bpffs mountpoint path.
For example,
$ bpftool prog loadall test.o /sys/fs/bpf currently bpffs will be repeatedly mounted to /sys/fs.
---
v2: compatible with commit 0232b7889786 ("bpftool: Register struct_ops with a link.")
tools/bpf/bpftool/common.c | 9 ++++++--- tools/bpf/bpftool/iter.c | 2 +- tools/bpf/bpftool/main.h | 2 +- tools/bpf/bpftool/prog.c | 2 +- tools/bpf/bpftool/struct_ops.c | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-)
tools/bpf/bpftool/common.c +6 -3
@@ -68,7 +68,7 @@ void p_info(const char *fmt, ...)va_end (ap); } -static bool is_bpffs (char *path) +static bool is_bpffs (const char *path) {struct statfs st_fs;
@@ -244,13 +244,16 @@ int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type)return fd; } -int mount_bpffs_for_pin (const char *name) +int mount_bpffs_for_pin (const char *name,bool is_dir) {char err_str[ERR_MAX_LEN ];char *file;char *dir;int err =0 ; +if (is_dir &&is_bpffs (name)) +return err; + file =malloc (strlen (name) +1 );if (!file) {p_err ("mem alloc failed" );
@@ -286,7 +289,7 @@ int do_pin_fd(int fd, const char *name) {int err; - err =mount_bpffs_for_pin (name); + err =mount_bpffs_for_pin (name, false);if (err)return err;
tools/bpf/bpftool/iter.c +1 -1
@@ -76,7 +76,7 @@ static int do_pin(int argc, char **argv) goto close_obj; } - err =mount_bpffs_for_pin (path); + err =mount_bpffs_for_pin (path, false);if (err) goto close_link;
tools/bpf/bpftool/main.h +1 -1
@@ -142,7 +142,7 @@ const char *get_fd_type_name(enum bpf_obj_type type);char *get_fdinfo (int fd,const char *key);int open_obj_pinned (const char *path,bool quiet);int open_obj_pinned_any (const char *path,enum bpf_obj_type exp_type); -int mount_bpffs_for_pin (const char *name); +int mount_bpffs_for_pin (const char *name,bool is_dir);int do_pin_any (int argc,char **argv,int (*get_fd_by_id)(int *,char ***));int do_pin_fd (int fd,const char *name);
tools/bpf/bpftool/prog.c +1 -1
@@ -1739,7 +1739,7 @@ static int load_with_options(int argc, char **argv, bool first_prog_only) goto err_close_obj; } - err =mount_bpffs_for_pin (pinfile); + err =mount_bpffs_for_pin (pinfile, !first_prog_only);if (err) goto err_close_obj;
tools/bpf/bpftool/struct_ops.c +1 -1
@@ -509,7 +509,7 @@ static int do_register(int argc, char **argv)if (argc ==1 ) linkdir =GET_ARG (); -if (linkdir &&mount_bpffs_for_pin (linkdir)) { +if (linkdir &&mount_bpffs_for_pin (linkdir, true)) {p_err ("can't mount bpffs for pinning" );return -1 ; }
Signature · 1 line
2.38.1
2023-05-06 11:07 UTC+0800 ~ Pengcheng Yang <[email protected]>
Quoted 9 lines
Currently, when using prog loadall, if the pin path is a bpffs mountpoint, bpffs will be repeatedly mounted to the parent directory of the bpffs mountpoint path.
For example,
$ bpftool prog loadall test.o /sys/fs/bpf currently bpffs will be repeatedly mounted to /sys/fs.Signed-off-by Pengcheng Yang <[email protected]>
Thanks!
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 9 lines · On Sat, 6 May 2023 11:07:19 +0800 you wrote:
Currently, when using prog loadall, if the pin path is a bpffs mountpoint, bpffs will be repeatedly mounted to the parent directory of the bpffs mountpoint path.
For example,
$ bpftool prog loadall test.o /sys/fs/bpf currently bpffs will be repeatedly mounted to /sys/fs.[...]
Here is the summary with links:
- [v2,bpf-next] bpftool: Support bpffs mountpoint as pin path for prog loadall
https://git.kernel.org/bpf/bpf-next/c/2a36c26fe3b8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html