diff --git a/aya/src/maps/stack_trace.rs b/aya/src/maps/stack_trace.rs index 389b28f7..5a122a92 100644 --- a/aya/src/maps/stack_trace.rs +++ b/aya/src/maps/stack_trace.rs @@ -1,11 +1,17 @@ //! A hash map of kernel or user space stack traces. //! //! See [`StackTraceMap`] for documentation and examples. -use std::{borrow::Borrow, fs, io, mem, os::fd::AsFd as _, path::Path, str::FromStr}; +use std::{ + borrow::{Borrow, BorrowMut}, + fs, io, mem, + os::fd::AsFd as _, + path::Path, + str::FromStr, +}; use crate::{ maps::{IterableMap, MapData, MapError, MapIter, MapKeys}, - sys::{bpf_map_lookup_elem_ptr, SyscallError}, + sys::{bpf_map_delete_elem, bpf_map_lookup_elem_ptr, SyscallError}, }; /// A hash map of kernel or user space stack traces. @@ -157,6 +163,22 @@ impl<'a, T: Borrow> IntoIterator for &'a StackTraceMap { } } +impl> StackTraceMap { + /// Removes the stack trace with the given stack_id. + pub fn remove(&mut self, stack_id: &u32) -> Result<(), MapError> { + let fd = self.inner.borrow().fd().as_fd(); + bpf_map_delete_elem(fd, stack_id) + .map(|_| ()) + .map_err(|(_, io_error)| { + SyscallError { + call: "bpf_map_delete_elem", + io_error, + } + .into() + }) + } +} + /// A kernel or user space stack trace. /// /// See the [`StackTraceMap`] documentation for examples. diff --git a/xtask/public-api/aya.txt b/xtask/public-api/aya.txt index 0aa722a5..66a33253 100644 --- a/xtask/public-api/aya.txt +++ b/xtask/public-api/aya.txt @@ -849,6 +849,8 @@ pub fn aya::maps::stack_trace::StackTraceMap::iter(&self) -> aya::maps::MapIt pub fn aya::maps::stack_trace::StackTraceMap::stack_ids(&self) -> aya::maps::MapKeys<'_, u32> impl> aya::maps::stack_trace::StackTraceMap pub fn aya::maps::stack_trace::StackTraceMap::pin>(self, path: P) -> core::result::Result<(), aya::pin::PinError> +impl> aya::maps::stack_trace::StackTraceMap +pub fn aya::maps::stack_trace::StackTraceMap::remove(&mut self, stack_id: &u32) -> core::result::Result<(), aya::maps::MapError> impl core::convert::TryFrom for aya::maps::stack_trace::StackTraceMap pub type aya::maps::stack_trace::StackTraceMap::Error = aya::maps::MapError pub fn aya::maps::stack_trace::StackTraceMap::try_from(map: aya::maps::Map) -> core::result::Result @@ -2231,6 +2233,8 @@ pub fn aya::maps::stack_trace::StackTraceMap::iter(&self) -> aya::maps::MapIt pub fn aya::maps::stack_trace::StackTraceMap::stack_ids(&self) -> aya::maps::MapKeys<'_, u32> impl> aya::maps::stack_trace::StackTraceMap pub fn aya::maps::stack_trace::StackTraceMap::pin>(self, path: P) -> core::result::Result<(), aya::pin::PinError> +impl> aya::maps::stack_trace::StackTraceMap +pub fn aya::maps::stack_trace::StackTraceMap::remove(&mut self, stack_id: &u32) -> core::result::Result<(), aya::maps::MapError> impl core::convert::TryFrom for aya::maps::stack_trace::StackTraceMap pub type aya::maps::stack_trace::StackTraceMap::Error = aya::maps::MapError pub fn aya::maps::stack_trace::StackTraceMap::try_from(map: aya::maps::Map) -> core::result::Result