aya: remove pop()

lookup_and_delete_elem is only supported for QUEUE and STACK maps at the
moment.
pull/1/head
Alessandro Decina 4 years ago
parent 1bbbf616b6
commit 6682a5ff39

@ -85,15 +85,6 @@ impl<T: DerefMut<Target = Map>, K: Pod, V: Pod> HashMap<T, K, V> {
Ok(())
}
pub unsafe fn pop(&mut self, key: &K) -> Result<Option<V>, MapError> {
let fd = self.inner.deref_mut().fd_or_err()?;
bpf_map_lookup_and_delete_elem(fd, key).map_err(|(code, io_error)| MapError::SyscallError {
call: "bpf_map_lookup_and_delete_elem".to_owned(),
code,
io_error,
})
}
pub fn remove(&mut self, key: &K) -> Result<(), MapError> {
let fd = self.inner.deref_mut().fd_or_err()?;
bpf_map_delete_elem(fd, key)
@ -374,39 +365,6 @@ mod tests {
assert!(matches!(unsafe { hm.get(&1, 0) }, Ok(None)));
}
#[test]
fn test_pop_syscall_error() {
override_syscall(|_| sys_error(EFAULT));
let mut map = Map {
obj: new_obj_map("TEST"),
fd: Some(42),
};
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();
assert!(matches!(
unsafe { hm.pop(&1) },
Err(MapError::SyscallError { call, code: -1, io_error }) if call == "bpf_map_lookup_and_delete_elem" && io_error.raw_os_error() == Some(EFAULT)
));
}
#[test]
fn test_pop_not_found() {
override_syscall(|call| match call {
Syscall::Bpf {
cmd: bpf_cmd::BPF_MAP_LOOKUP_AND_DELETE_ELEM,
..
} => sys_error(ENOENT),
_ => sys_error(EFAULT),
});
let mut map = Map {
obj: new_obj_map("TEST"),
fd: Some(42),
};
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();
assert!(matches!(unsafe { hm.pop(&1) }, Ok(None)));
}
fn bpf_key<T: Copy>(attr: &bpf_attr) -> Option<T> {
match unsafe { attr.__bindgen_anon_2.key } as *const T {
p if p.is_null() => None,

@ -9,10 +9,7 @@ use crate::{
generated::bpf_map_type::BPF_MAP_TYPE_PROG_ARRAY,
maps::{IterableMap, Map, MapError, MapIter, MapKeys, MapRef, MapRefMut},
programs::ProgramFd,
sys::{
bpf_map_delete_elem, bpf_map_lookup_and_delete_elem, bpf_map_lookup_elem,
bpf_map_update_elem,
},
sys::{bpf_map_delete_elem, bpf_map_lookup_elem, bpf_map_update_elem},
};
pub struct ProgramArray<T: Deref<Target = Map>> {
@ -94,18 +91,6 @@ impl<T: Deref<Target = Map> + DerefMut<Target = Map>> ProgramArray<T> {
Ok(())
}
pub unsafe fn pop(&mut self, index: &u32) -> Result<Option<RawFd>, MapError> {
let fd = self.inner.fd_or_err()?;
self.check_bounds(*index)?;
bpf_map_lookup_and_delete_elem(fd, index).map_err(|(code, io_error)| {
MapError::SyscallError {
call: "bpf_map_lookup_and_delete_elem".to_owned(),
code,
io_error,
}
})
}
pub fn remove(&mut self, index: &u32) -> Result<(), MapError> {
let fd = self.inner.fd_or_err()?;
self.check_bounds(*index)?;

Loading…
Cancel
Save