pub struct Map {
pub name: String,
pub kind: u32,
/* private fields */
}
Expand description
A base BPF map data structure
It is a base data structure that contains a map definition and auxiliary
data. It just hods data but it does not provide any useful API to users.
See HashMap
,
LruHashMap
,
PerCpuHashMap
,
LruPerCpuHashMap
,
Array
, PerCpuArray
that wrap Map
to provide API of BPF maps to userspace programs.
Fields§
§name: String
§kind: u32
Implementations§
Source§impl Map
impl Map
pub fn load(name: &str, code: &[u8]) -> Result<Map>
Sourcepub fn from_pin_file(file: impl AsRef<Path>) -> Result<Map>
pub fn from_pin_file(file: impl AsRef<Path>) -> Result<Map>
Create Map
from a file which represents pinned map
§Example
use redbpf::{Array, Map};
let map = Map::from_pin_file("/sys/fs/bpf/persist_map").expect("error on creating map from file");
let array = Array::<u64>::new(&map).expect("error on creating array");
Sourcepub fn pin(&mut self, file: impl AsRef<Path>) -> Result<()>
pub fn pin(&mut self, file: impl AsRef<Path>) -> Result<()>
Pin map to BPF FS
§Example
use redbpf::Module;
use redbpf::load::Loader;
let mut loaded = Loader::load_file("file.elf").expect("error loading probe");
loaded.map_mut("persist_map").expect("map not found").pin("/sys/fs/bpf/persist_map").expect("error on pinning");
Sourcepub fn unpin(&mut self) -> Result<()>
pub fn unpin(&mut self) -> Result<()>
Unpin map
§Example
use redbpf::Module;
use redbpf::load::Loader;
let mut loaded = Loader::load_file("file.elf").expect("error loading probe");
let persist_map = loaded.map_mut("persist_map").expect("map not found");
persist_map.pin("/sys/fs/bpf/persist_map").expect("error on pinning");
// do some stuff...
persist_map.unpin().expect("error on unpinning");
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Map
impl RefUnwindSafe for Map
impl Send for Map
impl Sync for Map
impl Unpin for Map
impl UnwindSafe for Map
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more