aya: per_cpu_hash_map: add support for BPF_MAP_TYPE_LRU_PERCPU_HASH

pull/1/head
Alessandro Decina 4 years ago
parent 635dcd44b9
commit 7a989b43b9

@ -7,7 +7,7 @@ use std::{
}; };
use crate::{ use crate::{
generated::bpf_map_type::BPF_MAP_TYPE_PERCPU_HASH, generated::bpf_map_type::{BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_PERCPU_HASH},
maps::{ maps::{
hash_map, IterableMap, Map, MapError, MapIter, MapKeys, MapRef, MapRefMut, PerCpuValues, hash_map, IterableMap, Map, MapError, MapIter, MapKeys, MapRef, MapRefMut, PerCpuValues,
}, },
@ -18,6 +18,9 @@ use crate::{
/// Similar to [`HashMap`](crate::maps::HashMap) but each CPU holds a separate value for a given key. Tipically used to /// Similar to [`HashMap`](crate::maps::HashMap) but each CPU holds a separate value for a given key. Tipically used to
/// minimize lock contention in eBPF programs. /// minimize lock contention in eBPF programs.
/// ///
/// This type can be used with eBPF maps of type `BPF_MAP_TYPE_PERCPU_HASH` and
/// `BPF_MAP_TYPE_LRU_PERCPU_HASH`.
///
/// # Example /// # Example
/// ///
/// ```no_run /// ```no_run
@ -36,6 +39,8 @@ use crate::{
/// } /// }
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::BpfError>(())
/// ``` /// ```
#[doc(alias = "BPF_MAP_TYPE_LRU_PERCPU_HASH")]
#[doc(alias = "BPF_MAP_TYPE_PERCPU_HASH")]
pub struct PerCpuHashMap<T: Deref<Target = Map>, K: Pod, V: Pod> { pub struct PerCpuHashMap<T: Deref<Target = Map>, K: Pod, V: Pod> {
inner: T, inner: T,
_k: PhantomData<K>, _k: PhantomData<K>,
@ -47,7 +52,9 @@ impl<T: Deref<Target = Map>, K: Pod, V: Pod> PerCpuHashMap<T, K, V> {
let map_type = map.obj.def.map_type; let map_type = map.obj.def.map_type;
// validate the map definition // validate the map definition
if map_type != BPF_MAP_TYPE_PERCPU_HASH as u32 { if map_type != BPF_MAP_TYPE_PERCPU_HASH as u32
&& map_type != BPF_MAP_TYPE_LRU_PERCPU_HASH as u32
{
return Err(MapError::InvalidMapType { return Err(MapError::InvalidMapType {
map_type: map_type as u32, map_type: map_type as u32,
})?; })?;

Loading…
Cancel
Save