Browse Source

bpf: Add HashMap::pinned API

Alessandro Decina 3 years ago
parent
commit
696ae6079c
1 changed files with 16 additions and 0 deletions
  1. 16 0
      bpf/aya-bpf/src/maps/hash_map.rs

+ 16 - 0
bpf/aya-bpf/src/maps/hash_map.rs

@@ -31,6 +31,22 @@ impl<K, V> HashMap<K, V> {
         }
     }
 
+    pub const fn pinned(max_entries: u32, flags: u32, pinning: u32) -> HashMap<K, V> {
+        HashMap {
+            def: bpf_map_def {
+                type_: BPF_MAP_TYPE_HASH,
+                key_size: mem::size_of::<K>() as u32,
+                value_size: mem::size_of::<V>() as u32,
+                max_entries,
+                map_flags: flags,
+                id: 0,
+                pinning,
+            },
+            _k: PhantomData,
+            _v: PhantomData,
+        }
+    }
+
     pub unsafe fn get(&mut self, key: &K) -> Option<&V> {
         let value = bpf_map_lookup_elem(
             &mut self.def as *mut _ as *mut _,