Skip to content

Commit

Permalink
aya: Don't store bpf_fd in MapData
Browse files Browse the repository at this point in the history
This is only used in create and therefore can be passed
as a parameter.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
  • Loading branch information
dave-tucker committed Aug 11, 2023
1 parent c0a0827 commit db975e9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 77 deletions.
7 changes: 3 additions & 4 deletions aya/src/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
ffi::CString,
fs, io,
os::{
fd::{OwnedFd, RawFd},
fd::{AsFd as _, OwnedFd, RawFd},
raw::c_int,
},
path::{Path, PathBuf},
Expand Down Expand Up @@ -479,7 +479,6 @@ impl<'a> BpfLoader<'a> {
obj,
fd: None,
pinned: false,
btf_fd: btf_fd.as_ref().map(Arc::clone),
};
let fd = match map.obj.pinning() {
PinningType::ByName => {
Expand All @@ -494,7 +493,7 @@ impl<'a> BpfLoader<'a> {
fd as RawFd
}
Err(_) => {
let fd = map.create(&name)?;
let fd = map.create(&name, btf_fd.as_deref().map(|f| f.as_fd()))?;
map.pin(&name, path).map_err(|error| MapError::PinError {
name: Some(name.to_string()),
error,
Expand All @@ -503,7 +502,7 @@ impl<'a> BpfLoader<'a> {
}
}
}
PinningType::None => map.create(&name)?,
PinningType::None => map.create(&name, btf_fd.as_deref().map(|f| f.as_fd()))?,
};
if !map.obj.data().is_empty() && map.obj.section_kind() != BpfSectionKind::Bss {
bpf_map_update_elem_ptr(fd, &0 as *const _, map.obj.data_mut().as_mut_ptr(), 0)
Expand Down
9 changes: 0 additions & 9 deletions aya/src/maps/bloom_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};
assert_matches!(
BloomFilter::<_, u16>::new(&map),
Expand Down Expand Up @@ -145,7 +144,6 @@ mod tests {
}),
fd: None,
pinned: false,
btf_fd: None,
};

let map = Map::PerfEventArray(map_data);
Expand All @@ -162,7 +160,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};

assert_matches!(
Expand All @@ -177,7 +174,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};

assert!(BloomFilter::<_, u32>::new(&mut map).is_ok());
Expand All @@ -189,7 +185,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};

let map = Map::BloomFilter(map_data);
Expand All @@ -204,7 +199,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let bloom_filter = BloomFilter::<_, u32>::new(&mut map).unwrap();

Expand All @@ -228,7 +222,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};

let bloom_filter = BloomFilter::<_, u32>::new(&mut map).unwrap();
Expand All @@ -242,7 +235,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let bloom_filter = BloomFilter::<_, u32>::new(&map).unwrap();

Expand All @@ -265,7 +257,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let bloom_filter = BloomFilter::<_, u32>::new(&map).unwrap();

Expand Down
22 changes: 0 additions & 22 deletions aya/src/maps/hash_map/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};
assert_matches!(
HashMap::<_, u8, u32>::new(&map),
Expand All @@ -164,7 +163,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};
assert_matches!(
HashMap::<_, u32, u16>::new(&map),
Expand All @@ -181,7 +179,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};

let map = Map::Array(map_data);
Expand All @@ -197,7 +194,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};

let map = Map::HashMap(map_data);
Expand All @@ -216,7 +212,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};

assert_matches!(
Expand All @@ -231,7 +226,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};

assert!(HashMap::<_, u32, u32>::new(&mut map).is_ok());
Expand All @@ -243,7 +237,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};

let map = Map::HashMap(map_data);
Expand All @@ -268,7 +261,6 @@ mod tests {
}),
fd: Some(42),
pinned: false,
btf_fd: None,
};

let map = Map::HashMap(map_data);
Expand All @@ -284,7 +276,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();

Expand All @@ -308,7 +299,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();

Expand All @@ -329,7 +319,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();

Expand All @@ -344,7 +333,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();

Expand All @@ -368,7 +356,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let mut hm = HashMap::<_, u32, u32>::new(&mut map).unwrap();

Expand All @@ -382,7 +369,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();

Expand All @@ -405,7 +391,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();

Expand Down Expand Up @@ -442,7 +427,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();
let keys = hm.keys().collect::<Result<Vec<_>, _>>();
Expand Down Expand Up @@ -491,7 +475,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();

Expand Down Expand Up @@ -524,7 +507,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();

Expand Down Expand Up @@ -562,7 +544,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();
let items = hm.iter().collect::<Result<Vec<_>, _>>().unwrap();
Expand Down Expand Up @@ -600,7 +581,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();

Expand Down Expand Up @@ -639,7 +619,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();

Expand Down Expand Up @@ -687,7 +666,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let hm = HashMap::<_, u32, u32>::new(&map).unwrap();

Expand Down
12 changes: 0 additions & 12 deletions aya/src/maps/lpm_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};
assert_matches!(
LpmTrie::<_, u16, u32>::new(&map),
Expand All @@ -255,7 +254,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};
assert_matches!(
LpmTrie::<_, u32, u16>::new(&map),
Expand Down Expand Up @@ -283,7 +281,6 @@ mod tests {
data: Vec::new(),
}),
fd: None,
btf_fd: None,
pinned: false,
};

Expand All @@ -301,7 +298,6 @@ mod tests {
obj: new_obj_map(),
fd: None,
pinned: false,
btf_fd: None,
};

assert_matches!(
Expand All @@ -316,7 +312,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};

assert!(LpmTrie::<_, u32, u32>::new(&mut map).is_ok());
Expand All @@ -328,7 +323,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};

let map = Map::LpmTrie(map_data);
Expand All @@ -343,7 +337,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let mut trie = LpmTrie::<_, u32, u32>::new(&mut map).unwrap();
let ipaddr = Ipv4Addr::new(8, 8, 8, 8);
Expand All @@ -368,7 +361,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};

let mut trie = LpmTrie::<_, u32, u32>::new(&mut map).unwrap();
Expand All @@ -385,7 +377,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let mut trie = LpmTrie::<_, u32, u32>::new(&mut map).unwrap();
let ipaddr = Ipv4Addr::new(8, 8, 8, 8);
Expand All @@ -410,7 +401,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let mut trie = LpmTrie::<_, u32, u32>::new(&mut map).unwrap();
let ipaddr = Ipv4Addr::new(8, 8, 8, 8);
Expand All @@ -425,7 +415,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let trie = LpmTrie::<_, u32, u32>::new(&map).unwrap();
let ipaddr = Ipv4Addr::new(8, 8, 8, 8);
Expand All @@ -450,7 +439,6 @@ mod tests {
obj: new_obj_map(),
fd: Some(42),
pinned: false,
btf_fd: None,
};
let trie = LpmTrie::<_, u32, u32>::new(&map).unwrap();
let ipaddr = Ipv4Addr::new(8, 8, 8, 8);
Expand Down
Loading

0 comments on commit db975e9

Please sign in to comment.