Repository: aya-rs/aya (language: rust)

Issue:
Unsupported map type warning message doesn't go away when unsupported type maps are allowed
I was trying to load an unsupported map type and I got the following error:

```console
The map my_task_storage is of type BPF_MAP_TYPE_TASK_STORAGE which is currently unsupported in Aya, use `allow_unsupported_maps()` to load it anyways
```

and my program crashes with something like:

```console
Unsupported map type found 29
```

and it's OK. 

Then I added `allow_unsupported_maps()` to `BpfLoader` it loads the program without crashing but prints again:

```console
The map my_task_storage is of type BPF_MAP_TYPE_TASK_STORAGE which is currently unsupported in Aya, use `allow_unsupported_maps()` to load it anyways
```


Discussion / hints:
Yah. The message could use some tweaking, or removed, when loading an unsupported map in aya with `allow_unsupported_maps` specified.

The [`parse_map()`](https://github.com/aya-rs/aya/blob/main/aya/src/bpf.rs#L698) function could probably be inlined like how `programs` is done.

Fix patch:
diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs
index bbe064b15..357232ac5 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::<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 {
@@ -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 bb6412888..ee072bf08 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 51106ea3d..9fdceb2db 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<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


Test patch: