aya: rename map_pin_path to default_map_pin_path

This is the path in which pinned maps are created or resolved. It
isn't actually the path for any specific map itself. This rename
makes way for a method `set_map_pin_path` that actually specifies
the pin path for a specific map.
reviewable/pr1371/r1
Andrew Werner 3 weeks ago committed by ajwerner
parent 0144c0eb22
commit 1c924bb421

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove `AsyncPerfEventArray` and `AsyncPerfEventArrayBuffer` These types have been removed to - Remove `AsyncPerfEventArray` and `AsyncPerfEventArrayBuffer` These types have been removed to
avoid maintaining support for multiple async runtimes. Use `PerfEventArrayBuffer`, which avoid maintaining support for multiple async runtimes. Use `PerfEventArrayBuffer`, which
implements `As{,Raw}Fd` for integration with async executors. implements `As{,Raw}Fd` for integration with async executors.
- Rename `EbpfLoader::map_pin_path` to `EbpfLoader::default_map_pin_directory`.
## 0.13.1 (2024-11-01) ## 0.13.1 (2024-11-01)

@ -110,7 +110,7 @@ pub fn features() -> &'static Features {
/// // load the BTF data from /sys/kernel/btf/vmlinux /// // load the BTF data from /sys/kernel/btf/vmlinux
/// .btf(Btf::from_sys_fs().ok().as_ref()) /// .btf(Btf::from_sys_fs().ok().as_ref())
/// // load pinned maps from /sys/fs/bpf/my-program /// // load pinned maps from /sys/fs/bpf/my-program
/// .map_pin_path("/sys/fs/bpf/my-program") /// .default_map_pin_directory("/sys/fs/bpf/my-program")
/// // finally load the code /// // finally load the code
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::EbpfError>(()) /// # Ok::<(), aya::EbpfError>(())
@ -118,8 +118,10 @@ pub fn features() -> &'static Features {
#[derive(Debug)] #[derive(Debug)]
pub struct EbpfLoader<'a> { pub struct EbpfLoader<'a> {
btf: Option<Cow<'a, Btf>>, btf: Option<Cow<'a, Btf>>,
map_pin_path: Option<PathBuf>, default_map_pin_directory: Option<PathBuf>,
globals: HashMap<&'a str, (&'a [u8], bool)>, globals: HashMap<&'a str, (&'a [u8], bool)>,
// Max entries overrides the max_entries field of the map that matches the provided name
// before the map is created.
max_entries: HashMap<&'a str, u32>, max_entries: HashMap<&'a str, u32>,
extensions: HashSet<&'a str>, extensions: HashSet<&'a str>,
verifier_log_level: VerifierLogLevel, verifier_log_level: VerifierLogLevel,
@ -156,7 +158,7 @@ impl<'a> EbpfLoader<'a> {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
btf: Btf::from_sys_fs().ok().map(Cow::Owned), btf: Btf::from_sys_fs().ok().map(Cow::Owned),
map_pin_path: None, default_map_pin_directory: None,
globals: HashMap::new(), globals: HashMap::new(),
max_entries: HashMap::new(), max_entries: HashMap::new(),
extensions: HashSet::new(), extensions: HashSet::new(),
@ -222,13 +224,13 @@ impl<'a> EbpfLoader<'a> {
/// use aya::EbpfLoader; /// use aya::EbpfLoader;
/// ///
/// let bpf = EbpfLoader::new() /// let bpf = EbpfLoader::new()
/// .map_pin_path("/sys/fs/bpf/my-program") /// .default_map_pin_directory("/sys/fs/bpf/my-program")
/// .load_file("file.o")?; /// .load_file("file.o")?;
/// # Ok::<(), aya::EbpfError>(()) /// # Ok::<(), aya::EbpfError>(())
/// ``` /// ```
/// ///
pub fn map_pin_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { pub fn default_map_pin_directory<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.map_pin_path = Some(path.as_ref().to_owned()); self.default_map_pin_directory = Some(path.as_ref().to_owned());
self self
} }
@ -379,7 +381,7 @@ impl<'a> EbpfLoader<'a> {
pub fn load(&mut self, data: &[u8]) -> Result<Ebpf, EbpfError> { pub fn load(&mut self, data: &[u8]) -> Result<Ebpf, EbpfError> {
let Self { let Self {
btf, btf,
map_pin_path, default_map_pin_directory,
globals, globals,
max_entries, max_entries,
extensions, extensions,
@ -494,7 +496,7 @@ impl<'a> EbpfLoader<'a> {
PinningType::ByName => { PinningType::ByName => {
// pin maps in /sys/fs/bpf by default to align with libbpf // pin maps in /sys/fs/bpf by default to align with libbpf
// behavior https://github.com/libbpf/libbpf/blob/v1.2.2/src/libbpf.c#L2161. // behavior https://github.com/libbpf/libbpf/blob/v1.2.2/src/libbpf.c#L2161.
let path = map_pin_path let path = default_map_pin_directory
.as_deref() .as_deref()
.unwrap_or_else(|| Path::new("/sys/fs/bpf")); .unwrap_or_else(|| Path::new("/sys/fs/bpf"));

@ -10742,10 +10742,10 @@ pub struct aya::EbpfLoader<'a>
impl<'a> aya::EbpfLoader<'a> impl<'a> aya::EbpfLoader<'a>
pub fn aya::EbpfLoader<'a>::allow_unsupported_maps(&mut self) -> &mut Self pub fn aya::EbpfLoader<'a>::allow_unsupported_maps(&mut self) -> &mut Self
pub fn aya::EbpfLoader<'a>::btf(&mut self, btf: core::option::Option<&'a aya_obj::btf::btf::Btf>) -> &mut Self pub fn aya::EbpfLoader<'a>::btf(&mut self, btf: core::option::Option<&'a aya_obj::btf::btf::Btf>) -> &mut Self
pub fn aya::EbpfLoader<'a>::default_map_pin_directory<P: core::convert::AsRef<std::path::Path>>(&mut self, path: P) -> &mut Self
pub fn aya::EbpfLoader<'a>::extension(&mut self, name: &'a str) -> &mut Self pub fn aya::EbpfLoader<'a>::extension(&mut self, name: &'a str) -> &mut Self
pub fn aya::EbpfLoader<'a>::load(&mut self, data: &[u8]) -> core::result::Result<aya::Ebpf, aya::EbpfError> pub fn aya::EbpfLoader<'a>::load(&mut self, data: &[u8]) -> core::result::Result<aya::Ebpf, aya::EbpfError>
pub fn aya::EbpfLoader<'a>::load_file<P: core::convert::AsRef<std::path::Path>>(&mut self, path: P) -> core::result::Result<aya::Ebpf, aya::EbpfError> pub fn aya::EbpfLoader<'a>::load_file<P: core::convert::AsRef<std::path::Path>>(&mut self, path: P) -> core::result::Result<aya::Ebpf, aya::EbpfError>
pub fn aya::EbpfLoader<'a>::map_pin_path<P: core::convert::AsRef<std::path::Path>>(&mut self, path: P) -> &mut Self
pub fn aya::EbpfLoader<'a>::new() -> Self pub fn aya::EbpfLoader<'a>::new() -> Self
pub fn aya::EbpfLoader<'a>::set_global<T: core::convert::Into<aya::GlobalData<'a>>>(&mut self, name: &'a str, value: T, must_exist: bool) -> &mut Self pub fn aya::EbpfLoader<'a>::set_global<T: core::convert::Into<aya::GlobalData<'a>>>(&mut self, name: &'a str, value: T, must_exist: bool) -> &mut Self
pub fn aya::EbpfLoader<'a>::set_max_entries(&mut self, name: &'a str, size: u32) -> &mut Self pub fn aya::EbpfLoader<'a>::set_max_entries(&mut self, name: &'a str, size: u32) -> &mut Self

Loading…
Cancel
Save