@@ -21,6 +21,15 @@ struct submit_event_args_t {
2121 bool use_bpf_d_path ;
2222};
2323
24+ __always_inline static bool reserve_event (struct submit_event_args_t * args ) {
25+ args -> event = bpf_ringbuf_reserve (& rb , sizeof (struct event_t ), 0 );
26+ if (args -> event == NULL ) {
27+ args -> metrics -> ringbuffer_full ++ ;
28+ return false;
29+ }
30+ return true;
31+ }
32+
2433__always_inline static void __submit_event (struct submit_event_args_t * args ) {
2534 struct event_t * event = args -> event ;
2635 event -> timestamp = bpf_ktime_get_boot_ns ();
@@ -50,9 +59,7 @@ __always_inline static void __submit_event(struct submit_event_args_t* args) {
5059
5160__always_inline static void submit_open_event (struct submit_event_args_t * args ,
5261 file_activity_type_t event_type ) {
53- args -> event = bpf_ringbuf_reserve (& rb , sizeof (struct event_t ), 0 );
54- if (args -> event == NULL ) {
55- args -> metrics -> ringbuffer_full ++ ;
62+ if (!reserve_event (args )) {
5663 return ;
5764 }
5865 args -> event -> type = event_type ;
@@ -61,9 +68,7 @@ __always_inline static void submit_open_event(struct submit_event_args_t* args,
6168}
6269
6370__always_inline static void submit_unlink_event (struct submit_event_args_t * args ) {
64- args -> event = bpf_ringbuf_reserve (& rb , sizeof (struct event_t ), 0 );
65- if (args -> event == NULL ) {
66- args -> metrics -> ringbuffer_full ++ ;
71+ if (!reserve_event (args )) {
6772 return ;
6873 }
6974 args -> event -> type = FILE_ACTIVITY_UNLINK ;
@@ -74,9 +79,7 @@ __always_inline static void submit_unlink_event(struct submit_event_args_t* args
7479__always_inline static void submit_mode_event (struct submit_event_args_t * args ,
7580 umode_t mode ,
7681 umode_t old_mode ) {
77- args -> event = bpf_ringbuf_reserve (& rb , sizeof (struct event_t ), 0 );
78- if (args -> event == NULL ) {
79- args -> metrics -> ringbuffer_full ++ ;
82+ if (!reserve_event (args )) {
8083 return ;
8184 }
8285
@@ -92,9 +95,7 @@ __always_inline static void submit_ownership_event(struct submit_event_args_t* a
9295 unsigned long long gid ,
9396 unsigned long long old_uid ,
9497 unsigned long long old_gid ) {
95- args -> event = bpf_ringbuf_reserve (& rb , sizeof (struct event_t ), 0 );
96- if (args -> event == NULL ) {
97- args -> metrics -> ringbuffer_full ++ ;
98+ if (!reserve_event (args )) {
9899 return ;
99100 }
100101
@@ -110,9 +111,7 @@ __always_inline static void submit_ownership_event(struct submit_event_args_t* a
110111__always_inline static void submit_rename_event (struct submit_event_args_t * args ,
111112 const char old_filename [PATH_MAX ],
112113 inode_key_t * old_inode ) {
113- args -> event = bpf_ringbuf_reserve (& rb , sizeof (struct event_t ), 0 );
114- if (args -> event == NULL ) {
115- args -> metrics -> ringbuffer_full ++ ;
114+ if (!reserve_event (args )) {
116115 return ;
117116 }
118117
@@ -124,9 +123,7 @@ __always_inline static void submit_rename_event(struct submit_event_args_t* args
124123}
125124
126125__always_inline static void submit_mkdir_event (struct submit_event_args_t * args ) {
127- args -> event = bpf_ringbuf_reserve (& rb , sizeof (struct event_t ), 0 );
128- if (args -> event == NULL ) {
129- args -> metrics -> ringbuffer_full ++ ;
126+ if (!reserve_event (args )) {
130127 return ;
131128 }
132129 args -> event -> type = DIR_ACTIVITY_CREATION ;
0 commit comments