From 6682a5ff395d8fbea20393ff81140adcfc2a0c09 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Sat, 6 Mar 2021 04:58:17 +0000 Subject: [PATCH] aya: remove pop() lookup_and_delete_elem is only supported for QUEUE and STACK maps at the moment. --- aya/src/maps/hash_map.rs | 42 ----------------------------------- aya/src/maps/program_array.rs | 17 +------------- 2 files changed, 1 insertion(+), 58 deletions(-) diff --git a/aya/src/maps/hash_map.rs b/aya/src/maps/hash_map.rs index 129863f6..a3776077 100644 --- a/aya/src/maps/hash_map.rs +++ b/aya/src/maps/hash_map.rs @@ -85,15 +85,6 @@ impl, K: Pod, V: Pod> HashMap { Ok(()) } - pub unsafe fn pop(&mut self, key: &K) -> Result, 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(attr: &bpf_attr) -> Option { match unsafe { attr.__bindgen_anon_2.key } as *const T { p if p.is_null() => None, diff --git a/aya/src/maps/program_array.rs b/aya/src/maps/program_array.rs index 81f160a8..0a647825 100644 --- a/aya/src/maps/program_array.rs +++ b/aya/src/maps/program_array.rs @@ -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> { @@ -94,18 +91,6 @@ impl + DerefMut> ProgramArray { Ok(()) } - pub unsafe fn pop(&mut self, index: &u32) -> Result, 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)?;