Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions libbpf-rs/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ impl<'obj> OpenMap<'obj> {
pub fn autocreate(&self) -> bool {
unsafe { libbpf_sys::bpf_map__autocreate(self.ptr.as_ptr()) }
}

/// Retrieve the map flags.
pub fn map_flags(&self) -> u32 {
unsafe { libbpf_sys::bpf_map__map_flags(self.ptr.as_ptr()) }
}

/// Retrieve the map numa node.
pub fn numa_node(&self) -> u32 {
unsafe { libbpf_sys::bpf_map__numa_node(self.ptr.as_ptr()) }
}

/// Retrieve the key size of the map in bytes.
pub fn key_size(&self) -> u32 {
unsafe { libbpf_sys::bpf_map__key_size(self.ptr.as_ptr()) }
}

/// Retrieve the value size of the map in bytes.
pub fn value_size(&self) -> u32 {
unsafe { libbpf_sys::bpf_map__value_size(self.ptr.as_ptr()) }
}
}

impl<'obj> OpenMapMut<'obj> {
Expand Down
20 changes: 20 additions & 0 deletions libbpf-rs/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,26 @@ fn test_map_query_fdinfo() {
assert_eq!(fdinfo.owner_jited, None);
}

/// Check that `OpenMap` gets information correctly.
#[tag(root)]
#[test]
fn test_map_get_info() {
let obj = open_test_object("runqslower.bpf.o");

let start = obj
.maps()
.find(|map| map.name() == OsStr::new("start"))
.expect("failed to find `start` map");

assert!(start.autocreate());
assert_eq!(start.key_size(), size_of::<u32>() as _);
assert_eq!(start.value_size(), size_of::<u64>() as _);
assert_eq!(start.map_flags(), 0);
assert_eq!(start.map_type(), MapType::Hash);
assert_eq!(start.max_entries(), 10240);
assert_eq!(start.numa_node(), 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NUMA node seems bogus to me. Is there any guarantee it will be 0? If not let's leave it out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref to doc of bpf_map__numa_node: https://docs.ebpf.io/ebpf-library/libbpf/userspace/bpf_map__numa_node/ .
And it says "NUMA node the map is or will be created on. Or 0 if no preference is given". So I think 0 should be expected for this map

}

/// Check that we can adjust a map's value size.
#[tag(root)]
#[test]
Expand Down