From 2636d1afac0dd3c60ec2d21c0f16f1d16b21af0c Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Sat, 4 Oct 2025 17:49:01 +0200 Subject: [PATCH] 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. --- aya/src/bpf.rs | 18 ++++++++++-------- xtask/public-api/aya.txt | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/aya/src/bpf.rs b/aya/src/bpf.rs index bb43c529..c4bd9d3a 100644 --- a/aya/src/bpf.rs +++ b/aya/src/bpf.rs @@ -109,7 +109,7 @@ pub fn features() -> &'static Features { /// // load the BTF data from /sys/kernel/btf/vmlinux /// .btf(Btf::from_sys_fs().ok().as_ref()) /// // 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 /// .load_file("file.o")?; /// # Ok::<(), aya::EbpfError>(()) @@ -117,8 +117,10 @@ pub fn features() -> &'static Features { #[derive(Debug)] pub struct EbpfLoader<'a> { btf: Option>, - map_pin_path: Option, + default_map_pin_directory: Option, 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>, extensions: HashSet<&'a str>, verifier_log_level: VerifierLogLevel, @@ -155,7 +157,7 @@ impl<'a> EbpfLoader<'a> { pub fn new() -> Self { Self { btf: Btf::from_sys_fs().ok().map(Cow::Owned), - map_pin_path: None, + default_map_pin_directory: None, globals: HashMap::new(), max_entries: HashMap::new(), extensions: HashSet::new(), @@ -221,13 +223,13 @@ impl<'a> EbpfLoader<'a> { /// use aya::EbpfLoader; /// /// 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")?; /// # Ok::<(), aya::EbpfError>(()) /// ``` /// - pub fn map_pin_path>(&mut self, path: P) -> &mut Self { - self.map_pin_path = Some(path.as_ref().to_owned()); + pub fn default_map_pin_directory>(&mut self, path: P) -> &mut Self { + self.default_map_pin_directory = Some(path.as_ref().to_owned()); self } @@ -378,7 +380,7 @@ impl<'a> EbpfLoader<'a> { pub fn load(&mut self, data: &[u8]) -> Result { let Self { btf, - map_pin_path, + default_map_pin_directory, globals, max_entries, extensions, @@ -488,7 +490,7 @@ impl<'a> EbpfLoader<'a> { PinningType::ByName => { // 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. - let path = map_pin_path + let path = default_map_pin_directory .as_deref() .unwrap_or_else(|| Path::new("/sys/fs/bpf")); diff --git a/xtask/public-api/aya.txt b/xtask/public-api/aya.txt index 29238bc6..d4075c47 100644 --- a/xtask/public-api/aya.txt +++ b/xtask/public-api/aya.txt @@ -10239,10 +10239,10 @@ pub struct 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>::btf(&mut self, btf: core::option::Option<&'a aya_obj::btf::btf::Btf>) -> &mut Self +pub fn aya::EbpfLoader<'a>::default_map_pin_directory>(&mut self, path: P) -> &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 pub fn aya::EbpfLoader<'a>::load_file>(&mut self, path: P) -> core::result::Result -pub fn aya::EbpfLoader<'a>::map_pin_path>(&mut self, path: P) -> &mut Self pub fn aya::EbpfLoader<'a>::new() -> Self pub fn aya::EbpfLoader<'a>::set_global>>(&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