Skip to content

Commit

Permalink
aya: add StackTraceMap::remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrod authored and vadorovsky committed Jan 29, 2024
1 parent 057f27d commit 92b1947
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 24 additions & 2 deletions aya/src/maps/stack_trace.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -157,6 +163,22 @@ impl<'a, T: Borrow<MapData>> IntoIterator for &'a StackTraceMap<T> {
}
}

impl<T: BorrowMut<MapData>> StackTraceMap<T> {
/// 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.
Expand Down
4 changes: 4 additions & 0 deletions xtask/public-api/aya.txt
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ pub fn aya::maps::stack_trace::StackTraceMap<T>::iter(&self) -> aya::maps::MapIt
pub fn aya::maps::stack_trace::StackTraceMap<T>::stack_ids(&self) -> aya::maps::MapKeys<'_, u32>
impl<T: core::borrow::Borrow<aya::maps::MapData>> aya::maps::stack_trace::StackTraceMap<T>
pub fn aya::maps::stack_trace::StackTraceMap<T>::pin<P: core::convert::AsRef<std::path::Path>>(self, path: P) -> core::result::Result<(), aya::pin::PinError>
impl<T: core::borrow::BorrowMut<aya::maps::MapData>> aya::maps::stack_trace::StackTraceMap<T>
pub fn aya::maps::stack_trace::StackTraceMap<T>::remove(&mut self, stack_id: &u32) -> core::result::Result<(), aya::maps::MapError>
impl core::convert::TryFrom<aya::maps::Map> for aya::maps::stack_trace::StackTraceMap<aya::maps::MapData>
pub type aya::maps::stack_trace::StackTraceMap<aya::maps::MapData>::Error = aya::maps::MapError
pub fn aya::maps::stack_trace::StackTraceMap<aya::maps::MapData>::try_from(map: aya::maps::Map) -> core::result::Result<Self, Self::Error>
Expand Down Expand Up @@ -2231,6 +2233,8 @@ pub fn aya::maps::stack_trace::StackTraceMap<T>::iter(&self) -> aya::maps::MapIt
pub fn aya::maps::stack_trace::StackTraceMap<T>::stack_ids(&self) -> aya::maps::MapKeys<'_, u32>
impl<T: core::borrow::Borrow<aya::maps::MapData>> aya::maps::stack_trace::StackTraceMap<T>
pub fn aya::maps::stack_trace::StackTraceMap<T>::pin<P: core::convert::AsRef<std::path::Path>>(self, path: P) -> core::result::Result<(), aya::pin::PinError>
impl<T: core::borrow::BorrowMut<aya::maps::MapData>> aya::maps::stack_trace::StackTraceMap<T>
pub fn aya::maps::stack_trace::StackTraceMap<T>::remove(&mut self, stack_id: &u32) -> core::result::Result<(), aya::maps::MapError>
impl core::convert::TryFrom<aya::maps::Map> for aya::maps::stack_trace::StackTraceMap<aya::maps::MapData>
pub type aya::maps::stack_trace::StackTraceMap<aya::maps::MapData>::Error = aya::maps::MapError
pub fn aya::maps::stack_trace::StackTraceMap<aya::maps::MapData>::try_from(map: aya::maps::Map) -> core::result::Result<Self, Self::Error>
Expand Down

0 comments on commit 92b1947

Please sign in to comment.