pub struct BpfSyscallAccessor { /* private fields */ }Expand description
Live-host BPF map accessor.
Construction enumerates every map id reachable via
BPF_MAP_GET_NEXT_ID, opens an fd for each via
BPF_MAP_GET_FD_BY_ID, and caches the metadata. The fd vector is
held for the accessor’s lifetime so the maps cannot be freed
underneath us — even if the scheduler exits and tears down its
struct_ops link mid-walk.
Selectively populating the cache is intentional: the same trait
surface accepts a BpfMapInfo argument on every method, so an
accessor that holds only the maps a particular failure dump cares
about (filtered by name suffix at construction time) is just as
valid as one that holds every map on the system. The
from_running_kernel_filtered constructor exposes that knob.
Implementations§
Source§impl BpfSyscallAccessor
impl BpfSyscallAccessor
Sourcepub fn from_running_kernel() -> Result<Self>
pub fn from_running_kernel() -> Result<Self>
Discover and pin every BPF map currently visible to the running kernel.
Walks the kernel’s id space via BPF_MAP_GET_NEXT_ID (starting
from id 0), pinning each map with BPF_MAP_GET_FD_BY_ID and
fetching its metadata via BPF_OBJ_GET_INFO_BY_FD. Maps that
disappear between the NEXT_ID and GET_FD_BY_ID calls (a
concurrent scheduler unload, for instance) are silently
skipped — that race is inherent to live-host enumeration and
is not an error.
Requires CAP_SYS_ADMIN. ktstr always runs as root in the
test environment so this is a non-issue for the primary
consumer; live-host CLI users that hit EPERM will see it
in the returned error.
Sourcepub fn from_running_kernel_filtered<F>(predicate: F) -> Result<Self>
pub fn from_running_kernel_filtered<F>(predicate: F) -> Result<Self>
Discover and pin every BPF map for which predicate returns
true. Maps that fail the predicate are closed (their fds
drop) so the kernel can free them as usual.
Useful when the caller knows which maps the failure dump will touch — typically the scheduler’s named maps that match a specific suffix — and wants to avoid pinning hundreds of unrelated maps that happen to be alive (cilium, systemd, other workloads).
Trait Implementations§
Source§impl BpfMapAccessor for BpfSyscallAccessor
impl BpfMapAccessor for BpfSyscallAccessor
Source§fn read_value(
&self,
map: &BpfMapInfo,
offset: usize,
len: usize,
) -> Option<Vec<u8>>
fn read_value( &self, map: &BpfMapInfo, offset: usize, len: usize, ) -> Option<Vec<u8>>
Source§fn read_array(&self, map: &BpfMapInfo, key: u32) -> Option<Vec<u8>>
fn read_array(&self, map: &BpfMapInfo, key: u32) -> Option<Vec<u8>>
BPF_MAP_TYPE_ARRAY map
by entry index. Read moreSource§fn iter_hash_map(&self, map: &BpfMapInfo) -> Vec<(Vec<u8>, Vec<u8>)>
fn iter_hash_map(&self, map: &BpfMapInfo) -> Vec<(Vec<u8>, Vec<u8>)>
Source§fn read_percpu_array(
&self,
map: &BpfMapInfo,
key: u32,
num_cpus: u32,
) -> Vec<Option<Vec<u8>>>
fn read_percpu_array( &self, map: &BpfMapInfo, key: u32, num_cpus: u32, ) -> Vec<Option<Vec<u8>>>
BPF_MAP_TYPE_PERCPU_ARRAY map. Read moreSource§fn iter_percpu_hash_map(
&self,
map: &BpfMapInfo,
num_cpus: u32,
) -> Vec<(Vec<u8>, Vec<Option<Vec<u8>>>)>
fn iter_percpu_hash_map( &self, map: &BpfMapInfo, num_cpus: u32, ) -> Vec<(Vec<u8>, Vec<Option<Vec<u8>>>)>
BPF_MAP_TYPE_PERCPU_HASH or
BPF_MAP_TYPE_LRU_PERCPU_HASH map. Returns
(key_bytes, per_cpu_values) where per_cpu_values is one
entry per CPU indexed by CPU number; Some(bytes) when the
CPU’s slot is readable, None otherwise (unmapped page or
out-of-range CPU). Read moreSource§fn read_arena_pages(
&self,
map: &BpfMapInfo,
_arena_offsets: &BpfArenaOffsets,
) -> ArenaSnapshot
fn read_arena_pages( &self, map: &BpfMapInfo, _arena_offsets: &BpfArenaOffsets, ) -> ArenaSnapshot
BPF_MAP_TYPE_ARENA map. Read moreSource§fn load_program_btf(&self, map: &BpfMapInfo, base_btf: &Btf) -> Option<Btf>
fn load_program_btf(&self, map: &BpfMapInfo, base_btf: &Btf) -> Option<Btf>
Source§fn find_map(&self, name_suffix: &str) -> Option<BpfMapInfo>
fn find_map(&self, name_suffix: &str) -> Option<BpfMapInfo>
name_suffix. Read moreSource§fn iter_task_storage(&self, _map: &BpfMapInfo) -> Vec<(Vec<u8>, Vec<u8>)>
fn iter_task_storage(&self, _map: &BpfMapInfo) -> Vec<(Vec<u8>, Vec<u8>)>
BPF_MAP_TYPE_TASK_STORAGE map (and
the shape-identical INODE_STORAGE / SK_STORAGE /
CGRP_STORAGE variants — they all use
super::btf_offsets::TaskStorageOffsets). Read moreAuto Trait Implementations§
impl Freeze for BpfSyscallAccessor
impl RefUnwindSafe for BpfSyscallAccessor
impl Send for BpfSyscallAccessor
impl Sync for BpfSyscallAccessor
impl Unpin for BpfSyscallAccessor
impl UnwindSafe for BpfSyscallAccessor
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more