From 7a989b43b9ee5b4807f53001c2d7d8824a162a34 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Sat, 13 Mar 2021 22:37:20 +0000 Subject: [PATCH] aya: per_cpu_hash_map: add support for BPF_MAP_TYPE_LRU_PERCPU_HASH --- aya/src/maps/hash_map/per_cpu_hash_map.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aya/src/maps/hash_map/per_cpu_hash_map.rs b/aya/src/maps/hash_map/per_cpu_hash_map.rs index 98500c97..a61fb7ed 100644 --- a/aya/src/maps/hash_map/per_cpu_hash_map.rs +++ b/aya/src/maps/hash_map/per_cpu_hash_map.rs @@ -7,7 +7,7 @@ use std::{ }; 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::{ 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 /// 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 /// /// ```no_run @@ -36,6 +39,8 @@ use crate::{ /// } /// # Ok::<(), aya::BpfError>(()) /// ``` +#[doc(alias = "BPF_MAP_TYPE_LRU_PERCPU_HASH")] +#[doc(alias = "BPF_MAP_TYPE_PERCPU_HASH")] pub struct PerCpuHashMap, K: Pod, V: Pod> { inner: T, _k: PhantomData, @@ -47,7 +52,9 @@ impl, K: Pod, V: Pod> PerCpuHashMap { let map_type = map.obj.def.map_type; // 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 { map_type: map_type as u32, })?;