Skip to content

Conversation

@Rtoax
Copy link
Contributor

@Rtoax Rtoax commented Jun 30, 2025

Do the same thing #5340 to tools.

add

  • tools/path_helpers.bpf.c: add bpf helpers to get full-path from dentry;
  • tools/path_helpers.py: to parse full-path in userspace with python;
  • tools/full_path.h: define C full-path struct/macro;

filelife,filegone

  • use ring-buffer instead of perf-buffer;
  • support full-path with -F argument;

@Rtoax Rtoax force-pushed the patch-101-tools-path-helpers branch 3 times, most recently from a0a14fb to 3803a20 Compare July 1, 2025 02:03
@Rtoax Rtoax changed the title tools: introduce path helpers and filelife support full-path tools: introduce path helpers and filelife,filegone support full-path Jul 1, 2025
@Rtoax Rtoax force-pushed the patch-101-tools-path-helpers branch 2 times, most recently from 97a3232 to 8af1b95 Compare July 1, 2025 07:08
@Rtoax Rtoax force-pushed the patch-101-tools-path-helpers branch 2 times, most recently from b2bca4c to 32642f1 Compare July 15, 2025 07:23
@Rtoax
Copy link
Contributor Author

Rtoax commented Jul 15, 2025

Rebase to master.

Copy link
Collaborator

@ekyooo ekyooo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few questions about the overall structure first.

  1. Is the use of bpf_map_ringbuf mandatory for path_helper?

  2. If not mandatory, can we split the application commits for each tool (e.g., filegone, filelife) into two separate changes?
    (1) One commit for replacing the perf buffer map with the ring buffer map
    (2) Another commit for actually applying path_helper
    I believe separating the structural (infrastructure) change (ring buffer migration) from the functional change (full-path helper adoption) would make the history easier to manage and help with future maintenance. Also, having a dedicated commit for path_helper integration will serve as a clear reference for other developers who may want to apply it to additional tools later.

  3. Would it be possible to separate the application of path_helper to opensnoop into its own commit? The first commit is quite large, so splitting out the path_helper integration—similar to what was done for the other tools—would make the code easier to review and understand.

  4. Is there a specific reason for using -F (full-path) instead of -P/--path? Personally, when I see the -F option, it’s not immediately clear that it refers to “path output,” and the meaning of “F” isn’t very intuitive. I’m curious about the reasoning behind this choice.

Thank you.

@Rtoax Rtoax force-pushed the patch-101-tools-path-helpers branch from 32642f1 to 1695645 Compare July 29, 2025 13:25
@Rtoax Rtoax requested a review from ekyooo July 29, 2025 13:25
@Rtoax
Copy link
Contributor Author

Rtoax commented Jul 29, 2025

@ekyooo There are 6 commits ( minimize code modifications per commit )

  1. Introduce path_helpers (without modifying opensnoop.py)
  2. Modify opensnoop.py
  3. filelife perf-buffer replaced with ring-buffer (required, ringbuffer_reserve required)
  4. filelife implementation file path (-P)
  5. Replace perf-buffer of fileone with ring-buffer (required, ringbuffer_reserve required)
  6. filebone implementation file path (-P)

Please review the code again, thank you

@Rtoax Rtoax changed the title tools: introduce path helpers and filelife,filegone support full-path tools: introduce path helpers and filelife,filegone support fle path Jul 29, 2025
@Rtoax Rtoax changed the title tools: introduce path helpers and filelife,filegone support fle path tools: introduce path helpers and filelife,filegone support file path Jul 29, 2025
@Rtoax Rtoax force-pushed the patch-101-tools-path-helpers branch from 1695645 to a6160df Compare August 6, 2025 06:52
Rtoax added 6 commits October 1, 2025 14:18
Add the path_helpers code and header file. These functions are separate from
opensnoop.py, and because the code changes are large, this commit does not
modify the opensnoop.py code.

Add source code:

- full_path.h: defined FULL_PATH_FIELD(name);
- path_helpers.bpf.c: add bpf_dentry_full_path() and bpf_getcwd() helpers;
- path_helpers.py: add get_full_path() to parse full-path in full_path.h;

Signed-off-by: Rong Tao <[email protected]>
 Apply path_helpers to opensnoop.

Signed-off-by: Rong Tao <[email protected]>
In order for filelife to support file paths, it is necessary to replace
perf-buffer with ring-buffer, because the single event size of path
information transmission is large, and it is impossible to statically
allocate events in the stack, so it is necessary to use ring-buffer
reservation mechanism.

At the same time, 'create_arg' and 'unlink_event' structures are separated
from 'data_t' for file creation and deletion events and data record transfer.

Signed-off-by: Rong Tao <[email protected]>
Support for file paths using path_helpers.

For example:

    $ sudo ./filelife.py -P
    TIME     PID     COMM             AGE(s)  FILE
    20:51:32 55738   rm               0.21    /home/sdb/Git/bcc/build/a.out
    20:51:44 47715   Chrome_ChildIOT  0.00    /home/sdb/.org.chromium.Chromium.3hn6CS
    20:51:44 3490    ThreadPoolForeg  10.00   /home/rongtao/.cache/google-chrome/Default/Cache/Cache_Data/todelete_8829186fc5f5441a_0_1
    20:51:49 3490    ThreadPoolForeg  10.00   /home/rongtao/.cache/google-chrome/Default/Cache/Cache_Data/todelete_25ef4b49ebd6a803_0_1
    20:51:49 55767   rm               6.42    /home/sdb/Git/bcc/build/a.out

Signed-off-by: Rong Tao <[email protected]>
In order for filegone to support file paths, it is necessary to replace
perf-buffer with ring-buffer, because the single event size of path
information transmission is large, and it is impossible to statically
allocate events in the stack, so it is necessary to use ring-buffer
reservation mechanism.

Add 'struct entry_t' to pass the information from kprobe to kretprobe.

Signed-off-by: Rong Tao <[email protected]>
Support for file paths using path_helpers.

For example:

    $ realpath .
    /home/sdb/Git/bcc/build
    $ touch a.out && sleep 0.2 && mv a.out b.out && sleep 0.2 && rm b.out

    $ sudo ./filegone.py -P
    TIME     PID     COMM   ACTION FILE
    21:22:37 58683   mv     RENAME /home/sdb/Git/bcc/build/a.out > /home/sdb/Git/bcc/build/b.out
    21:22:37 58685   rm     DELETE /home/sdb/Git/bcc/build/b.out

Signed-off-by: Rong Tao <[email protected]>
@Rtoax Rtoax force-pushed the patch-101-tools-path-helpers branch from a6160df to 82f17b0 Compare October 1, 2025 06:19
@Rtoax
Copy link
Contributor Author

Rtoax commented Oct 1, 2025

rebase to master

@ekyooo
Copy link
Collaborator

ekyooo commented Oct 3, 2025

Is the use of bpf_map_ringbuf mandatory for path_helper?

Could you answer my question with clear reasoning?

To clarify the buffer type in #5340:

  1. You used compat.h in filelife, which provides compatibility between perf buffer and ring buffer.
  2. You stated in the commit message that you replaced perf buffer with ring buffer.
  3. What is true?

The use of the ring buffer is a modern change, but it excludes users of kernel versions below 5.8.
Should we reduce the tool's overall usability for an optional feature?
Before deciding, I need to verify the justification for this change.

@Rtoax
Copy link
Contributor Author

Rtoax commented Oct 5, 2025

Is the use of bpf_map_ringbuf mandatory for path_helper?

Could you answer my question with clear reasoning?

To clarify the buffer type in #5340:

1. You used compat.h in filelife, which provides compatibility between perf buffer and ring buffer.

2. You stated in the commit message that you replaced perf buffer with ring buffer.

3. What is true?

Thanks for your reply, the #5340 is for libbpf-tools/, this PR for tools/, those are different. This PR only replace perfbuffer with ring buffer.

The use of the ring buffer is a modern change, but it excludes users of kernel versions below 5.8. Should we reduce the tool's overall usability for an optional feature? Before deciding, I need to verify the justification for this change.

Indeed, thanks, you're right, maybe we should introduce compat.h like method for tools/ ?

@ekyooo
Copy link
Collaborator

ekyooo commented Oct 8, 2025

I have a question: was perf_buffer also verified to work correctly in PR #5340?

If so, I think it would be beneficial to apply compat.h to the Python tools as well. Even without using path_helper, this change would likely benefit multiple tools. Thanks!

@Rtoax
Copy link
Contributor Author

Rtoax commented Oct 9, 2025

Thank you for your reply, I will confirm this ;)

@Rtoax
Copy link
Contributor Author

Rtoax commented Oct 19, 2025

I have a question: was perf_buffer also verified to work correctly in PR #5340?

Sorry about the late reply, i tried this change, it's not works.

diff --git a/libbpf-tools/compat.c b/libbpf-tools/compat.c
index 7d932ef30591..31065e178984 100644
--- a/libbpf-tools/compat.c
+++ b/libbpf-tools/compat.c
@@ -35,7 +35,7 @@ struct bpf_buffer *bpf_buffer__new(struct bpf_map *events, struct bpf_map *heap)
        bool use_ringbuf;
        int type;
 
-       use_ringbuf = probe_ringbuf();
+       use_ringbuf = 0;
        if (use_ringbuf) {
                bpf_map__set_autocreate(heap, false);
                type = BPF_MAP_TYPE_RINGBUF;
$ sudo ./filelife 
libbpf: map 'events': failed to create: -EINVAL
libbpf: failed to load BPF skeleton 'filelife_bpf': -EINVAL
failed to load BPF object: -22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants