Skip to content

Commit

Permalink
libbpf-rs: remove deprecated bpf_map__def() usage
Browse files Browse the repository at this point in the history
bpf_map__def() is deprecated since libbpf-0.8.
This commit changes the code to use the appropriate getters/setters
instead.

Signed-off-by: Joanne Koong <joannekoong@gmail.com>
  • Loading branch information
insearchoflosttime committed Jul 26, 2022
1 parent a8073fa commit 40d25f5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions libbpf-rs/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,20 @@ impl Object {
let name = unsafe { libbpf_sys::bpf_map__name(next_ptr) };
let name = util::c_ptr_to_string(name)?;

// Get the map def
// bpf_map__def can return null but only if it's passed a null.
// We already know next_ptr is not null.
let def = unsafe { ptr::read(libbpf_sys::bpf_map__def(next_ptr)) };

// Get the map fd
let fd = unsafe { libbpf_sys::bpf_map__fd(next_ptr) };
if fd < 0 {
return Err(Error::System(-fd));
}

let map_type = unsafe { libbpf_sys::bpf_map__type(next_ptr) };
let key_size = unsafe { libbpf_sys::bpf_map__key_size(next_ptr) };
let value_size = unsafe { libbpf_sys::bpf_map__value_size(next_ptr) };

// Add the map to the hashmap
obj.maps.insert(
name.clone(),
Map::new(fd, name, def.type_, def.key_size, def.value_size, next_ptr),
Map::new(fd, name, map_type, key_size, value_size, next_ptr),
);
map = next_ptr;
}
Expand Down

0 comments on commit 40d25f5

Please # to comment.