Skip to content
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

libbpf-tools: add BPF CO-RE filegone #4978

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kerennaomidev
Copy link

This is a CO-RE port of the filegone BCC Python tool. The code is inspired by the 'filelife' port.

$ cd libbpf-tools/
$ make filegone 
$ sudo ./filegone 
TIME     PID     COMM         ACTION FILE
16:44:07 172531  mv           RENAME testfile > testfile2
16:44:10 172687  rm           DELETE testfile2

Supports [-p PID] filter option.

Please let us know if any changes are required.

This is a CO-RE port of the filegone BCC Python tool. The code is
inspired by the 'filelife' port.

Signed-off-by: Keren Naomi <[email protected]>
@kerennaomidev kerennaomidev force-pushed the libbpf-tools-filegone branch from 0174990 to 28c3bf4 Compare April 30, 2024 14:05
@@ -22,6 +22,7 @@
/f2fsdist
/f2fsslower
/filelife
/filegone
Copy link
Contributor

@ekyooo ekyooo Dec 3, 2024

Choose a reason for hiding this comment

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

filegone comes before filelife in the dictionary.
Please keep the list sorted.

@@ -55,6 +55,7 @@ APPS = \
execsnoop \
exitsnoop \
filelife \
filegone \
Copy link
Contributor

Choose a reason for hiding this comment

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

filegone comes before filelife in the dictionary.

if (targ_tgid && targ_tgid != tgid)
return 0;

bool has_arg = renamedata_has_old_mnt_userns_field()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please declare variables first.

if (targ_tgid && targ_tgid != tgid)
return 0;

bool has_arg = renamedata_has_old_mnt_userns_field()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please declare variables first.

" filegone -p 123 # trace pid 123\n";

static const struct argp_option opts[] = {
{"pid", 'p', "PID", 0, "Process PID to trace"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the missing initialize group field.
Refer to commit - 74fe720


struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 8192);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using macro instead of magic number?

bpf_get_current_comm(&event.task, sizeof(event.task));
bpf_probe_read_kernel_str(&event.fname, sizeof(event.fname), qs_name_ptr.name);
bpf_probe_read_kernel_str(&event.fname2, sizeof(event.fname2), qd_name_ptr.name);
event.action = 'R';
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using an enum type for action values?
Using enum values like RENAME and DELETE could be more descriptive.

memcpy(&e, data, sizeof(e));
action_str = action2str(e.action);

if (strcmp(action_str, "RENAME") == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we can classify the values of action using an enum type, without string comparison.

return (action == 'D') ? "DELETE" : "RENAME";
}

void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
Copy link
Contributor

Choose a reason for hiding this comment

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

how about declaring static if available?

#include "filegone.h"
#include "core_fixes.bpf.h"

#define FMODE_CREATED 0x100000
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not used as I check.

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