-
Notifications
You must be signed in to change notification settings - Fork 4k
libbpf-tools: introduce path helpers and filelife support full-path #5340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There will be many programs that need to get the current working directory
or full-path of file, such as opensnoop, which is already supported.
and other tools like filelife/filetop need it too.
Therefore, it will be helpful to separate the bpf_getcwd function from
opensnoop.bpf.c as a public helper function.
Add functions:
1. bpf_dentry_full_path(): Get the full-path based on the dentry and
vfsmount.
2. bpf_getcwd(): Get the full-path of the current working directory.
3. print_full_path(): Assembling full-path in user space.
Add structures:
1. struct full_path {}: Record the absolute path.
Signed-off-by: Rong Tao <[email protected]>
To support full-path, the following operations are performed:
1. First, to support the transmission of larger data, perf-buffer is
replaced with ring-buff.
2. Then, before this patch, events are constructed in kprobe/unlink,
and events of successful unlink are submitted in kretprobe/unlink.
However, the reservation and submission of ring-buff cannot be
separated, so the struct unlink_event small structure is introduced
for transfer, and the reservation and submission of events are in
kretprobe/unlink.
3. In order to record the dentry and vfsmount structures of cwd when the
file is created, the structure struct create_arg{} is introduced.
Note: cannot obtain the dentry and vfsmount structures of cwd in
kretprobe/unlink.
Example:
# Test commands
$ cd /home/sda/git-repos/
$ touch a.out && sleep 0.2 && rm a.out
# before
$ sudo ./filelife
Tracing the lifespan of short-lived files ... Hit Ctrl-C to end.
TIME PID COMM AGE(s) FILE
17:27:05 458702 rm 0.21 a.out
# after
$ sudo ./filelife -F
Tracing the lifespan of short-lived files ... Hit Ctrl-C to end.
TIME PID COMM AGE(s) FILE
17:26:58 458692 rm 0.21 /home/sda/git-repos/a.out
^^^^^^^^^^^^^^^^^^^^ full-path
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to support full-path. [1] iovisor#5340 iovisor@74bddcbe646e Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jun 30, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 1, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 13, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 13, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 15, 2025
In bcc PR [1], add common path helpers for serial of tools, this patch do the same thing. After analysis and experiments, libbpf-tools/c and tools/py codes about path-helpers cannot be reused. Thus, this patch add: 1. full_path.h: defined FULL_PATH_FIELD(name); 2. path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers same as commit [1]; 3. path_helpers.py: add get_full_path() to parse full-path in full_path.h; [1] iovisor#5340 Signed-off-by: Rong Tao <[email protected]>
Rtoax
added a commit
to Rtoax/bcc
that referenced
this pull request
Jul 15, 2025
Same as libbpf-tools/filelife changes [1], introduce -F argument to
support full-path.
Example:
$ touch a.out && sleep 0.2 && rm a.out
# Before
$ sudo ./filelife.py
TIME PID COMM AGE(s) FILE
18:57:25 343907 rm 0.21 a.out
# After
$ sudo ./filelife.py -F
TIME PID COMM AGE(s) FILE
18:57:35 343917 rm 0.21 /home/sda/git-repos/iovisor/bcc/libbpf-tools/a.out
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[1] iovisor#5340
iovisor@74bddcbe646e
Signed-off-by: Rong Tao <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1st patch: libbpf-tools: Introduce path helpers
There will be many programs that need to get the current working directory
or full-path of file, such as opensnoop, which is already supported.
and other tools like filelife/filetop need it too.
Therefore, it will be helpful to separate the bpf_getcwd function from
opensnoop.bpf.c as a public helper function.
Add functions:
vfsmount.
Add structures:
2nd patch: libbpf-tools/filelife: support full-path
To support full-path, the following operations are performed:
replaced with ring-buff.
and events of successful unlink are submitted in kretprobe/unlink.
However, the reservation and submission of ring-buff cannot be
separated, so the struct unlink_event small structure is introduced
for transfer, and the reservation and submission of events are in
kretprobe/unlink.
file is created, the structure struct create_arg{} is introduced.
Note: cannot obtain the dentry and vfsmount structures of cwd in
kretprobe/unlink.
Example: