@@ -6,21 +6,26 @@ static __always_inline int trace_file_operation(struct pt_regs *ctx, struct file
66 if (!file )
77 return 0 ;
88
9- u32 zero = 0 ;
10- struct data_t * data = bpf_map_lookup_elem (& logs_data , & zero );
11- if (!data )
9+ struct data_t * data = bpf_ringbuf_reserve (& events , sizeof (struct data_t ), 0 );
10+ if (!data ) {
1211 return 0 ;
12+ }
1313 __builtin_memset (data , 0 , sizeof (* data ));
1414
15+
1516 struct dentry * de = NULL ;
1617 bpf_core_read (& de , sizeof (de ), & file -> f_path .dentry );
17- if (!de )
18+ if (!de ) {
19+ bpf_ringbuf_discard (data , 0 );
1820 return 0 ;
21+ }
1922
2023 struct qstr d_name = {};
2124 bpf_core_read (& d_name , sizeof (d_name ), & de -> d_name );
22- if (d_name .len == 0 )
25+ if (d_name .len == 0 ) {
26+ bpf_ringbuf_discard (data , 0 );
2327 return 0 ;
28+ }
2429
2530 char fname [128 ] = {};
2631 bpf_core_read_str (fname , sizeof (fname ), d_name .name );
@@ -35,8 +40,10 @@ static __always_inline int trace_file_operation(struct pt_regs *ctx, struct file
3540
3641 struct inode * inode = NULL ;
3742 bpf_core_read (& inode , sizeof (inode ), & file -> f_inode );
38- if (!inode )
43+ if (!inode ) {
44+ bpf_ringbuf_discard (data , 0 );
3945 return 0 ;
46+ }
4047
4148 u32 inode_num = 0 ;
4249 bpf_core_read (& inode_num , sizeof (inode_num ), & inode -> i_ino );
@@ -47,9 +54,12 @@ static __always_inline int trace_file_operation(struct pt_regs *ctx, struct file
4754 bpf_trace_printk ("LOG: inode=%u\n" , sizeof ("LOG: inode=%u\n" ), inode_num );
4855
4956 u32 * monitored = bpf_map_lookup_elem (& monitored_inodes , & key );
50- if (!monitored )
57+ if (!monitored ) {
58+ bpf_ringbuf_discard (data , 0 );
5159 return 0 ;
60+ }
61+
62+ bpf_ringbuf_submit (data , 0 );
5263
53- bpf_perf_event_output (ctx , & events , BPF_F_CURRENT_CPU , data , sizeof (* data ));
5464 return 0 ;
5565}
0 commit comments