Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fact-ebpf/src/bpf/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ int BPF_PROG(trace_path_unlink, struct path* dir, struct dentry* dentry) {
return 0;
}

// We only support files with one link for now
inode_remove(&inode_key);

submit_unlink_event(&m->path_unlink,
path->path,
inode_to_submit);
Expand Down
4 changes: 4 additions & 0 deletions fact/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ impl Event {
})
}

pub fn is_unlink(&self) -> bool {
matches!(self.file, FileData::Unlink(_))
}

/// Unwrap the inner FileData and return the inode that triggered
/// the event.
///
Expand Down
17 changes: 17 additions & 0 deletions fact/src/host_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ impl HostScanner {
self.inode_map.borrow().get(inode?).cloned()
}

/// Special handling for unlink events.
///
/// This method removes the inode from the userland inode->path map.
/// The probe already cleared the kernel inode map.
fn handle_unlink_event(&self, event: &Event) {
let inode = event.get_inode();

if self.inode_map.borrow_mut().remove(inode).is_some() {
self.metrics.scan_inc(ScanLabels::InodeRemoved);
}
}

/// Periodically notify the host scanner main task that a scan needs
/// to happen.
///
Expand Down Expand Up @@ -229,6 +241,11 @@ impl HostScanner {
event.set_old_host_path(host_path);
}

// Special handling for unlink events
if event.is_unlink() {
self.handle_unlink_event(&event);
}

let event = Arc::new(event);
if let Err(e) = self.tx.send(event) {
self.metrics.events.dropped();
Expand Down
Loading