Skip to content

Commit

Permalink
Avoid warning with allow_unsupported_maps
Browse files Browse the repository at this point in the history
Remove the warning log altogether; either it's an error or it isn't.
  • Loading branch information
banditopazzo authored and tamird committed Nov 21, 2024
1 parent 0b58d3e commit a167550
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
28 changes: 14 additions & 14 deletions aya/src/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,23 +695,17 @@ impl<'a> EbpfLoader<'a> {
.collect();
let maps = maps
.drain()
.map(parse_map)
.map(|data| parse_map(data, *allow_unsupported_maps))
.collect::<Result<HashMap<String, Map>, EbpfError>>()?;

if !*allow_unsupported_maps {
maps.iter().try_for_each(|(_, x)| match x {
Map::Unsupported(map) => Err(EbpfError::MapError(MapError::Unsupported {
map_type: map.obj().map_type(),
})),
_ => Ok(()),
})?;
};

Ok(Ebpf { maps, programs })
}
}

fn parse_map(data: (String, MapData)) -> Result<(String, Map), EbpfError> {
fn parse_map(
data: (String, MapData),
allow_unsupported_maps: bool,
) -> Result<(String, Map), EbpfError> {
let (name, map) = data;
let map_type = bpf_map_type::try_from(map.obj().map_type()).map_err(MapError::from)?;
let map = match map_type {
Expand All @@ -735,9 +729,15 @@ fn parse_map(data: (String, MapData)) -> Result<(String, Map), EbpfError> {
BPF_MAP_TYPE_DEVMAP => Map::DevMap(map),
BPF_MAP_TYPE_DEVMAP_HASH => Map::DevMapHash(map),
BPF_MAP_TYPE_XSKMAP => Map::XskMap(map),
m => {
warn!("The map {name} is of type {:#?} which is currently unsupported in Aya, use `allow_unsupported_maps()` to load it anyways", m);
Map::Unsupported(map)
m_type => {
if allow_unsupported_maps {
Map::Unsupported(map)
} else {
return Err(EbpfError::MapError(MapError::Unsupported {
name,
map_type: m_type,
}));
}
}
};

Expand Down
6 changes: 4 additions & 2 deletions aya/src/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,12 @@ pub enum MapError {
ProgIdNotSupported,

/// Unsupported Map type
#[error("Unsupported map type found {map_type}")]
#[error("type of {name} ({map_type:?}) is unsupported; see `EbpfLoader::allow_unsupported_maps`")]
Unsupported {
/// Map name
name: String,
/// The map type
map_type: u32,
map_type: bpf_map_type,
},
}

Expand Down
3 changes: 2 additions & 1 deletion xtask/public-api/aya.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,8 @@ pub aya::maps::MapError::ProgIdNotSupported
pub aya::maps::MapError::ProgramNotLoaded
pub aya::maps::MapError::SyscallError(aya::sys::SyscallError)
pub aya::maps::MapError::Unsupported
pub aya::maps::MapError::Unsupported::map_type: u32
pub aya::maps::MapError::Unsupported::map_type: aya_obj::generated::linux_bindings_x86_64::bpf_map_type
pub aya::maps::MapError::Unsupported::name: alloc::string::String
impl core::convert::From<aya::maps::MapError> for aya::EbpfError
pub fn aya::EbpfError::from(source: aya::maps::MapError) -> Self
impl core::convert::From<aya::maps::MapError> for aya::maps::xdp::XdpMapError
Expand Down

0 comments on commit a167550

Please sign in to comment.