From a16755089bb642ded73a592ac25c6e21771b5792 Mon Sep 17 00:00:00 2001 From: banditopazzo Date: Mon, 18 Nov 2024 23:33:28 +0100 Subject: [PATCH] Avoid warning with `allow_unsupported_maps` Remove the warning log altogether; either it's an error or it isn't. --- aya/src/bpf.rs | 28 ++++++++++++++-------------- aya/src/maps/mod.rs | 6 ++++-- xtask/public-api/aya.txt | 3 ++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index bbe064b1..357232ac 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -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::, 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 { @@ -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, + })); + } } }; diff --git a/aya/src/maps/mod.rs b/aya/src/maps/mod.rs index bb641288..ee072bf0 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -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, }, } diff --git a/xtask/public-api/aya.txt b/xtask/public-api/aya.txt index 51106ea3..9fdceb2d 100644 --- a/xtask/public-api/aya.txt +++ b/xtask/public-api/aya.txt @@ -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 for aya::EbpfError pub fn aya::EbpfError::from(source: aya::maps::MapError) -> Self impl core::convert::From for aya::maps::xdp::XdpMapError